Set a control mode
To set a control mode, we use the SetAxisControlMode function.
Keep in mind these things:
- The access mode affects the control mode you can use. If you set a control mode that is not supported by the access mode you selected, the mode cannot be switched.
- If EnableSynchronizedControlMode is enabled, you can change the control mode when your axis is enabled as long as your axis supports this feature, otherwise you can change the control mode only when your axis is disabled.
- When EnableSynchronizedControlMode is enabled, the control mode is changed through PDO, which usually takes 3-5 cycles; when it is disabled, the control mode is changed through SDO, which takes about 10 cycles. Not all drives support this feature.
Code
In AxisConfiguration.cpp
, add the following code:
Copy
VOID SetControlMode(int Index)
{
RtPrintf("Set a control mode.\n");
string controlMode[10] = { "modeManual", "modeDirectPos", "modeDirectVel",
"modeDirectTor", "modePidVel", "modePidTor", "modeMasterIntPos",
"modeMasterIntVel", "modeMasterIntTor", "modeSlaveInt" };
//Set the mode depending on your access mode and needs.
McControlMode Mode = modeMasterIntPos;
KsCommandStatus status = WaitForCommand(5, TRUE, SetAxisControlMode(Index, Mode));
if (status.Error)
RtPrintf("SetAxisControlMode failed: %d\n", status.ErrorId);
else if (status.Done)
{
for (int i = 0; i < 10; i++)
{
if (Mode == i)
{
RtPrintf("The current control mode: %s\n\n", controlMode[i].c_str());
break;
}
}
}
RtPrintf("\n");
}