Switching Between Cams
In principle, you can switch between different cams at any time. However, you should consider some points:
In the cam editor, the position of the slave is defined uniquely as the function value of the cam function. This function is defined in the master value range and can be expressed as follows:
SlavePosition = CAM( MasterPosition )
Because the current position of the master drive usually deviates from the master value range, you need to scale the master position in the definition range of the cam function in order to represent a valid argument:
SlavePosition = CAM( MasterScale*MasterPosition + MasterOffset )
In a similar way, you need to scale the function value (the slave position) if the start of the cam in the mode
Absolute
would lead to a jump:SlavePosition = SlaveScale*CAM( MasterPosition ) + SlaveOffset
You may have to apply both scaling values, which results in the following:
Slaveposition = SlaveScale*CAM( MasterScale*Masterposition + MasterOffset ) + SlaveOffset
The appropriate values for scaling and offset parameters can vary from period to period.
Switching between cams can be done in three ways:
Start the second cam via a second instance of
MC_CamIn
withBufferMode = MC_BUFFER_MODE.Buffered
,StartMode = relative
,MasterAbsolute = FALSE
, andSlaveAbsolute = FALSE
.Important
As of CODESYS SoftMotion version 4.17.0.0
Start of the new cam by assigning
MC_CamIn.CamTableID
to the new cam (no restart of theMC_CamIn
function block required).This variant is recommended if the following points apply to your use case:
All of the following cams should be executed relatively with
MasterAbsolute = FALSE
orSlaveAbsolute = FALSE
.The new cam should start exactly at the end of the previous one.
No other parameters are changed (example:
SlaveOffset
).Important
The jump, which is explained in the following example for periodic cams and
SlaveAbsolute = FALSE
, does not apply to this variant because the next cam is placed exactly at the end positions of the previous cam.The new cam is placed exactly at the end of the previous cam only if the switch to the new cam is done in the same cycle when the previous cam reports
EndOfProfile = TRUE
.
Start of the new cam by restarting the
MC_CamIn
function block.This variant is recommended if parameters have to be changed for the correct function of the new cam (for example,
SlaveOffset
from the following example). The restrictions of the following example apply.
In the following example, it switches from CAM1
to CAM2
:
CAM1
consists of a 5th order polynomial followed by two line segments.

CAM2
consists of two line segments followed by one 5th order polynomial.

When switching between both cams, you should consider the following:
To prevent jumps, the values of velocity and acceleration at the end point of the first cam should agree with the values at the starting point of the second cam. In the example, this condition is fulfilled because the same velocity (=1) and acceleration (=0) is assigned to the end point of
CAM1
and the starting point ofCAM2
.You can start the second cam in
Relative
mode when you have defined the start position of the slave as 0. However, the first cam has to be running innon-periodic
mode. Otherwise, ifCAM1
were periodic, then theRelative
setting would result in a jump.

The magnification shows the transition from CAM1
to CAM2
. The blue lines mark the evaluations of the cam functions at the master positions x1
and x2
.
Now, we will look at the unfavorable case of periodic
:
| |
| The call starts an evaluation of the cam at the master position |
| For the following call of the module, the master position |
| Switch to the new cam |
| Second evaluation at master position |
Select the non-periodic
mode in order to prevent jumps:
| |
| The call starts an evaluation of the cam at the master position |
| For the following call of the module, the master position |
| Switch to new cam. |
| Second evaluation at master position |
To start the cam in Absolute
mode, you need to make sure that the slave is in an appropriate start position. If the value range of the master agrees with the period of the slave, then switching between cams does not have any complications, regardless of whether the cams are periodic or not.
In the example above, you can start CAM2
in Absolute
mode when the periods of the master and slave agree with the master value range of CAM2
(each is 360°).
If not, for example when the period of the slave is 270°
(indicated by the light blue line), then the Absolute
option is not permitted without taking additional actions.

In this case, the slave is at 90° when switching from CAM1
to CAM2
. Starting CAM2
in Absolute
mode causes a jump to 0° (indicated by a gray line).
However, the jump can be prevented by setting the slave offset to the appropriate value of 90°.