Gear-in-position
For gear-in-position, we use SetAxisGearInPos to link the master and slave axes.
In Gear.cpp
, add the following code:
Copy
SetAxisGearInPos
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;
}
Output:
Motion command: MoveAxisVelocity
Direction: negative