Link a slave axis to the master

After setting the cam table, we use SetAxisCam to link a slave axis to a master. You need to carefully choose a cam mode. In the McCamStartMode type, for camAbsolute and camRelative, the slave axis will jump to the synchronized position if it is not in position when cam starts. This may damage the axis. To avoid this, camRampDistance or camRampTime is a better choice – the slave axis is being synchronized after the master starts to move. In this sample we use camRampTime. You should select a cam mode that best meet your needs.

When you use camRamptime, you need to give your axes enough time to synchronize, especially when the slave is far away from its synchronized position, and make sure the waiting time is greater than or equal to the time you set in SetAxisCam, or the InSync state won't be changed to TRUE.

In Cam.cpp, add the following code:

Copy
SetAxisCam
KsCommandStatus AssignCamSlave(int Master, int Slave, int Table)
{
    RtPrintf("Link the master and slave axes for camming.\n\n");

    /*We use camRampTime for the cam mode. The time you set in WaitForCommand
      must be greater than or equal to StartParameter, or the axes won't be in sync.
      If your slave axis is far away from its synchronized position, you need more time to
      sync the two axes.*/
      
    //We wait 5.01 seconds because InSync needs a few more cycles to become TRUE.

    KsCommandStatus cam = WaitForCommand(5.01, FALSE, SetAxisCam(
        Master,   //The index of the master axis.
        Slave,    //The index of the slave axis.
        FALSE,    //Determine whether the cam state is preserved after the motor is disabled.
                  //TRUE: Preserved. FALSE: Not preserved.
        0,        //Master Offset. Offset to add to the master positions in the cam table.
        0,        //Slave Offset. Offset to add to the slave positions in the cam table.
        1,        /*Master Scaling. Ratio to apply to the distance between the master positions
                    and the original position.*/
        1,        //Slave Scaling. Ratio to apply to the slave positions in the cam table.
        camRampTime, //The cam mode.
                     /*Absolute: the slave axis jumps to its target in the table.
                       Alarms may be triggered if the position is too far.*/
                     /*Relative: the current master/slave positions are used as origin for the cam table.
                       The slave axis jumps to its target in the table if it is not in position.*/
                     /*Ramp Distance: the slave axis is moving to its target position.
                       while the master axis moves along the distance provided in StartParameter.*/
                     /*Ramp Time: the slave axis is moving to its target position over
                       the period of time provided in seconds in StartParameter.*/
        5,        //StartParameter.
        mcSetValue,  /*Master Value Source. Value of the master position used.
                       Can be the target position or the actual position.
                       (commanded value and set value are identical)*/
        Table,    //The index of a cam table.
        mcAborting
    ));
    if (cam.Error)
        RtPrintf("SetAxisCam failed: %d\n\n", cam.ErrorId);

    return cam;
}