Wait with Trigger Motion

The basic Wait(int axis) function will wait until the axis is in Idle operation state until returning. Calling another motion function immediately after returning from the Wait(int axis) function introduces a variable delay depending on when the system is able to execute the motion function. This variable delay may be between 0 and several milliseconds or longer, and may not be consistent between multiple executions of the same motion application.

To eliminate this inconsistency, Trigger Motion can be used to queue the next motion command while the previous motion command is still executing.

The first motion function can be a regular, non-trigger motion function. Then, a trigger motion function can be called immediately to queue the next motion command. Then, any number of alternating Wait(WaitCondition *pWaitCondition) functions and trigger motion functions can be called.

The WaitCondition that is specified should have a WaitConditionType of MotionStartedOverrideReady. This wait condition will wait until the previous trigger motion has executed and the next trigger motion function can be called.

The other parameters of the WaitCondition that must be specified are axis and axisCount. The axisCount can be set to 1 and the axis to the commanded axis.

With the above parameters, the Wait(WaitCondition *pWaitCondition) will return when the previous trigger motion executes and a new trigger motion can be queued.

The following figure illustrates the timings at which the functions are called and the trigger motions are executed.

../_images/WMXDOC_FUNC_WAIT_TRIGGER_MOTION_image2.png

Wait with Trigger Motion Example

The following code executes a simple sequence of motion commands using trigger motion functions and Wait(WaitCondition *pWaitCondition) functions.

Motion::PosCommand pos;
Motion::TriggerPosCommand tpos;
Motion::WaitCondition wait;

//Set position command parameters
pos.axis = 0;
pos.profile.type = ProfileType::Trapezoidal;
pos.profile.velocity = 10000;
pos.profile.acc = 10000;
pos.profile.dec = 10000;

//Set triggered position command parameters
tpos.axis = 0;
tpos.profile.type = ProfileType::Trapezoidal;
tpos.profile.velocity = 10000;
tpos.profile.acc = 10000;
tpos.profile.dec = 10000;
tpos.trigger.triggerAxis = 0;
tpos.trigger.triggerType = TriggerType::RemainingTime;
tpos.trigger.triggerValue = 0;

//Set wait condition parameters
wait.waitConditionType = Motion::WaitConditionType::MotionStartedOverrideReady;
wait.axisCount = 1;
wait.axis[0] = 0;

//Execute motion to move axis forward 10000
pos.target = 10000;
wmxlib_CoreMotion->motion->StartMov(&pos);

//Execute trigger motion to move axis backward 10000 at the end of the previous motion
tpos.target = -10000;
wmxlib_CoreMotion->motion->StartMov(&tpos);

//Wait until trigger motion executes
wmxlib_CoreMotion->motion->Wait(&wait);

//Execute trigger motion to move axis forward 20000 at the end of the previous motion
tpos.target = 20000;
wmxlib_CoreMotion->motion->StartMov(&tpos);

//Wait until trigger motion executes
wmxlib_CoreMotion->motion->Wait(&wait);

//Execute trigger motion to move axis backward 20000 at the end of the previous motion
tpos.target = -20000;
wmxlib_CoreMotion->motion->StartMov(&tpos);

The following plots show the position, velocity, and acceleration when the above code is executed.

../_images/WMXDOC_FUNC_WAIT_TRIGGER_MOTION_image0.png

Wait with Override Trigger Motion Example

The trigger condition can be adjusted to execute the trigger motion as an override, before the previous motion command finishes. In this way, a sequence of motion commands can be executed without stopping the axis.

The following code executes a sequence of override motion commands using trigger motion functions and Wait(WaitCondition *pWaitCondition) functions.

Motion::PosCommand pos;
Motion::TriggerPosCommand tpos;
Motion::WaitCondition wait;

//Set position command parameters
pos.axis = 0;
pos.profile.type = ProfileType::Trapezoidal;
pos.profile.acc = 10000;
pos.profile.dec = 10000;
pos.target = 180000;

//Set triggered position command parameters
tpos.axis = 0;
tpos.profile.type = ProfileType::Trapezoidal;
tpos.profile.acc = 10000;
tpos.profile.dec = 10000;
tpos.trigger.triggerAxis = 0;
tpos.trigger.triggerType = TriggerType::CompletedTime;
tpos.trigger.triggerValue = 2000;
tpos.target = 180000;

//Set wait condition parameters
wait.waitConditionType = Motion::WaitConditionType::MotionStartedOverrideReady;
wait.axisCount = 1;
wait.axis[0] = 0;

//Execute motion to move axis forward
pos.profile.velocity = 10000;
wmxlib_CoreMotion->motion->StartPos(&pos);

//Execute trigger motion to change axis velocity after the previous command has executed for 2 seconds
tpos.profile.velocity = 20000;
wmxlib_CoreMotion->motion->StartPos(&tpos);

//Wait until trigger motion executes
wmxlib_CoreMotion->motion->Wait(&wait);

//Execute trigger motion to change axis velocity after the previous command has executed for 2 seconds
tpos.profile.velocity = 30000;
wmxlib_CoreMotion->motion->StartPos(&tpos);

//Wait until trigger motion executes
wmxlib_CoreMotion->motion->Wait(&wait);

//Execute trigger motion to change axis velocity after the previous command has executed for 2 seconds
tpos.profile.velocity = 20000;
wmxlib_CoreMotion->motion->StartPos(&tpos);

//Wait until trigger motion executes
wmxlib_CoreMotion->motion->Wait(&wait);

//Execute trigger motion to change axis velocity after the previous command has executed for 2 seconds
tpos.profile.velocity = 10000;
wmxlib_CoreMotion->motion->StartPos(&tpos);

The following plots show the position, velocity, and acceleration when the above code is executed.

../_images/WMXDOC_FUNC_WAIT_TRIGGER_MOTION_image1.png