Emergency group stop

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

Functions

StopGroup: decelerates a group until the velocity of the group is zero. While the group is decelerating, it is in the GroupMoving state. When the group's velocity is zero, it is in the GroupStopping state. No function can move the group when it is in GroupStopping. To leave GroupStopping and go to GroupStandstill, use ReleaseGroup.

WaitForCommand: waits for a command to be finished.

ReleaseGroup: release a group from the GroupStopping state.

 

To test StopGroup, use it with a continuous move command such as JogGroup. Because a group needs some time to be stopped, we use WaitForCommand to give it a few seconds to finish its work. After a group is stopped, it is locked in the GroupStopping state. To free the group from GroupStopping, we use ReleaseGroup.

Code

In GroupMotion.cpp, add the following code. Notice that we use the function GetAGroupState that displays the state of a group in string. For more information about GetAGroupState, see Chapter 9 > Get the state of a group.

Copy
StopGroup
VOID GroupStop(int Group)
{
    //Give some time for the group to be stopped.
    KsCommandStatus stop = WaitForCommand(5, FALSE, StopGroup(Group, MAXIMUM_DECELERATION,
        MAXIMUM_JERK));
    if (stop.Error)
        RtPrintf("StopGroup failed: %d\n", stop.ErrorId);

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

    //Get the state of the group. The group should be in the GroupStopping state.
    GetAGroupState(Group);

    //Release the group from the GroupStopping state.
    RtPrintf("Release the group from the GroupStopping state.\n\n");

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

    //Give some time for the group state to be changed, and get the state again.
    Sleep(30);
    GetAGroupState(Group);
}

 

Output:

Jog group: while the axes are jogging, they keep moving without a target or distance until you stop them, so the end positions are where they are detected by GetAGroupPosition.