Reset, enable, and disable an axis

To reset an axis, we use ResetAxis; to enable and disable an axis, we use PowerAxis. An axis needs some time to be reset, enabled, and disabled, so we use WaitForCommand to give each function some time to finish their work.

Reset and power functions

ResetAxis: makes the transition from the state ErrorStop to Standstill or Disabled by resetting all internal axis-related errors — it doesn't affect the output of the function instances.

PowerAxis: enables or disables the operation of a servo motor. It can also control the direction an axis moves.

WaitForCommand: waits for a command to be finished.

Code

In SingleAxisMotion.cpp, add the following code. We use two functions to demonstrate the code: EnableAxis and DisableAxis. Before we enable an axis, we use ResetAxis to reset it in case it has an alarm. Because an axis needs some time to be reset, enabled, or disabled, we give ResetAxis and PowerAxis 5 milliseconds to finish its work. If it is not done within the time span, it will be aborted.

Copy

EnableAxis

BOOL EnableAxis(int Index)
{
    //Reset an alarm.
    KsCommandStatus status = WaitForCommand(5, TRUE, ResetAxis(Index));
    if (status.Error)
    {
        RtPrintf("ResetAxis failed: %d\n", status.ErrorId);
        return FALSE;
    }

    //Enable an axis. You can limit the direction the axis moves.
    status = WaitForCommand(5, TRUE, PowerAxis(Index, TRUE, TRUE, TRUE));
    if (status.Error)
    {
        RtPrintf("PowerAxis failed: %d\n", status.ErrorId);
        return FALSE;
    }

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

    return TRUE;
}

 

Copy

DisableAxis

BOOL DisableAxis(int Index)
{
    //Disable an axis.
    KsCommandStatus status = WaitForCommand(5, TRUE, PowerAxis(Index, FALSE, TRUE, TRUE));
    if (status.Error)
    {
        RtPrintf("PowerAxis failed: %d\n", status.ErrorId);
        return FALSE;
    }
    
    RtPrintf("Disable Axis %d.\n\n", Index);

    return TRUE;
}