Join us today!
Creating a CAM Table in TwinCAT
Sometimes, just the gear ratio wouldn't be enough to define the relationship between master and slave axes synchronization. We can use a cam table to define complex relations between axes.
In TwinCAT 3, you can generate CAM tables using the demo license, however they won't be saved when the project is saved without having an actual license. Go to 'Manage Licenses' tab and add the licenses below :
The warning below will remind you that storing the CAM data is not possible with the demo license.
Before creating the table, add 2 axes to the project and name them as 'Master' and 'Slave'.
Declare the axes in your program and build the project. After the build, we can link the axes to the PLC.
Master : AXIS_REF; Slave : AXIS_REF;
To create a table, right click on the 'Tables' under NC-Task and select 'add a new item'.
To open the settings for the table, double click on the added table item and change the name and set the assigned axis.
To add the slave, right click on the 'Master' table and a new item.
Rename the name and assign an axis for the table.
Double click on Slave table and select the insert point tool to start adding the positions on the table.
Select 6 points on the table and an end point. All the selected point information will be shown at the top as well.
You can adjust the X, Y points on the section below. Select the point you would like to change and type the value and hit enter. After setting the point values to rounded values, the graph will look smoother.
When creating position points, it would be wise to utilize the velocity and acceleration graphs to eliminate sudden jerky movements for our cam table. Right click on the graph, and select the 'Select 2 Graph View' to display the velocity graph and select the 'Select 3 Graph View' to display the acceleration graph.
If you look at the velocity graph, you will notice the sudden changes which would cause unexpected jerky movements. We would want to have a continues velocity graph for cam motion control. To achieve this, we need to change the function method to 'Automatic' for the points shown below.
After changing function method from Synchron to 'Automatic', we can see that the velocity graph is not discrete anymore.
Add the Tc2_MC2 library for motion function blocks and the Tc2_MC2_Camming library for CAM function blocks. Also, add the code below in the MAIN program.
PROGRAM MAIN VAR fbPowerMaster : MC_Power; fbPowerSlave : MC_Power; fbMoveMaster : MC_MoveRelative; fbCamIn : MC_CamIn; Master : AXIS_REF; Slave : AXIS_REF; bEnableMasterAxis : BOOL := FALSE; bEnableSlaveAxis : BOOL := FALSE; bMoveMasterAxis : BOOL := FALSE; fSetPosition : LREAL := 360; fSetVelocity : LREAL := 150; bMoveDone : BOOL := FALSE; END_VAR //Power Axes fbPowerMaster( Axis:= Master, Enable:= bEnableMasterAxis, Enable_Positive:= TRUE, Enable_Negative:= TRUE, Override:=100); fbPowerSlave( Axis:= Slave , Enable:= bEnableSlaveAxis, Enable_Positive:= TRUE, Enable_Negative:= TRUE, Override:= 100); //Cam In fbCamIn( Master:= Master, Slave:= Slave, Execute:= bStartCamIn, CamTableID:= 1, InSync=> bCamInSync); //Move Master fbMoveMaster( Axis:= Master, Execute:= bMoveMasterAxis, Distance:= fSetPosition, Velocity:= fSetVelocity, Done=> bMoveDone);
We have used the MC_Power function block to enable the Master and Slave Axis. MC_MoveRelative function block is used to move the master axis. MC_CamIn function block allows us to start the cam table and coupling. For the CamTableID, use the ID number you put for the cam table.
Enable the axes by setting bEnableMasterAxis and bEnableSlaveAxis variables to TRUE. Go to NC Online functions to verify the axis enabling are set.
Set the bStartCamIn variable to TRUE and check the 'online function' of Slave axis to verify the axis status as coupled.
Before setting the bMoveMasterAxis variable to TRUE, you can add a scope project into this project to plot the Master and Slave axes positions.
Start recording the chart and set the bMoveMasterAxis to TRUE. You should see the graph below:
Green- Master Axis, Blue - Slave Axis
To modify the data points on the CAM Table in the plc logic, add these variables and the code in your program:
//To modify the points on the cam table fbReadCamTable : MC_ReadMotionFunction; fbWriteCamTable : MC_WriteMotionFunction; stCamRef : MC_CAM_REF; stCamTable : ARRAY [1..6] OF MC_MotionFunctionPoint; bReadPoints : BOOL; bWritePoints : BOOL; bChangePoints : BOOL; //Read points from the cam table and modify them stCamRef.TableType := MC_TABLETYPE_MOTIONFUNCTION; stCamRef.pArray := ADR(stCamTable); stCamRef.ArraySize := SIZEOF(stCamTable); stCamRef.NoOfColumns := 1; stCamRef.NoOfRows := 6; fbReadCamTable( Execute:= bReadPoints, CamTableID:= 1, PointID:= 1, NumPoints:= 6, CamTable:= stCamRef); IF bChangePoints THEN stCamTable[3].MasterPos := 125.0; stCamTable[3].SlavePos := 40.0; stCamTable[5].MasterPos := 222.0; stCamTable[5].SlavePos := 65.0; bChangePoints := FALSE; END_IF fbWriteCamTable( Execute:= bWritePoints, CamTableID:= 1, PointID:= 1, NumPoints:= 6, CamTable:= stCamRef);
We are using the MC_ReadMotionFunction to read data points from the CAM table and the MC_WriteMotionFunction to write the new points into the CAM table. CamTableID is the ID we have used for the CAM table. PointID is the ID from which point we would like to read/write. NumPoints is how many points we want to read/write. For reading all points, you can use 0.
Since we have 6 points in our CAM table, we have set the stCamRef.NoOfRows and the NumPoints to 6. Set the bReadPoints to TRUE and check the stCamTable array to see the current data points. Set the bChangePoints to TRUE to update the 3rd and the 5th data points. Set the bWritePoints to TRUE to write the new data points to the CAM table. Retrigger the bMoveMasterAxis and observe the new motion pattern for the Slave axis on the scope.
You can also update the CAM table by using the 'Upload' button.
You can now see the CAM table graph with the updated new data points.
In case you want to say thank you !)
We'd be very grateful if you could share this community with your colleagues and friends. You can also buy us a coffee to keep us fueled 😊 This is the best way to say thank you to this project and support your community.
twinControls - https://twincontrols.com/
https://github.com/runtimevic
https://github.com/TcMotion
https://www.youtube.com/playlist?list=PLEfi_hUmmSjFpfdJ6yw3B9yj7dWHYkHmQ
https://github.com/VisualPLC
- 17 Forums
- 267 Topics
- 924 Posts
- 0 Online
- 737 Members