Forecast for Single-Axis Movements
The BasicMotion_Forecast.project
sample project is located in the installation directory of CODESYS under ..\CODESYS SoftMotion\Examples
.
This example shows how to define a forecast for an axis in order to get information about the state of the axis in the future.
In the example, an absolute movement is executed on an axis to position 10. By setting a forecast of 300 ms on the axis, you can find out in advance in the application when and with what dynamics the axis will move through position 8.
For more information all about the forecast for axes, see: Forecast
Structure of the application
The application consists of a PLC_PRG
program and a Trace
.
PLC_PRG
The virtual axis is switched on in the
STATE_POWER_DRIVE
state. Then theSMC_SetForecast
function block is used to define a forecast of 300 ms for the axis in theSTATE_SET_FORECAST
state. TheSMC_GetForecast
function block can be used to read the set forecast for the axis.In the
STATE_MOVE_TO_POSITION
state, an absolute movement to position 10 is executed. TheSMC_GetTravelTime
function block is also started. The function block is used to read the time when the axis will reach position 8. TheSMC_ReadSetValues
function block is used to determine the dynamics at position 8. A time offset can be passed to this function block where the dynamics of the axis should be read. In our case, we pass the duration which the axis needs to reach position 8.Trace
You can use the trace to track the movement of the virtual axis. The current position, velocity, and acceleration of the axis are recorded. The duration up to position 8 and the dynamics of the axis at this position are also displayed.
Note that the duration of
SMC_GetTravelTime
is specified relative to the start of the cycle. The set values of the axis correspond to those at the end of the cycle.
Commissioning
Build the application and download it to a controller.
Start the trace and the application.
In the trace, you can track the movement of the virtual axis. Pay attention to the duration up to position 8 and the dynamics at position 8.