Direction

The moving direction of an axis is a safety issue. Mostly you need the axis to move in positive and negative directions. In some cases you may need to limit the direction the axis can move.

To limit the direction an axis moves, use the function PowerAxis, which is also used to enable or disable an axis. Before we enable an axis, we use ResetAxis to reset the axis in case it has an alarm. We'll introduce more about PowerAxis and ResetAxis in Chapter 5.

In AxisConfiguration.cpp, add the following code:

Copy
VOID LimitDirection(int Index)
{
    RtPrintf("Limit the direction of an axis.\n");

    //Reset an axis.
    KsCommandStatus status = ResetAxis(Index);
    if (status.Error)
        RtPrintf("ResetAxis failed: %d\n", status.ErrorId);
    
    Sleep(30);

    //Enable an axis and only allow it to move in negative direction.
    PowerAxis(
        Index,  //The index of an axis.
        TRUE,   //TRUE to enable the axis, FALSE to disable the axis.
        FALSE,  //Forbid the axis to move in positive direction.
        TRUE    //Allow the axis to move in negative direction.
    );
    if (status.Error)
        RtPrintf("PowerAxis failed: %d\n", status.ErrorId);

    Sleep(30);

    RtPrintf("\n");
}