Red Lion C programing - Wait? RESOLVED

3 posts in this topic

Anyone ever used a Wait-for digital tag in a C Program?

I have to use C in the Red Lion Programs.. but, I'm not at all proficient in C (or anything else for that matter ..)

Here’s a nice problem for basic C programming .. I really need to solve it .. but, so far ... can't ... sigh!:

I have an actuator that will be commanded to make sine wave motion.  The program that does that, in the actuator’s driver-controller, requires the actuator to first be in a zero position.  Homing has already been done, so the drive knows where the actuator is.  I cannot modify the sine wave program; but, can command a Move Absolute program in the drive, to take the actuator to zero, if it isn’t already there.  When the actuator is at zero, it is “In position” and a digital tag will go True. If the Tag is False, the actuator is not at zero, it’s at some other position,  and only the Move Absolute program can return the actuator to zero.

So, when launching this position command program, In a Red Lion G3 HMI, using only Basic C programming, how would you write a control program that would test the status of the actuator’s position, and, finding it at zero (the “InPos” tag is true) would start the Sine Wave program.  And, If the “InPos” Tag is false, would start the Move Absolute program, which would return the actuator to zero, and when the actuator is In Position, would start the Sine Wave program.

Here’s the tricky part. It will take only a few milliseconds to start the Move Absolute program (if required) .. but how do you get the “C” control program you are writing, to wait until the actuator actually reaches zero, and the “inPos” tag goes true … which could take several seconds?

I don’t believe there is a WaitFor function in “C” , and you cannot send either the Move Absolute, or the Sine Wave program more than once .. so, if a loop is used, it can loop only one time .. presumably with conditional delays. (however that's done)  You cannot use Sleep().. that would be cheating.. the full program must run in the least amount of time, and you do not know how far the actuator is from zero.

You could use if (! InPos) or if (InPos) to qualify what programs to run .. but, where does the “Wait for In position”  fit into C Programming?  You might be able to use Continue .. but, ya still have to wait for “InPos” to go True…..before running the Sine Wave.       Thanks Much, Regards, Michael

Edited by lamboom
End the Thread .. shouldn't do this in the HMI

Share this post

Link to post
Share on other sites

Open the tag 'inpos' and look for the tab 'triggers'. Set the trigger mode and value(true) and define what you want to happen(the action. It can be complex code if you like. 

1 person likes this

Share this post

Link to post
Share on other sites

Thanks Nj Controls .. I posted this on Forum too.. just in case no one took me seriously here.. It's kinda a basic question.. :-)

Turns out one shouldn't use C programming for a position control program from an HMI.. there are unintended consequences in the HMI for loops which are paused to await a condition before continuing.   This program is easily done in the Motion Controller, which has "wait for" conditions available in it's "user programs" (the ones you write)  The Red Lion uses programs that can be called from the HMI's pages. Those programs must be written in basic C.    Using loops that wait for position conditions which are initiated by the HMI, by sending parameters and a start command to a Driver/Controller .. is not recommended.    

However, some of the suggestions I got on were to use 

while ( !inPos )
// do nothing

for a wait .. but that could end badly.. but would work if all went well.


switch Step {

case 0: if start then 
        issue Home();

case 1: if Homed then
        issue MoveAbsoluteToZero();

case 2: if Inpos then 
        issue Sinewave();

case 3: if Abort then 
        issue Stop;

case 4: if Stopped then 

Not exactly..but something similar should work.

Edited by lamboom

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now