Skip to main content

Controlling a Cam Drive with a Virtual Time Axis

See the PLCopenMulti.project sample project in the installation directory of CODESYS under ..\CODESYS SoftMotion\Examples.

This example demonstrates how to implement a periodic cam on a linear drive. The example also shows how to use the tappet function.

  1. Insert a cam named Example in the device tree below Application. Open the cam in the editor.

  2. Define a tappet on the Tappet tab.

    • X: 8.0

    • Positive pass: Invert

    • Negative pass: Invert

  3. Insert a virtual drive named Drive in the device tree below SoftMotion General Axis Pool. For this axis, select the axis type Modulo with a modulo value of 360.

  4. Insert another virtual drive named Virtual. For this axis, select the Modulo axis type with a modulo value of 10.

  5. Create a MOTION_PRG program in CFC.

    PROGRAM MOTION_PRG
    VAR
            power1, power2: MC_Power;
            TableSelect: MC_CamTableSelect;
            CamIn: MC_CamIn;
            Tappet: SMC_GetTappetValue;
            MoveVirtual: MC_MoveVelocity;
    END_VAR
  6. Insert a box element and assign the variable power1 to it. The box element is used for switching on the Drive.

    Configure the inputs as follows:

    • Axis: Drive

    • Enable: TRUE

    • bRegulatorOn: TRUE

    • bDriveStart TRUE

  7. Insert a box element and assign the variable power2 to it. The box element is used for switching on the Virtual drive.

    Configure the inputs as follows:

    • Axis: Virtual

    • Enable: TRUE

    • bRegulatorOn: TRUE

    • bDriveStart TRUE

  8. Insert a box element and assign the variable MoveVirtual to it. The box element is used for moving the virtual master.

    Configure the inputs as follows:

    • Axis: Virtual

    • Execute: power2.Status

    • Velocity: 2

    • Acceleration 10

    • Deceleration 10

    • Direction positive

  9. Insert a box element and assign the variable TableSelect to it. The box element is used for selecting a cam.

    Configure the inputs as follows:

    • Master: Virtual

    • Slave: Drive

    • CamTable: Example

    • Execute TRUE

    • Periodic TRUE

    • MasterAbsolute TRUE

    • SlaveAbsolute TRUE

  10. Insert a box element and assign the variable CamIn to it. The box element implements the selected cam plate.

    Configure the inputs as follows:

    • Master: Virtual

    • Slave: Drive

    • Execute power1.Status

    • MasterOffset: 0

    • SlaveOffset: 0

    • MasterScaling: 1

    • SlaveScaling: 1

    • StartMode: absolute

    • CamTableID: TableSelect.CamTableID

    • VelocityDiff: 1

    • Acceleration: 1

    • Deceleration: 1

    • TappetHysteresis: 1

  11. Insert a box element and assign the variable Tappet to it. The box element checks the setting of the cam switch.

    Configure the inputs as follows:

    • Tappets: CamIn.Tappets

    • iID: 1

    • bInitValue FALSE

    • bSetInitValueAtReset: FALSE

    The tappet is defined as an inverting tappet. For this reason, its value is changed every 10 seconds.

  12. The sample project provides a visualization for checking the individual function blocks and the position of the axes.

  13. Add the call of the MOTION_PRG program to the task MainTask.

  14. Download the project to the controller and start it.