Control Mode complete code

This page contains the complete code of Control modes.

In AxisConfiguration.cpp, your Control Mode code should be as follows:

Copy
#include "RT_Project_01.h"
#include "AxisConfiguration.h"
using namespace std;

VOID GetAvailableControlMode(int Index)
{
    RtPrintf("Get the available control modes.\n");

    int Modes = 0;
    char trueFalse[] = "false";
    KsError nRet = errNoError;
    //Use a string array to store the list of control modes.
    string controlMode[10] = { "modeManual", "modeDirectPos", "modeDirectVel",
        "modeDirectTor", "modePidVel", "modePidTor", "modeMasterIntPos",
        "modeMasterIntVel", "modeMasterIntTor", "modeSlaveInt" };

    //Get the available control modes from an axis.
    nRet = GetAxisAvailableControlModes(Index, &Modes);

    /*Print the control modes in decimal format. The output is 67. The bits of Modes are 01000011.
      Since we use accessPos in SystemInitialization.h, modeManual, modeDirectPos, and modeMasterIntPos are true. 
      modeSlaveint is false because it is not supported yet.
      The output number varies between access modes.*/
    RtPrintf("Control Modes: %d\n", Modes);

    /*KINGSTAR offers 10 control modes.
      To check what mode available to the axis, we use bitwise shift.*/

    for (int i = 0; i < 10; i++)
    {
        //Reset trueFalse to "false."
        strcpy(trueFalse, "false");

        if (Modes & (1 << i))
            strcpy(trueFalse, "true");    //Set trueFalse to "true."

        //Print the control modes with flags.
        /*Use c_str() to convert a string object to a C-style string.
          You can see the available control modes in text instead of seeing them in number.*/
        RtPrintf("Control mode: %s is %s\n", controlMode[i].c_str(), trueFalse);
    }
    RtPrintf("\n");
}

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;
            }
        }
    }
}