NEWS
LinuxCNC 2.5.2 Release
LinuxCNC 2.5.2 Update Released (changelog).
 
LinuxCNC 2.5.1 Release

LinuxCNC 2.5.1 Update Released (changelog). If the Package Manager does not prompt you to upgrade see this page.

 
LinuxCNC 2.5.0 Release
New major release (changelog). See the instructions to update your system from EMC 2.4 to LinuxCNC 2.5.
 
Home Forum HAL HAL Components Can I use a C shell script for my PLC stuff?

Welcome, Guest
Username: Password: Remember me

TOPIC: Can I use a C shell script for my PLC stuff?

Re:Can I use a C shell script for my PLC stuff? 06 Feb 2012 16:24 #17476

  • JR1050
  • JR1050's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 88
  • Thank you received: 1
  • Karma: 3
Thank for your help!!!As I said,this is my first go at full blown C programming.Might as well jump in with both feet,no pain no gain!!With all of that being said,I have a few questions concerning the passing of values through the pins and the names that can be used in a comp file.

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.
The administrator has disabled public write access.

Re:Can I use a C shell script for my PLC stuff? 06 Feb 2012 23:25 #17478

  • andypugh
  • andypugh's Avatar
  • OFFLINE
  • Moderator
  • Posts: 4117
  • Thank you received: 141
  • Karma: 129
JR1050 wrote:
net AUTO_MODE halui.mode.is-auto
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.
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;
This will create a HAL "pin" called buttonlogic.0.PB_CYL_START, to use that in your HAL file you will need something like:

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.
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 am confused when you say "in the same file". The line above is C / .comp syntax, but "net" commands are HAL file syntax.
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)
The administrator has disabled public write access.

Re:Can I use a C shell script for my PLC stuff? 07 Feb 2012 05:59 #17485

  • JR1050
  • JR1050's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 88
  • Thank you received: 1
  • Karma: 3
Thank you again for your help and quick response.I didnt mean to confuse you(or anyone else for that matter).There are no C statements in my hal file,and no net commands in my comp file.Im learning the syntax of C as I go from a couple of books and various web sites,trial by fire.There are missing pieces(or just plain hard to find) in the manual.
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...
The administrator has disabled public write access.

Re:Can I use a C shell script for my PLC stuff? 07 Feb 2012 06:13 #17486

  • BigJohnT
  • BigJohnT's Avatar
  • OFFLINE
  • Administrator
  • Posts: 4955
  • Thank you received: 86
  • Karma: 134
The comp chapter does seem to be missing any description for pin and param and skips right to pin direction...

I'll work on that.

John
The administrator has disabled public write access.

Re:Can I use a C shell script for my PLC stuff? 11 Feb 2012 16:29 #17614

  • JR1050
  • JR1050's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 88
  • Thank you received: 1
  • Karma: 3
After a couple days of playing with comp.I can get my files to install/compile,but I get this

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.
This attachment is hidden for guests. Please log in or register to see it.


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...
Attachments:
  • Attachment This attachment is hidden for guests. Please log in or register to see it.
The administrator has disabled public write access.

Re:Can I use a C shell script for my PLC stuff? 11 Feb 2012 16:46 #17615

  • andypugh
  • andypugh's Avatar
  • OFFLINE
  • Moderator
  • Posts: 4117
  • Thank you received: 141
  • Karma: 129
JR1050 wrote:
are the errors that are showing up at install time causing my output not to function or am I missing something else?
Probably not, they seem to always appear.

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.
The administrator has disabled public write access.
Time to create page: 1.143 seconds
Powered by Kunena Forum
© 2013 LinuxCNC.org
Joomla! is Free Software released under the GNU General Public License.