Project Example: Main Motion (Structure Text)
|Language:||English • 中文(简体)|
The task's purpose is to use motion Function Blocks such as MC_MoveRelative, MC_MoveVelocity and mc_halt.
The main program initializes a startup process in the softMC.
After the startup process is done, a global variable is set and programs 'Axis1' and 'Axis2' are called.
The application uses two drives and their outputs.
After installation of device description file (created by the Configurator) to Device Repository, the drive's address will be declared in the Axis Pool:
In the EtherCAT Slaves section, we can find the I/O mapping for each device.
In the picture below Input1, Input2, Input3, Input4, Input5, Input11, Output1, Output2, Output3, Output4 and Output5 are declared as new variables (can also be mapped as existing variables):
The main program uses 'softMC_Startup' FB ('mc_st' Instance) to initialize a startup process in the softMC.
When the process is done, a global variable will be set TRUE. After that, programs 'Axis1' and 'Axis2' are called.
Axis POU - Declaration Section
The declaration section in the Axis programs contains the following instances (as shown in the next picture):
1. MC_POWER_01 - an instance of MC_Power FB.
This Function Block enables/disables an axis.
If the axis is associated with a real drive, a state machine is invoked to enable/disable the drive via PDO.
If the axis is simulated, a MC-Basic subroutine is invoked to enable/disable the axis.
2. MC_MoveVelocity_01 - an instance of MC_MoveVelocity FB.
This Function Block commands a never ending controlled motion at a specified velocity.
3. MC_halt_01 - an instance of MC_halt FB.
This Function Block commands a controlled motion stop. The axis is moved to the state ‘DiscreteMotion’, until the velocity is zero. With the ‘Done’ output set, the state is transferred to ‘Standstill’.
4. MC_MoveRelative_01 - an instance of MC_MoveRelative FB.
This Function Block commands a controlled motion of a specified distance relative to the set position at the time of the execution.
5. mc_reset_01 - an instance of MC_Reset FB.
This Function Block makes the transition from the state ‘ErrorStop’ to ‘Standstill’ or ‘Disabled’ by resetting all internal axis-related errors. It does not affect the output of the FB instances.
Axis POU - Implementation Section
Note: Programs 'Axis1' and 'Axis2' are similar.
Output5 is turned on when POU is called.
Input1, Input2, Input3 and Input4 are attached to Output1, Output2, Output3 and Output4 respectively.
If Output1 is triggered, the MC_Power FB is enabled.
If Axis is enabled, Input4 is not on, MC_MoveRelative_01.Busy has a False value and a rising edge is detected in Input2, then MC_MoveVelocity FB is executed with a positive direction.
If Axis is enabled, Input4 is not on, MC_MoveRelative_01.Busy has a False value and a rising edge is detected in Input3, then MC_MoveVelocity FB is executed with a negative direction.
'jog1_ftrig' and 'jog2_ftrig' are instances of F_TRIG FB, which sets the falling edge detection for Input2 and Input3 respectively.
When a falling edge is detected in Input2 or Input3, then a boolean variable 'stop_jog" is triggered.
If axis is enabled and 'stop_jog' is TRUE, the MC_halt FB is executed.
If Input2 and Input3 are not on, Input 4 is on, then MC_MoveRelative is executed.
If Input11 is on, then MC_Reset is executed.
The program is controlled by a graphic interface:
When the startup process of softMC is done, the blue lamp is turned on.
The user can turn on and off Inputs 1 - 4 for each drive and watch their status in the green lamps.
The axes actual velocity is displayed by velocity meters.