Emergency stop

An emergency stop is to decelerate an axis as fast as possible, in case the axis crashes into something or runs into some problems.

Functions

StopAxis: decelerates an axis until the velocity of the axis is zero. While the axis is decelerating, it is in the Discrete Motion state. When the axis' velocity is zero, it is in the Stopping state. No function can move the axis when it is in the Stopping state. To leave the Stopping state and go to Standstill, use ReleaseAxis.

WaitForCommand: waits for a command to be finished.

ReleaseAxis: releases an axis from the Stopping state or detaches it from camming or gearing.

 

To test StopAxis, use it with a continuous move command such as MoveAxisContinuousAbsolute or MoveAxisContinuousRelative. Because an axis needs some time to be stopped, we use WaitForCommand to give it a few seconds to complete its work. After an axis is stopped, it is locked in the Stopping state. To free the axis from Stopping, we use ReleaseAxis.

Code

In SingleAxisMotion.cpp, add the following code. Notice that we use the function GetAnAxisState that displays the state of an axis in string. For more information about GetAnAxisState, see Get and set values.

Copy
StopAxis
VOID Stop(int Index)
{
    //Give some time for the axis to be stopped.
    KsCommandStatus status = WaitForCommand(5, FALSE, StopAxis(Index, MAXIMUM_DECELERATION, MAXIMUM_JERK));
    if (status.Error)
        RtPrintf("StopAxis failed: %d\n", status.ErrorId);

    RtPrintf("Stop Axis %d.\n\n", Index);

    //Get the state of the axis. The axis should be in the Stopping state.
    GetAnAxisState(Index);

    //Release the axis from the Stopping state.
    RtPrintf("Release the axis from the Stopping state.\n\n");

    KsError error = ReleaseAxis(Index);
    if (error != errNoError)
        RtPrintf("ReleaseAxis failed: %x\n", error);

    //Give some time for the axis state to be changed, and get the state again.
    Sleep(5);
    GetAnAxisState(Index);
}

 

Output:

MoveAxisContinuousRelative Distance: 11000

For MoveAxisContinuousRelative, an axis continues to move after it travels the distance, so the end position won't be the same as the distance.