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

More
17 Feb 2012 18:44 #17768 by PCW
I dont think you can have a while statement that waits an indefinite period in a comp,
as each time the comp is invoked, it must fall through in << than the thread time
(without looking closely, I think you could just replace the while with an if)

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

More
19 Feb 2012 04:17 #17814 by JR1050
Thanks for the help. I have had no luck getting the following to compile:

param rw s32 state =- 1;

It forces this error with the whole program at compile time

ke[1]: Entering directory `/usr/src/linux-headers-2.6.32-122-rtai'
CC [M] /tmp/tmp_l5PxK/turret.o
turret.comp:35: error: expected ‘{’ before ‘(’ token
turret.comp:35: error: expected ‘;’, ‘,’ or ‘)’ before ‘long’
make[2]: *** [/tmp/tmp_l5PxK/turret.o] Error 1

I had to asign the state like so
;;;
int state = -1;

Any suggestions as to why a parameter throws an error? I will also need a timer to allow the turret plate to drop down.How do I make one?I saw something about fperiods but no explanation.I would guess a sleep statement wont work in a real time function.


The code

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








function_nofp;
license "gpl";
;;

int state = -1;
int wait_two = 0;



FUNCTION(_)
{

switch (state) {
case -1:
if((tc_call)==1)
{
state=0;
}
case 0:
if((turret_pos_m)!=(next_tool)&&(next_tool)<=8)
{
state=1;
sl_turret_index=1;
}
break;
case 1://rotate da turret
if((turret_pos_m)==(next_tool))
{
state=2;
sl_turret_stop=1;
sl_turret_index=0;
}
break;
case 2:///wait for the turret to seat
if((turret_pos_m)==(next_tool)&&(ls_turret_up)!=1)
{
state=3;
wait_two=75;
sl_turret_stop=0;
}
break;
case 3: //make sure da turret is seated
if((turret_pos_m)==(next_tool)&&(ls_turret_up)==1)
{
state=0;
tc_complete=1;
}
break;
case 4: //errors in case da turret aint seated
if((turret_pos_m)==(next_tool)&&(ls_turret_up)==0)
{
rtapi_print_msg(RTAPI_MSG_ERR, "Turret unseated,limit switch false");
}
else
if((turret_pos_m)!=(next_tool) && (ls_turret_up)==1)
{
rtapi_print_msg(RTAPI_MSG_ERR, "Current tool does not match commanded tool");
}
break;
case 5: break;

default: state=4;
break;
}

}

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

More
19 Feb 2012 10:28 #17819 by ArcEye
Hi,

Thanks for the help. I have had no luck getting the following to compile:
param rw s32 state =- 1;

If you do comp turret.comp and generate a C file you should soon see why you should not have a variable called state.

state is the name of the struct which holds all the pins and parameters declared in your header, and doubtless clashes with your param.

There is no real reason to have a param to hold the the current 'state', but it is useful for debugging certainly.

I called that variable progress-level in my components, set it as a param whilst developing ( as I did with several other variables until the debugging stage was over, so as to be able to easily monitor them) and then made it a local int variable.

I will also need a timer to allow the turret plate to drop down.How do I make one?I saw something about fperiods but no explanation.

I used an existing component called timedelay and created a couple of pins to connect to it from the toolchanger, to cater for a similar requirement to wait for the ATC to reverse and lock against the pawl before cutting the power to its motor.

See wiki.linuxcnc.org/cgi-bin/emcinfo.pl?Con...oolchanger_component where you can download the code for exact details

I would guess a sleep statement wont work in a real time function

No you should avoid sleep() and usleep().
Where I have wanted a very short pause I have used an incrementing counter eg something like -
switch(progress_level)
   {
   case 1:
       if(x < 500)
          {
          x++;
          return;
          }
       progress_level = 2;
       return;
   .........
   }
The duration is obviously dependent upon the speed of the thread.

You are almost there, I learnt a huge amount from similar travails

regards

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

More
19 Feb 2012 10:44 #17820 by andypugh
JR1050 wrote:

param rw s32 state =- 1;

As ArcEye said, you can't use "state" as it is used in the generated C-code. You should probably used "signed" rather than "s32" also. My fault, I should have checked my code.

I will also need a timer to allow the turret plate to drop down.How do I make one?I saw something about fperiods but no explanation.


float timer;

timer = 0;
state = 5;
break;

case 5;
timer += fperiod;
if (timer > timeout){
state = error_state;
<timeout message>
}
<other stuff>
break:

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

More
22 Feb 2012 14:59 #17935 by JR1050
Thanks again for your help.I have the turret up,indexing and stopping in the right spot.I need to get it to drop down and seat.I have not had much sucess using the timedelay component.Is there any one out there who has a good grasp of how it works? The manual page is not very descriptive....

Im attemping this;

pin out bit timer_run; ///////timedelay.0.timer-run

case 2:///wait for the turret to seat
if((turret_pos_m)==(next_tool)&&(ls_turret_up)!=1)
{
tc_cond=3; //state of this plc
sl_turret_index=0; // turn off the index motor causing the turret to seat
timer_run=1; // wait for it to drop down
sl_turret_stop=0; //disengage the stop pin
}
break;

In hal
setp timedelay.0.on-delay 2
net run_timer timedelay.0.timer-run = timedelay.0.in( i think,i dont have the hal file infront of me)

This should work,but...it dont.I wrote the same function with if statements and got stuck in the same place,again any one have a detailed knowledge hoe the timedelay works.Thanks.

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

More
22 Feb 2012 15:14 #17936 by andypugh
JR1050 wrote:

I have not had much sucess using the timedelay component..


I think it is a mistake to try to use that here.

timedelay simply sets an output pin high a fixed time after the input pin goes high. Feeding those pins into and out of your comp is a waste of time.

It makes a lot more sense to do it all inside your comp.

...
case 5:
timer = 0;
tc_cond = 6;
break;
case 6; // waiting
timer = timer + fperiod; //(or use timer += fperiod)
if (timer > 10) { // Not sure if this is seconds, nanoseconds, fortnights)
state = 7;
}
break;
case 7: // finished waiting..
...

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

More
22 Feb 2012 16:32 #17941 by JR1050
I can do this,but I would like to know how this works,so question 1,fperiods,do I have to define this or does comp just know it when it see's it ?Is timer in or char variable ot int? Thanks

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

More
22 Feb 2012 16:39 #17942 by ArcEye
Hi,

I have not had much success using the timedelay component..

The example of its use is in the header of the oracchanger.comp
loadrt timedelay count=1
addf timedelay.0 servo-thread
# will wait 5 secs approx and turn motor off after reversing against stop
setp timedelay.0.on-delay 5   

net delaystart timedelay.0.in <= oracchanger.delaystart
net delaydone timedelay.0.out => oracchanger.delaydone
.........
pin out bit delaystart = false          "Starts timerdelay";
pin in bit delaydone =false             "Signals timer finished";
delaystart is set true when the motor is set into reverse to engage the pawl
When delaydone is positive the motor is shut off

I could have just used an inline timer, partly because I could not find a satisfactory definition of fperiod I decided to use a stock component.
The other reason was that using an external counter made it easy to continue to a idle state (progress_level 0) in the component and just turn off the motor when the delaydone signal comes back.

There is no 'right' way, just different paths leading to the same end

regards

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

More
22 Feb 2012 17:05 #17943 by andypugh
JR1050 wrote:

I can do this,but I would like to know how this works,so question 1,fperiods,do I have to define this or does comp just know it when it see's it


"fperiod" is described in the comp docs under "Convenience macros"
linuxcnc.org/docs/html/hal_comp.html#r1_8
It is the floating point representation of the time since the function was last called, in seconds.
(you can also use "period" if you want it as nanoseconds in integer notation)

Your timer variable needs to be a double or float.

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

More
29 Feb 2012 14:26 #18203 by JR1050
A big thank you to Arceye and Andy.I finally got this thing workn and learned a few things along the way!!
I couldnt get Andy's timer to work for me(mostly bescause I dont understand how it works!!!),I did however get the time delay component to work.

For any one who might be fighting with all the toolchange i/o,here are some things i found out;

After calling a tool with a t word(iocontrol.0.tool-prep-number),the register is set to zero and now
for comparing the toolchanger postion to the commanded tool,you have to use iocontrol.0.tool-number.

On a hardinge turret,you have to stop the tool one before the commanded tool(I had to do this on my Cincinatti also) due to the air motor overshooting.My guess is that an air motor is not accurate enough to used for postioning.Maybe a servo.

To compile your C file you have top run comp in the emc2 realtime directory like so sudo comp --install comp myfile.comp.It wont compile as the root user.To edit your file run sudo gedit as above.


Thanks again and I post a video of if shortly.Ive been making notes on what I had to do to get this to work along the way.Ill post them.

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

Time to create page: 0.091 seconds
Powered by Kunena Forum