Get the available control modes

In addition to reading your servo drive's manual, you can use GetAxisAvailableControlModes to check the control modes your axis can use. These modes are affected by access modes. For example, if you select accessPos as your access mode, the available control mode will be modeDirectPos, modeMasterIntPos, and modeManual. By default, it uses modeMasterIntPos. For more information about the access modes and the control modes they support, check the KsAccessMode type.

  1. In RT_Project_01.h, make sure #include <string> is added because we are going to use strings in our code. We have talked about this in Motion states. See Axis Configration header to learn how to add this line.
  2. Copy
    #include <string>

    NOTE:  The original code may be written as #include <string.h>. Change it as per above.

  3. In AxisConfiguration.cpp, make sure the following code is added. We have talked about this in Motion states. See Control Mode complete code to learn how to add them.
  4. Copy
    #include "RT_Project_01.h"
    #include "AxisConfiguration.h"
    using namespace std;
  5. Under using namespace std;, add the following code. The long comments explain what the code is doing. They can be omitted if you just want the code.
  6. Copy
    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");
    }