Controlling a Cam Drive with a Virtual Time Axis
Refer to the sample project PLCopenMulti.project in the installation directory of CODESYS.
This example demonstrates how to implement a periodic cam on a linear drive. The example also demonstrates how to use the tappet function.
Insert a cam named Example in the device tree below Application. Open the cam in the editor.
Define a tappet in the Tappet tab.
X: 8.0
Positive pass: Invert
Negative pass: Invert
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.
Insert another virtual drive named Virtual. For this axis, select the axis type Modulo with a modulo value of 10.
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
Insert a function block and assign the variable power1 to it. The function block is used for switching on the Drive.
Configure the inputs as follows:
Axis: Drive
Enable: TRUE
bRegulatorOn: TRUE
bDriveStart TRUE
Insert a function block and assign the variable power2 to it. The function block is used for switching on the Virtual.
Configure the inputs as follows:
Axis: Virtual
Enable: TRUE
bRegulatorOn: TRUE
bDriveStart TRUE
Insert a function block and assign the variable MoveVirtual to it. The function block 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
Insert a function block and assign the variable TableSelect to it. The function block 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
Insert a function block and assign the variable CamIn to it. The function block 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
Insert a function block and assign the variable Tappet to it. The function block 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.
The sample project provides a visualization for checking the individual function blocks and the position of the axes.
Add the call of the MOTION_PRG program to the task MainTask.
Load the project to the controller and start it.