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

More
23 Jan 2012 14:28 #17051 by JR1050
I have a Hardinge HNC lathe that is 90% done.I realize I can use Classic ladder,a Comp component or a Python userspace script for plc coding.I have no desire to ladder program,so can I simply write my plc stuff as a C shell script and call it as a user space com[onent? Thanks.

Please Log in or Create an account to join the conversation.

More
23 Jan 2012 16:45 #17058 by andypugh
JR1050 wrote:

can I simply write my plc stuff as a C shell script and call it as a user space com[onent? Thanks.

I am not sure what you mean by "C shell script", but it is relatively easy to write it in comp then compile as a user-space component.
linuxcnc.org/docs/html/hal_comp.html
I have never written a userspace component, but as far as I can see the only difference is that you load them with loadusr rather than loadrt in the HAL file, and that you put "option userspace yes" in the .comp file.

Please Log in or Create an account to join the conversation.

More
23 Jan 2012 17:05 #17059 by ArcEye
Hi

As Andy says, userspace component is probably the way to go.

All you need to write is the C routine that does the actual job required, comp will add all the stuff to enable it to be loaded from a .hal file and have visible hal pins etc

In its simplest form, the userspace component just needs void user_mainloop(void) after the pin declarations, options etc..

user_mainloop can just contain a while(1){ } loop which does whatever you want it to each time it is polled.

All the normal C libraries are available, so it is far easier to write than a real time component in many ways.

regards

Please Log in or Create an account to join the conversation.

More
24 Jan 2012 00:38 #17074 by cmorley
Userspace program for a PLC?

PLC stuff is usually realtime.

Please Log in or Create an account to join the conversation.

More
24 Jan 2012 01:08 #17076 by BigJohnT
JR1050 wrote:

I have a Hardinge HNC lathe that is 90% done.I realize I can use Classic ladder,a Comp component or a Python userspace script for plc coding.I have no desire to ladder program,so can I simply write my plc stuff as a C shell script and call it as a user space component? Thanks.


What exactly are you needing to do? Tool change in classicladder is done and on my web site for my CHNC which I think is the same as the HNC as far as the turret goes.

John

Please Log in or Create an account to join the conversation.

More
24 Jan 2012 05:14 #17081 by JR1050
My initial idea was to write an executable shell script in the c shell( csh,like bash or ksh).It seemed like it might be easier than Comp and considering Python scripts work as user space components,it mighta been worth a shot.I have some previous retrofit experience with Delta Tau and I wrote two PLC programs for a Cincinatti lathe.One was estop,error messages and button functions,the other for the Duplimatic turret.DT scans for changes in i/o states and acts on the changes accordingly.I was thinking about just writing one long file with my turret,estop logic,fault conditions ect.Right now Im using some and/or functions to get things up and going.

I do appreciate that the HNC turret logic has been figured out and shared.Im a glutten for punishment and was gonna have a go at it myself,just for the learning experience.Im not hot on ladder programming and Classic ladder runs in userspace anyway.I was thinking about putting a reverseable two way solinoid on the lathe so the turret would be bi directional.

Thanks for all the input,I started writing the C component and will post some snippets...its a first and Im sure Im gonna get stuck!!.I posted some pics.....


if I can be of any help to any one,please ask!!!
Attachments:

Please Log in or Create an account to join the conversation.

More
24 Jan 2012 05:17 - 24 Jan 2012 05:18 #17082 by JR1050
[img size=320]www.linuxcnc.org/media/kunena/attachment...acy/images/hard2.JPG

I gotta get better at this photo thing!!
Attachments:
Last edit: 24 Jan 2012 05:18 by JR1050. Reason: picture mistake

Please Log in or Create an account to join the conversation.

More
24 Jan 2012 10:34 #17093 by andypugh
JR1050 wrote:

I was thinking about just writing one long file with my turret,estop logic,fault conditions ect.


I wouldn't suggest combining them all.
I think you would want to run e-stop and fault logic in a separate realtime function (or one each). It wouldn't be good for the toolchanger userspace code to be stuck in a wait loop and not be watching the e-stop logic.

Actually, I would probably run the toolchanger in realtime too. It can be done easily as a state machine:

...
param unsigned state = 0 "toolchanger state"
...
;;
function(_)
switch (state){
case 0:
if (tool-prep-select) {
state =1;
}
break;
case 1:
if (tool_change_abort) {
state = 10;
break;
{
table-lift-solenoid = 1;
if (table-lifted){
state = 3;
}
.....

And so on. The only trick with realtime functions is that they have to drop-through and exit every time, which is why the state-machine approach works best.
That case 1 ought to be running a timeout too, case 0 would set a timer to 0. state 1 would add fperiod (the thread period, an internal comp macro) every call, and switch to the abort state if the table_lifted switch never activated, for example.

Please Log in or Create an account to join the conversation.

More
25 Jan 2012 01:29 #17108 by cmorley
Just for the record classicladder logic always runs in realtime.
if your using modbus that is in user space.
and the classicladder GUI runs in user space.

Please Log in or Create an account to join the conversation.

More
30 Jan 2012 04:56 #17276 by JR1050
Ive written the first of the plc programs I will need for my Lathe.When attempted to run Comp(which could use some better instructions),I got the following:


jr1050@jr1050-desktop:/usr/realtime-2.6.32-122-rtai/modules/emc2$ comp --install buttonlogic.comp
buttonlogic.comp:35:2: Trying to find one of "$", "pin", "param", "function", "variable", "option", "see_also", "notes", "description", "license", "author", "include", "modparam"
> int RUN_PROGRAM;
> ^
while parsing File():
jr1050@jr1050-desktop:/usr/realtime-2.6.32-122-rtai/modules/emc2$


This is the file with my button logic.Im sure I need some help here....


component buttonlogic;


pin in bit PB_OPEN_COL;
pin in bit PB_CLOSE_COL;
pin in bit LS_COLLET_CLOSED;
pin in bit EMER_STOP_OUT;
pin in bit PB_CYL_START;
pin in bit PB_FEEDHOLD;
pin in bit PB_COOL_ON;
pin in bit AUTO_MODE;
pin in bit MDI_MODE;
pin in bit MAN_MODE;

///Outputs///


pin out bit CL_ELEC_ON;
pin out bit CL_SPNL_ON;
pin out bit CL_IDOD_CLNT;
pin out bit SL_PC_FRONT;
pin out bit SL_COL_OPEN;
pin out bit SL_COL_CLOSE;
pin out bit SL_VERT_COFF;
pin out bit SL_LUBE;
pin out bit SL_TURRET_INDEX;
pin out bit CR_DRIVES_ON;
pin out bit SL_TURRET_STOP;
pin out bit PROG_RUN_OK;
pin out bit PROG_RESUME;
pin out bit FEED_HOLD;



int RUN_PROGRAM;
int CS_COOLANT_ON;
int CS_COOLANT_OFF;
int COLLET_CLSD;
int COLLET_OPN;

function _ nofp;
license "GPL";
;;

FUNCTION(_) {




////on push button//
{
if((PB_CYC_START)=1 && ((AUTO_MODE)=1 || (MDI_MODE))=1)){
RUN_PROGRAM=1;
}
{
if(RUN_PROGRAM)=1
{
PROG_RUN_OK=1;
}

////feed hold///
{
if((PROG_RUN_OK)=1 && (PB_FEED_HOLD)=1){
FEED_HOLD=1;
}

///resume program//
{
if((FEED_HOLD)=1 && (PB_CYC_START)=1)){
PROG_RESUME=1;
}

//coolant on button///
(
if((PB_COOL_ON)=1 && (CS_COOLANT_ON)=0){
CL_IDOD_CLNT=1;
CS_COOLANT_ON=1;
}
{
if((PB_COOL_ON)=1 && (CS_COOLANT_ON)=1){
CL_IDOD_CLNT=0;
CS_COOLANT_ON=0;
}
//COLLET open button///
(
if((PB_OPEN_COL )=1 &&(LS_COLLET_CLOSED)=1 && (MANUAL_MODE)=1))){
SL_COL_CLOSE=0;
SL_COL_OPEN=1;
COLLET_CLSD=0
COLLET_OPN=1;
}
{
if((PB_CLOSE_COL)=1 && (LS_COLLET_CLOSED)=0 && (MANUAL_MODE)=1)&&(COLLET_OPN=1))){
SL_COL_OPEN=0
SL_COL_CLOSE=1;
COLLET_CLSD=1;
}

And here is a snippet from my hal file


net TC_CALL iocontrol.0.tool-change
net current_tool iocontrol.0.tool-number
net next_tool iocontrol.0.tool-prep-number
net tc_compelte iocontrol.0.tool-changed

##Auto and MDI
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

###inputs starting on 5i20 p3

#connect limit switches to limit inputs
net X_plus_overtravel hm2_5i20.0.gpio.024.in_not =axis.0.pos-lim-sw-in
net X_minus_overtravel hm2_5i20.0.gpio.025.in_not =axis.0.neg-lim-sw-in
net X_home_switch hm2_5i20.0.gpio.026.in => axis.0.home-sw-in

net Z_pos_overtravel hm2_5i20.0.gpio.027.in_not => axis.2.pos-lim-sw-in
net Z_neg_overtravel hm2_5i20.0.gpio.028.in_not => axis.2.neg-lim-sw-in
net Z_home_switch hm2_5i20.0.gpio.029.in => axis.2.home-sw-in
#connect positive limit signals to home inputs

#turret encoder

net BCD_bit_1 hm2_5i20.0.gpio.030.in_not #1st bit of bcd encoder
net BCD_bit_1 wsum.0.bit.0.in
setp wsum.0.bit.0.weight -1
net BCD_bit_2 hm2_5i20.0.gpio.031.in_not #2nd bit of bcd encoder
net BCD_bit_2 wsum.0.bit.1.in
setp wsum.0.bit.1.weight -2
net BCD_bit_3 hm2_5i20.0.gpio.032.in_not #3rd bit of bcd encoder
net BCD_bit_3 wsum.0.bit.2.in
setp wsum.0.bit.2.weight -4
net BCD_bit_4 hm2_5i20.0.gpio.033.in_not #4th bit of bcd encoder
net BCD_bit_4 wsum.0.bit.3.in
setp wsum.0.bit.3.weight -8
setp wsum.0.offset 15

net TURRET_POS_M wsum.0.sum #full value
##other inputs

net LS_TURRET_UP hm2_5i20.0.gpio.034.in_not #TURRET 11LS hall effect
net EMER_STOP_OUT hm2_5i20.0.gpio.035.in #ESTP switch loopback
net LS_COLLET_CLOSED hm2_5i20.0.gpio.036.in_not #COLET CLOSED LS2
net LS_SPINDLE_PIN hm2_5i20.0.gpio.037.in_not #1 LS SPINDLE LOCK PIN
net PS_MACH_AIR hm2_5i20.0.gpio.038.in_not # 14 PS air pressure
net LS_VSLIDE_UP hm2_5i20.0.gpio.039.in_not #vert cutt off up LS17
net CL_SPNL_FAULT hm2_5i20.0.gpio.040.in_not #SPINDLE DRIVE FAULT
net OL_CLNT_MTR hm2_5i20.0.gpio.041.in_not #COOLANT MOTOR OVERLAOD NC-ON
net XZ_FAULT hm2_5i20.0.gpio.042.in_not #DRIVES FAULT

## p3 board 1



net PB_OPEN_COL hm2_5i20.0.gpio.047.in_not #COLLET OPEN PUSH BUTTON
net PB_CLOSE_COL hm2_5i20.0.gpio.048.in_not #COLLET CLOSE PUSH BUTTON

##p4 on first board

net PB_CYL_START hm2_5i20.0.gpio.049.in_not #CYCLE START PUSH BUTTON
net PB_FEEDHOLD hm2_5i20.0.gpio.050.in_not #FEED HOLD PUSH BUTTON
net PB_COOL_ON hm2_5i20.0.gpio.051.in #COOLANT ON PUSH BUTTON



#####MACHINE OUTPUTS 110V


net CL_ELEC_ON hm2_5i20.0.gpio.052.out #MACHINE ELECRICS On
setp hm2_5i20.0.gpio.052.is_output 1
setp hm2_5i20.0.gpio.052.is_opendrain 1
setp hm2_5i20.0.gpio.052.invert_output 1

ect,ect

Can any one shed some light on the message from the command line? Can I do the pin in/pin out the way I have it done,or am I missing something?More then 1 thing I suspect....Thanks for your help.

Please Log in or Create an account to join the conversation.

Time to create page: 0.080 seconds
Powered by Kunena Forum