Set an access mode

In Chapter 2 > Start the KINGSTAR Subsystem, you have learned how to set an access mode using SetAxisAccessMode and change the control mode through PDO using EnableSynchronizedControlMode. These functions are used before Start. The following code helps you review them.

In SystemInitialization.cpp, your code should be as follows:

Copy
#include "RT_Project_01.h"
#include "SystemInitialization.h"

BOOL StartKingstar() {
    ......
    
    /*We use accessPos, which supports modeDirectPos, modeMasterIntPos, and modeManual.
      By default, it uses modeMasterIntPos.*/
    nRet = SetAxisAccessMode(ACCESS_MODE);
    if (nRet != errNoError) {
        RtPrintf("SetAxisAccessMode failed: %x\n", nRet);
        WaitForCommand(5, FALSE, Stop());
        Destroy();
        return FALSE;
    }


    /*Enable the control mode change through PDO. This way, you can change
      the control mode while the drive is enabled, but when you change the mode,
      the motor can't be running. Not all drives support this feature.*/

    //SYNCHORNIZED_CONTROL_MODE is TRUE.
    nRet = EnableSynchronizedControlMode(SYNCHORNIZED_CONTROL_MODE);
    if (nRet != errNoError) {
        RtPrintf("EnableSynchronizedControlMode failed: %x\n", nRet);
        WaitForCommand(5, FALSE, Stop());
        Destroy();
        return FALSE;
    }
    
    ......
}