Define a cam table

Before we link two axes, we need to define the range they move, which is assigned by a cam table. We divide the cam table code into steps to explain. In the last part, we combine all the code for you to see the completed one.

In Cam.cpp, add the following code:

  1. Create the cam table Table using the McCamTable structure and set the attributes for Table. You can create many tables if you want. We create only one here to demonstrate how it works.
  2. Copy
    VOID DefineCamTable(int Index)
    {
        RtPrintf("Define a cam table.\n\n");

        //Create an instance of the MC_CamTable structure, which defines a cam table.
        McCamTable Table = { 0 };
        Table.MasterAbsolute = MASTER_ABSOLUTE;
        Table.SlaveAbsolute = SLAVE_ABSOLUTE;
        Table.Periodic = PERIODIC;
        Table.InterpolationType = INTERPOLATION_TYPE;
        Table.Length = TABLE_LENGTH;

  3. Set the positions for the master and slave axes in the cam table. This is the range they can move when both axes are synchronized. The range is defined in the header file. PointParameters are the additional parameter for the table points. Because we use linear interpolation, they are set to zero.
  4. Copy
        //Define the positions of the master and slave axes in the cam table.
        double MasterPositions[TABLE_LENGTH] = MASTER_POSITIONS;
        double SlavePositions[TABLE_LENGTH] = SLAVE_POSITIONS;
        double PointParameters[TABLE_LENGTH] = POINT_PARAMETERS;

  5. Use SetCamTable to select the cam table we created. We use WaitForCommand to give it some time to finish.
  6. Copy
        KsCommandStatus camTable = WaitForCommand(5, FALSE, SetCamTable(Index, Table, MasterPositions,
            SlavePositions, PointParameters));
        if (camTable.Error)
            RtPrintf("SetCamTable failed: %d\n\n", camTable.ErrorId);
    }

Complete code

The complete code should be as follows:

Copy
SetCamTable
VOID DefineCamTable(int Index)
{
    RtPrintf("Define a cam table.\n\n");

    //Create an instance of the MC_CamTable structure, which defines a cam table.
    McCamTable Table = { 0 };
    Table.MasterAbsolute = MASTER_ABSOLUTE;
    Table.SlaveAbsolute = SLAVE_ABSOLUTE;
    Table.Periodic = PERIODIC;
    Table.InterpolationType = INTERPOLATION_TYPE;
    Table.Length = TABLE_LENGTH;

    //Define the positions of the master and slave axes in the cam table.
    double MasterPositions[TABLE_LENGTH] = MASTER_POSITIONS;
    double SlavePositions[TABLE_LENGTH] = SLAVE_POSITIONS;
    double PointParameters[TABLE_LENGTH] = POINT_PARAMETERS;

    KsCommandStatus camTable = WaitForCommand(5, FALSE, SetCamTable(Index, Table, MasterPositions,
        SlavePositions, PointParameters));
    if (camTable.Error)
        RtPrintf("SetCamTable failed: %d\n\n", camTable.ErrorId);
}