Can I use a C shell script for my PLC stuff?
- JR1050
-
Topic Author
- Offline
- Platinum Member
-
- Posts: 450
- Thank you received: 33
This is a piece of my hal file.It works.The button changes state when pushed.
net PB_CYL_START hm2_5i20.0.gpio.049.in_not
I have also assigned the modes of operation to the following names
net AUTO_MODE halui.mode.is-auto
net MDI_MODE halui.mode.is-mdi
net MAN_MODE halui.mode.is-manual
net PROG_RUN_OK halui.program.run
net PROG_RESUME halui.program.resume
net FEED_HOLD halui.program.pause
In the declaretion section of my first comp file(which at this time is named buttonlogic.comp)which is the logic for that pushbutton,I have this..
pin in bit PB_CYL_START;
And in the same file I am attempting to use the bit like so
if(((PB_CYL_START)==1)&&((AUTO_MODE)==1||(MDI_MODE)==1))
RUN_PROGRAM=1;
I have seen some example comp files that attached an extra name at the end of the pin in a fashion like this.
net PB_CYL_START hm2_5i20.0.gpio.049.in_not=pbclystart.buttonlogic
Can I use the original name that is in my hal file ,that is actually attached to the physical pins as I already have or must I follow the convention above and add a second name for the comp file.I plan on elimenateing all the uppercase and underscores.Would I be correct in guessing if the second name is needed it must be followed by .name of the comp file?Thanks again.
Please Log in or Create an account to join the conversation.
- andypugh
-
- Offline
- Moderator
-
- Posts: 23451
- Thank you received: 4987
This might not be doing what you want. This creates a HAL "signal" called AUTO_MODE, but that is not the same as the AUTO_MODE "pin" that is created by your .comp component, which is called buttonlogic.0.AUTO_MODE.net AUTO_MODE halui.mode.is-auto
This will create a HAL "pin" called buttonlogic.0.PB_CYL_START, to use that in your HAL file you will need something like:In the declaretion section of my first comp file(which at this time is named buttonlogic.comp)which is the logic for that pushbutton,I have this..
pin in bit PB_CYL_START;
net pb_cyl_start_signal buttonlogic.0.PB_CYL_START <= hm2_5i20.gpio.049.in_not
This creates a HAL "signal" called pb_cyl_start_signal (you can use any name you like) which follows the value of the output pin to which it is assigned (hm2_5i20.gpio......) and writes that value to any input pin to which it shares a "net" command, in this case buttonlogic.0.PB_CYL_START.
I am confused when you say "in the same file". The line above is C / .comp syntax, but "net" commands are HAL file syntax.And in the same file I am attempting to use the bit like so
if(((PB_CYL_START)==1)&&((AUTO_MODE)==1||(MDI_MODE)==1))
RUN_PROGRAM=1;
I think that the logic above belongs in your .comp file, and the HAL file should just be "net"-ing the RUN_PROGRAM HAL pin to a physical output pin.
You _can_ do that sort of logic in HAL, but that involves netting together a bunch of and2 and or2 HAL components (which are written in .comp)
Incidentally, that line would work just as well as:
if (PB_CYL_START && (AUTO_MODE || MDI_MODE )) RUN_PROGRAM=1;
In fact this is better, as "TRUE" parport pins in HAL simply have a non-zero value, not necessarily 1. (hm2 gpio pins are always 1 == true, though)
Please Log in or Create an account to join the conversation.
- JR1050
-
Topic Author
- Offline
- Platinum Member
-
- Posts: 450
- Thank you received: 33
Id say the manual needs a section that says "pin in bit blah_blah" will create a signal(name?) in your .comp file called "0.blah_blah' and to make this name actually do something it has to be tied to a real pin(name,signal?) like so ,net but_blah mycompfileblah.0.blah_blah=hm2_5i20.gpio.049.in_not in your .hal file.
Again,a huge thanks for your help,hopefully I understand this correctly,Im sure Ill have a few more before its all over...
Please Log in or Create an account to join the conversation.
- BigJohnT
-
- Offline
- Administrator
-
- Posts: 6999
- Thank you received: 1176
I'll work on that.
John
Please Log in or Create an account to join the conversation.
- JR1050
-
Topic Author
- Offline
- Platinum Member
-
- Posts: 450
- Thank you received: 33
jr1050@jr1050-desktop:/usr/realtime-2.6.32-122-rtai/modules/emc2$ sudo comp --install coolant.comp
[sudo] password for jr1050:
make -C /usr/src/linux-headers-2.6.32-122-rtai SUBDIRS=`pwd` CC=gcc V=0 -o /Module.symvers modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-122-rtai'
CC [M] /tmp/tmp0lP5aI/coolant.o
Building modules, stage 2.
MODPOST 1 modules
WARNING: "hal_init" [/tmp/tmp0lP5aI/coolant.ko] undefined!
WARNING: "rtapi_print_msg" [/tmp/tmp0lP5aI/coolant.ko] undefined!
WARNING: "hal_exit" [/tmp/tmp0lP5aI/coolant.ko] undefined!
WARNING: "hal_export_funct" [/tmp/tmp0lP5aI/coolant.ko] undefined!
WARNING: "hal_malloc" [/tmp/tmp0lP5aI/coolant.ko] undefined!
WARNING: "hal_pin_bit_newf" [/tmp/tmp0lP5aI/coolant.ko] undefined!
WARNING: "rtapi_snprintf" [/tmp/tmp0lP5aI/coolant.ko] undefined!
WARNING: "hal_ready" [/tmp/tmp0lP5aI/coolant.ko] undefined!
CC /tmp/tmp0lP5aI/coolant.mod.o
LD [M] /tmp/tmp0lP5aI/coolant.ko
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-122-rtai'
cp coolant.ko /usr/realtime-2.6.32-122-rtai/modules/emc2/
I do have a coolant .ko file and the pins show in hal show.My inputs show change of state(when the coolant button is pushed,coolant.0.pb_cool_on go high),but I have no change to my output bit,so consequently, have actual output to the machine.
Below is the small file i am trying to run
component coolant;
pin in bit pb_cool_on;
pin out bit cl_idod_clnt;
variable bool run_program;
variable bool cs_coolant_on;
variable bool cs_coolant_off;
variable bool collet_clsd;
variable bool collet_opn;
function _ nofp;
license "gpl";
;;
FUNCTION(_)
{
//coolant on button///
if((pb_cool_on)==1)
{
cl_idod_clnt=1;
cs_coolant_on=1;
}
}
Here is my hal file.
are the errors that are showing up at install time causing my output not to function or am I missing something else?Thanks as always...
Please Log in or Create an account to join the conversation.
- andypugh
-
- Offline
- Moderator
-
- Posts: 23451
- Thank you received: 4987
Probably not, they seem to always appear.are the errors that are showing up at install time causing my output not to function or am I missing something else?
It looks like it ought to work. Are you not seeing the pin change on the Mesa card, or isn't it changing in HAL either?
I doubt this is the problem, but use
if(pb_cool_on)
rather than
if((pb_cool_on)==1)
As there is no guarantee that a "true" bit value is 1, it is merely any non-zero value.
Please Log in or Create an account to join the conversation.
- JR1050
-
Topic Author
- Offline
- Platinum Member
-
- Posts: 450
- Thank you received: 33
net coolant.0.pb_cool_on hm2_5i20.0.gpio.051.in_not .
I could not get any other configuration to show in hal and" net pb_cool_on coolant.0.pb_cool_on=hm2_5i20.0.gpio.051.in_not" caused an error while loading emc. "coolant.0.pb_cool_on does not exist"
Im kinda stumped,any suggestions.Seems like a hal thing....
Please Log in or Create an account to join the conversation.
- ArcEye
- Offline
- Junior Member
-
- Posts: 24
- Thank you received: 758
Can't see any reason why the component should not work, but have noticed your net syntax is wrong in your .hal file
Should be net <signal-name> <pin-name> <opt-direction> <opt-pin-name>
as per linuxcnc.org/docs/html/hal_basic_hal.html#r1_1_4
note that signal name and first pin are not optional.
This has no signal and just names 2 pins, and net will try to use the first param as a signal.net coolant.0.pb_cool_on hm2_5i20.0.gpio.051.in_not
For some reason this often does not create an error when LinuxCNC loads the .hal file and starts, but either does nothing or reports that pin such and such does not exist etc.
regards
Please Log in or Create an account to join the conversation.
- JR1050
-
Topic Author
- Offline
- Platinum Member
-
- Posts: 450
- Thank you received: 33
How does that go,we do it to ourselves...after a good nites sleep and finding my glass's,I noticed the pins in hal have "-" in them not " _".After changing the offending names in my hal file,all the buttons worked.This falls somewhere between amazing and duhh....
That brings me to my next "probably do'n it to myself".I have the following code to move my turret.It is a ruff write and will probably miss the actual tool,as it needs a delay to seat,Ill get to that next.I have a considerably nicer routine with error messages ect,but one battle at a time...This installs and compiles.
component turret;
pin in s32 turret_pos_m; // out put of bcd encoder
pin in bit ls_turret_up; // limit switch to indicate if the turret is seated
pin in bit tc_call; // connected to iocontrol.0.tool-change
pin in s32 current_tool; // connected to iocontrol.0.tool-number
pin in s32 next_tool; // connected iocontrol.0.tool-prep-number,tool #called by m6
///outputs///
pin out bit sl_turret_index; //connected to turret up/index solinoid
pin out bit sl_turret_stop; //connected to turret stop/seat solinoid
pin out bit tc_complete; //connected to iocontrol.0.tool-changed
variable char t_state;
variable char turret_ready;
variable bool change_tool;
variable char tool_changed;
variable char turret_error;
variable char turret_state;
function _ nofp;
license "gpl";
;;
FUNCTION(_)
{
if((tc_call)==1&&(turret_pos_m)!=(next_tool)&&(next_tool)<=8) ///check to see if tc is requested
{
change_tool=1;
}
else
{
change_tool=0;
}
{
while((turret_pos_m)!= (next_tool)&&(change_tool)==1)
sl_turret_index=1;
}
if((turret_pos_m)==(next_tool))
{
sl_turret_stop=1;
sl_turret_index=0;
sl_turret_stop=0;
}
if((turret_pos_m)==(next_tool)&&(ls_turret_up)==1)
{
tc_complete=1;
change_tool=0;
}
}
Now for the problem,when a tool change is called via M6 in mdi,the tool change flag( iocontrol.0.tool-change),never goes high and cosequently the turret never tries to move.The machine is homed and the tool # that is called by M6 updates to iocontrol.0.tool-prep-number,tool .There is no way to tell the emc what the current tool is and emc says "no tool".Where did I go wrong?and thanks...
Please Log in or Create an account to join the conversation.
- andypugh
-
- Offline
- Moderator
-
- Posts: 23451
- Thank you received: 4987
I noticed the pins in hal have "-" in them not " _".After changing the offending names in my hal file,all the buttons worked.
Ah, yes, a common problem.
Note that the "standard" for HAL is to use "-" all the time, but that in the C-code the "-" characters are automatically substituted to "_". It's not a very well adhered-to standard, but you probably want to stick to it to be consistent. So, that means "-" above the ;; and "_" below it…
Now for the problem,when a tool change is called via M6 in mdi,the tool change flag( iocontrol.0.tool-change),never goes high and cosequently the turret never tries to move.The machine is homed and the tool # that is called by M6 updates to iocontrol.0.tool-prep-number,tool .There is no way to tell the emc what the current tool is and emc says "no tool".Where did I go wrong?and thanks...
T6 drives the iocontrol.0.tool-prep-number pin and sets the tool-prepare pin. M6 won't set the tool-change pin until tool-prepared is true.
You probably need to loop tool-prepare to tool-prepared in HAL for your particular type of changer.
Please Log in or Create an account to join the conversation.