Skip to main content

Standard Use Cases

The SM3_Basic library contains superordinate function blocks which do not interact with the drive over the standard set/actual value interface. These function blocks provide commands or change the settings of the drive by reading or writing the parameters of the instance of AXIS_REF_SM3.

Reinitializing a drive

If you changed the drive parameters at runtime, then you need to reinitialize the drive. Example: Change the scaling factor or the modulo period of rotary drives. By calling the SMC3_ReinitDrive function block with a rising edge at the Execute input, the wCommuncationState parameter of the drive is reset and the complete start process of the drive is repeated.

Important

The reinitialization has to wait until the axis reaches the required state SMC_COMSTATE_BASE_COM_INITIALIZATION or higher. Otherwise the error will output SMC_RAG_ERROR_AXIS_NOT_INITIALIZED.

If the communication of a subordinate fieldbus is interrupted, then explicit reinitialization is no longer necessary for CODESYS SoftMotion version 4.18.0.0 and higher. The axis is automatically reinitialized as soon as fieldbus communication is restored. Before version 4.18.0.0, after the communication of the fieldbus was interrupted, an explicit call of SMC3_ReinitDrive was necessary (error with SMC_DI_GENERAL_COMMUNICATION_ERROR) as soon as the fieldbus communication has been restored.

Tip

The old behavior can be restored by setting the AutoRestart input of the SMC_AxisChangeSettings function block to SMC_AXIS_AUTORESTART_MODE.OFF.

Switching a drive on and off

The bRegulatorOn and bDriveStart parameters of the AXIS_REF_SM3 function block control the performance level and deceleration of a drive. Access is made by means of the MC_Power function block.

To release the output stage, you need to set the bRegulatorOn parameter of the MC_Power function block. The drive reports the current status of this process via the bRegulatorRealState output. If it is supported by the drive, a bRegulatorOn reset during the movement will immediately deactivate the torque. In this case, the function block reports an error and sets the axes to the errorstop state.

The bDriveStart variable determines whether or not the drive is permitted to move. The current state of this parameter is located in bDriveStartRealState.

If it is supported by the drive, a bDriveStart parameter reset decelerates the drive with the configured ramp ("QuickStop") during the motion. After that, the drive halts at the reached position as long as set in bRegulatorOn. The axis remains in the stopping state as long as the "QuickStop" mechanism is active (bDriveStart input = FALSE). If the drive has been moved by a function block before, then now it will display CommandAborted. This does not apply to the MC_Stop function block which reports an error and sets the axes to the errorstop state.

Handling mechanical brakes

If it is supported by the drive, the eBrakeControl variable can be set or reset by means of the SMC3_BrakeControl function block. Three different modes are possible.

. SMC3_BrakeSetState
  • SMC_BRAKE_AUTO: The state of the brake is controlled by the drive.

  • SMC_BRAKE_OPEN: The brake is open.

  • SMC_BRAKE_CLOSE: The brake is closed.

The bBrakeClosedRealState variable reports the current status of the brake.

From the point of view of SoftMotion, the control, as well as the state of the mechanical brake, does not depend on the state of the drive or the running motion.

Switching the control mode

With the SMC_SetControllerMode function block, you can switch between the different control modes. The byControllerMode and byRealControllerMode parameters from AXIS_REF_SM3 represent the desired and the current state of the control unit.

Table 1. Possible values

SMC_nocontrol

SoftMotion does not send cyclic data to the drive. This makes it possible to control the drive in other ways.

SMC_torque

Torque/force control

SMC_velocity

Velocity control

SMC_position,

Position control

SMC_current

Power control



After writing the byControllerMode variables, the current state is checked until it matches the desired control mode.

In the meantime, the FB calculates the set value for the axis for example when changing the control mode. Then it sets its bDone output to TRUE. As of this time, it does not prepare any more set values for the axis. This has to be done by other function blocks. Example: The bDone output triggers a MC_MoveVelocity, MC_MoveAbsolute, or MC_Halt function block. Otherwise the axis stops immediately after the control mode is changed.

Homing (drive-controlled)

In SoftMotion, there are two ways to reference a drive:

  • Referencing by a controller in the PLC: This referencing is performed by calling the SMC_Homing function block. The reference signal has to be part of the I/O mapping of the control unit. At the time of referencing, the drive remains in control mode "position control". In general, this method is not particularly accurate because detecting the position (when the reference switch is activated) is based on the current positions obtained by the drive. As a result, the accuracy is limited by the communication cycle.

  • Referencing by a controller in the drive: The reference switch is wired to the drive. Its position is detected faster and with higher accuracy. During the drive-controlled reference path, the drive is in another control mode, in which the drive is controlled by internal processes and does not follow the set values of the control unit. When the reference path ends, the drive is reset to its original control mode.

    The MC_Home function block starts the drive-controlled reference path by setting fReference and bStartReference. In addition, the state of AXIS_REF_SM3 (wState) is set to homing. When the drive passes to the reference path (meaning that it no longer follows the values specified by the control unit), the drive sets the parameter to TRUE. To display the end of the reference path, the driver sets the values of bStartReference and bStartReferenceRealState to FALSE.

Latching

You can detect the position of an axis in many ways, depending on the drive functions which the drive supports:

  • The drive detects the axis position itself (integrated or by switching on an external sensor). Because the actual position is transferred by the drive itself, the transfer time of the signal is minimal and precise.

  • The current position of the axis is determined independently of the drive and transferred to the controller via an input. Occurring latency of the controller input and the application cycle make this method less precise.

    When the position of the drive itself is transferred, it is processed directly in the application typically by the respective driver depending on the manufacturer. To determine the position of this kind of axis, you can use the MC_TouchProbe function block. It allows for the recording of the axis position to a configurable trigger and within a position window. If the position is not transferred by the drive, then it has to be passed to the device driver of the drive, for example for control.

    For more information, see: Position Control on the Controller with SM_Drive_PosControl