Gearing complete code

This page contains the complete code of Gearing.

In Gear.cpp, your gear code should be as follows:

Copy
#include "RT_Project_01.h"
#include "AxisConfiguration.h"
#include "Gear.h"

KsCommandStatus AssignGearSlave(int Master, int Slave)
{
    RtPrintf("Link a slave to the master for gearing.\n\n");

    KsCommandStatus gear = WaitForCommand(5, FALSE, SetAxisGear(
        Master,   //The index of the master axis.
        Slave,    //The index of the slave axis.
        FALSE,    //Determine whether the gear state is preserved after the motor is disabled.
        GEAR_NUMERATOR / GEAR_DENOMINATOR,   //The gear ratio.
        //For example, if the ratio is 3:2, the slave moves three units and master moves two.
        mcSetValue,   /*Master Value Source. Value of the master velocity used.
                        Can be the target velocity or the actual velocity.*/
        MAXIMUM_ACCELERATION,   //Acceleration for gearing in.
        MAXIMUM_DECELERATION,   //Deceleration for gearing in.
        MAXIMUM_JERK,           //Jerk fo gearing in.
        mcAborting              //Define how to blend the velocity of two functions.
    ));
    if (gear.Error)
        RtPrintf("SetAxisCam failed: %d\n\n", gear.ErrorId);

    return gear;
}

KsCommandStatus AssignGearInPosSlave(int Master, int Slave, double MasterPosition, double SlavePosition)
{
    RtPrintf("Link a slave to the master for gearing in position.\n\n");

    KsCommandStatus gearInPos = WaitForCommand(5, FALSE, SetAxisGearInPos(
        Master,   //The index of the master axis.
        Slave,    //The index of the slave axis.
        FALSE,    //Determine whether the gear state is preserved after the motor is disabled.
        GEAR_NUMERATOR / GEAR_DENOMINATOR,   //The gear ratio.
        mcSetValue,       /*Master Value Source. Value of the master velocity used.
                            Can be the target velocity or the actual velocity.*/
        MasterPosition,   /*The master's position where the slave is in sync with the master.
                            It's better to give it a number instead of setting it zero.*/
        SlavePosition,    /*The slave's position where the slave is in sync with the master
                            It's better to give it a number instead of setting it zero.*/
        mcCatchUp,        //Define the way to synchronize.
                          /*mcShortest: the slave takes the shortest way to the target position.
                            mcCatchUp: the slave moves fast to catch up the master.
                            mcSlowDown: the slave moves slowly in sync with the master.*/
        0,                /*MasterStartDistance: the distance for the master to travel to synchronize
                            with the slave, when the slave axis is started to get into synchronization.
                            This will be calculated automatically if not provided.*/
        MAXIMUM_VELOCITY,       //The maximum velocity during the synchronization phase.
        MAXIMUM_ACCELERATION,   //The maximum acceleration during the synchronization phase.
        MAXIMUM_DECELERATION,   //The maximum deceleration during the synchronization phase.
        MAXIMUM_JERK,           //The maximum jerk during the synchronization phase.
        mcAborting              //Define how to blend the velocity of two functions.
    ));
    if (gearInPos.Error)
        RtPrintf("SetAxisGearInPos failed: %d\n\n", gearInPos.ErrorId);

    return gearInPos;
}

VOID RemoveGearSlave(int Index)
{
    RtPrintf("Exit gearing.\n\n");

    //Remove the gear.
    KsError removeGear = ReleaseAxis(Index);
    if (removeGear != errNoError)
        RtPrintf("The slave axis has not been detached: %x\n\n", removeGear);

    else if (removeGear == errNoError)
        RtPrintf("The slave axis has been detached.\n\n");
}