Motion Control
The SoftPLC supports motion control using the standard PLCopen Motion Control function blocks. PLCopen Motion Control is supported by most PLC vendors, so programs written for the SoftPLC can be easily transferred to a physical PLC.
The SoftPLC plans the motion of each axis in every simulation step, and sends the resulting position setpoints to a motor in the model. The motor then follows the setpoints, provided that the physics permits its motion. The controller of the motor must be set to None, so that the motor follows the setpoints directly rather than planning its own motion. Sensors in the model, such as home switches and limit switches, can be connected to the axis.
This page describes the motion of single axes. To move several axes together along a path, such as the axes of a gantry or the joints of a robot, please see the coordinated motion page.
Contents
- Axes
- Axis Settings
- Binding Axes to Motors
- Writing a Motion Program
- Axis States
- Command Behavior
- Buffer Modes
- Motion Profiles
- Limits and Errors
- Homing
- Modulo Axes
- Limitations
Axes
An axis represents a single motor, such as the drive of a conveyor or a linear actuator. Each axis is defined by an axis definition file. To create an axis, click the add button in the file explorer of the script editor, select SoftPLC in the template window and then select Axis. The name of the file is the name of the axis, so it must be a valid identifier, such as Carriage or GantryX.
Each axis is automatically available to every Structured Text program as a global variable of type AXIS_REF, with the same name as the axis. You do not need to declare it. The axis is passed to the motion function blocks through their Axis input:
Power(Axis := Carriage, Enable := TRUE);The motion function blocks are only available when the project contains at least one axis definition file. An axis name must be unique, and must not be the same as the name of a POU or data type.
Axis Settings
Opening an axis definition file in the script editor displays a graphical user interface, where you can edit the settings of the axis. Hover over a setting to see its description.
Positions in a motion program are in PLC units, which you choose with the scaling factor. Velocities are in PLC units per second, accelerations in PLC units per second squared, and jerk in PLC units per second cubed.
Scaling
- Scaling factor: The number of PLC units per unit of the motor’s position. A linear motor reports its position in meters and an angular motor in radians, unless the binding has a converter, in which case the position is in the units that the converter produces. For example, use a scaling factor of 1000 to program in millimeters with a linear motor. Use a negative value to invert the direction. The presets menu provides the factors for meters, centimeters, millimeters, radians, degrees and turns, assuming that the motor’s position is in meters or radians.
- Position offset: The PLC position when the motor is at position zero.
- Modulo period: The period of a rotary axis, such as 360 for a turntable programmed in degrees. Use zero for a linear axis.
The PLC position is calculated as scaling factor × motor position + position offset. A motor’s position is zero where the entity was placed in the model, unless the initial position property of the motor is set to a non-zero value.
Limits
Software Limits
- Positive software limit: When enabled, the highest position the axis may move to.
- Negative software limit: When enabled, the lowest position the axis may move to.
The software limits are checked in two ways. A position command, such as MC_MoveAbsolute, whose target lies beyond an enabled software limit is rejected with the PositionOutsideLimits error, and the axis does not move. A velocity command, such as MC_MoveVelocity, has no target, so the axis moves until it reaches the limit. The axis then stops with an axis fault, which must be cleared with MC_Reset.
Homing searches, such as MC_Home and MC_StepLimitSwitch, ignore the software limits, because the position of the axis is not known until the search completes.
Precision at the Limits
Positions are floating-point numbers, so they are rarely exact, and the software limits are compared exactly. A position that should be at a limit can therefore lie a tiny amount beyond it, and a move to that position is rejected with the PositionOutsideLimits error. This commonly happens in two ways:
- Scaled positions: The motor reports its position in its own units, which the scaling factor converts to PLC units. For example, a motor at 45° reports its position in radians, which converts to 45.0000012°. A relative move of 45 from that position would end at 90.0000012°, beyond a positive limit of 90°.
- Calculated targets: A target that is calculated, such as
(Fraction + 0.2) * 300.0withFractionequal to 0.1, can be 90.00000000000001 rather than 90.
To avoid these errors, set the software limits slightly beyond the furthest positions that the program commands, or keep calculated targets within the limits with the LIMIT function.
Target := LIMIT(-90.0, Target, 90.0); // Keeps the target within the software limits.Velocity, Acceleration and Jerk
- Maximum velocity: The highest velocity of the axis, or zero for no limit. The default value is zero.
- Maximum acceleration: The highest acceleration of the axis, or zero for no limit. The default value is zero.
- Maximum deceleration: The highest deceleration of the axis, or zero for no limit. The default value is zero.
- Maximum jerk: The highest jerk of the axis, or zero for no limit. When it is zero, a move whose
Jerkinput is also zero uses a trapezoidal profile.
The maxima are checked when a function block starts a command. A command whose Velocity, Acceleration, Deceleration or Jerk input is above the maximum of the axis is rejected: the function block reports an error, such as InvalidVelocity, and the axis continues what it was doing. The SoftPLC never reduces an input to fit within a maximum.
The Acceleration, Deceleration and Jerk function block inputs are zero unless they are assigned. A zero value for these means that the command uses the maximum of the axis for that quantity. For example, a move without an Acceleration input accelerates at the maximum acceleration of the axis, as configured in the axis definition file. If that maximum is also zero, meaning that there is no limit, the move accelerates instantly. This is the case with the default settings, and motors cannot follow an instant acceleration without applying infinite force/torque, so you should set the maximum acceleration and deceleration to values that suit the machine. A position move with a Velocity of zero is rejected with the InvalidVelocity error.
Force and Torque
- Motor force/torque limit: The physical force or torque limit of the motor, or zero for no limit. It is sent to the motor through the
TorqueLimitdrive signal, when that signal is bound, and is used byMC_StepBlockto detect a mechanical stop.
When the limit is zero, the motor is not limited and MC_TorqueControl accepts any Torque input. The MC_StepBlock function block then needs its own TorqueLimit input, or it is rejected with the TorqueLimitUnavailable error.
Monitoring
- Maximum position lag: When enabled, stops the axis with an error when the following error exceeds this value, in PLC units. The following error is the difference between the position setpoint and the actual position of the motor.
Homing
Homing finds the position of an axis relative to the machine. A drive with an incremental encoder measures only how far the motor has moved, so the position of the axis is unknown when the machine starts. A drive with an absolute encoder knows its position at startup, so it does not need a search. The MC_HomeAbsolute function block can be used to mark such an axis as homed without moving it, provided that Encoder setting is set to Absolute for the axis.
A homing procedure moves the axis to a known reference, such as a home switch, a limit switch or a mechanical stop, and assigns a known position there. The SoftPLC does not require an axis to be homed before it moves, and always checks the software limits. However, until an axis with an incremental encoder is homed, its positions are measured from wherever it was at startup, so a move target or software limit may not correspond to the intended position on the machine. A program should therefore home its axes before relying on absolute positions. In a simulation the motor position is always known, but homing lets the same program run unchanged on a real machine.
These settings configure homing, including the search performed by MC_Home.
| Setting | Default | Description |
|---|---|---|
| Encoder | Incremental | The encoder of the real machine’s drive, Absolute or Incremental. MC_HomeAbsolute is rejected with the SignalNotConfigured error for an incremental encoder. |
| Direction | Negative | The direction in which the axis moves to search for the home switch. |
| Switch mode | Rising edge | The switch condition that locates the reference, such as the rising edge of the home switch. |
| Velocity | 0 | The search velocity, which must be greater than zero. |
| Time limit (ms) | 0 | The longest time that the search may take, in milliseconds, or zero for no limit. |
| Distance limit | 0 | The longest distance that the axis may travel during the search, in PLC units, or zero for no limit. |
| Force/torque limit | 0 | The force or torque limit during the search, or zero to use the motor force/torque limit. |
| Force/torque tolerance | 0 | How close the measured force or torque must come to the limit for MC_StepBlock to detect a mechanical stop. |
The velocity must be set before MC_Home can be used, since MC_Home is otherwise rejected with the InvalidVelocity error. If the reference is not found within the time limit or the distance limit, MC_Home reports the HomingTimeLimit or HomingDistanceLimit error, and the axis decelerates to a stop. The distance includes any movement off the home switch or back from a limit switch. The direction and switch mode are described in Search Direction and Switch Mode.
Search Direction and Switch Mode
A home switch is usually a sensor within the travel of the axis, which detects a flag, such as a metal tab, attached to the moving part. Unlike a limit switch, the axis can move past the home switch, which is on while the flag is in front of it. The switch turns on as soon as the flag reaches the sensor. Since the flag has a length, the position of the axis at which this happens depends on the direction from which the axis approaches, and the two positions differ by the length of the flag. Approaching the switch from the same side every time makes the homed position repeatable. The direction setting determines how the axis approaches the switch:
- Positive and Negative: The axis searches in that direction, starting from its current position. If the home switch is already on when homing starts, the result depends on the switch mode:
- On: The axis is homed immediately, at its current position.
- Off and Falling edge: The axis is homed when the switch turns off, as the flag leaves the sensor.
- Rising edge: The switch cannot turn on until the axis has left the flag, so the axis continues until it reaches a limit switch, and then returns to approach the home switch from outside, as described below. Without limit switches, the search fails when its time or distance limit is exceeded, or continues indefinitely if both are zero.
- Edge switch positive and Edge switch negative: The axis first moves in the opposite direction until the switch turns off, and then starts the search from outside the switch. This is the same as the Switch positive and Switch negative directions below.
- Switch positive and Switch negative: The axis searches in the positive or negative direction. If the home switch is already on when homing starts, the axis first moves in the opposite direction until the switch turns off, and then starts the search. The search therefore always reaches the switch from outside it.
When the LimitPositive and LimitNegative axis tags are bound, the search also uses the limit switches. If the axis reaches a limit switch before finding the reference, the home switch must lie behind it, so the axis reverses and moves back through the home switch, until the switch turns on and then off again. The axis is then beyond the flag, so it searches again in the original direction. A positive search therefore always reaches the home switch from the negative side of the flag, and a negative search from the positive side, whether the axis starts before or beyond the flag. If the axis reaches a limit switch a second time, homing fails with the ReferenceNotFound error.
Binding Axes to Motors
Each axis provides a set of tags, which can be imported by the SoftPLC server. The tags are named <axis>.<signal>, such as Carriage.SetPosition. You connect an axis to a motor by binding these tags to the IO signals of the motor through the IO Browser, in the same way as any other tag.
To use PLCopen Motion Control with a motor, it is required that you set the controller of the motor to None in the inspector. This ensures that the motor then follows each position setpoint from the SoftPLC directly, since the SoftPLC plans the motion profile itself. Only the SetPosition tag must be bound for the motor to move, but the Enable and ActualPosition tags should normally be bound as well:
| Tag | Area | Motor Signal | Description |
|---|---|---|---|
SetPosition | Output | Target Position | The position setpoint (required). |
Enable | Output | State | Switches the motor on while the axis is powered by MC_Power. If it is not bound, the motor stays in the state set in the inspector. |
ActualPosition | Input | Current Position | The measured position of the motor. If it is not bound, the axis is ideal, as described below, so it cannot detect a motor that is blocked or lags behind its setpoint. |
The other tags, listed below, are optional. Each provides a feature that some function blocks require:
| Tag | Area | Typical Signal | Used By |
|---|---|---|---|
ActualVelocity | Input | Motor Current Velocity | The actual velocity. Without it, the velocity is calculated from the change in position. |
ActualTorque | Input | Motor Current Force | MC_ReadActualTorque and MC_StepBlock. |
TorqueLimit | Output | Motor Force Limit | MC_TorqueControl and homing steps with a torque limit. |
HomeSwitch | Input | Sensor State | MC_Home, MC_StepAbsoluteSwitch and MC_StepReferenceFlyingSwitch. |
LimitPositive | Input | Sensor State | MC_StepLimitSwitch, and stops the axis when it moves into the positive limit switch. |
LimitNegative | Input | Sensor State | MC_StepLimitSwitch, and stops the axis when it moves into the negative limit switch. |
TouchProbe | Input | Sensor State | MC_TouchProbe. |
TouchProbePosition | Input | The motor position latched at the touch probe edge, for drives that provide it. |
The drive signals use the units of the signals they are bound to, which are meters or radians for a motor unless the binding has a converter. The axis converts them to PLC units with its scaling factor and offset. Forces and torques are not scaled, so they are in newtons or newton-meters for a motor. If a program expects a different unit, such as a percentage of the rated torque, add a converter to the force/torque bindings.
A function block that needs a signal that is not bound reports the SignalNotConfigured error, rather than searching for a switch that does not exist. If ActualPosition is not bound, the axis is ideal, meaning that its actual position always equals its setpoint. This allows you to develop and test a motion program before connecting it to the model.
Writing a Motion Program
A motion program usually powers the axis with MC_Power, homes the axis, and then issues motion commands with function blocks such as MC_MoveAbsolute. Each function block instance is called once per scan. The following program homes the Carriage axis using MC_Home, and then moves it back and forth between two positions. The search uses the homing settings of the axis, whose velocity must be set, and the HomeSwitch tag must be bound to the sensor that detects the home position. If an error occurs, the program turns on the AxisError output, which could be bound to a warning lamp, and waits for the Restart input. It then resets the axis and homes it again:
PROGRAM Main
VAR
Power : MC_Power;
Home : MC_Home;
Move : MC_MoveAbsolute;
Reset : MC_Reset;
Restart AT %IX0.0 : BOOL; // Used to restart the program after an error.
AxisError AT %QX0.0 : BOOL; // On while the program waits for a restart after an error.
Step : INT;
Target : LREAL := 500.0;
END_VAR
Power(Axis := Carriage, Enable := TRUE);
CASE Step OF
0: // Search for the home switch, starting once MC_Power reports that the axis is powered.
Home(Axis := Carriage, Execute := Power.Status, Position := 0.0);
IF Home.Done THEN
Step := 10;
ELSIF Home.Error THEN
Step := 90;
END_IF;
10: // Move to the target.
Move(Axis := Carriage, Execute := TRUE, Position := Target, Velocity := 250.0, Acceleration := 1000.0, Deceleration := 1000.0);
IF Move.Done THEN
Move(Axis := Carriage, Execute := FALSE);
Target := 500.0 - Target; // Alternate between 0 and 500.
ELSIF Move.Error OR Move.CommandAborted THEN
Move(Axis := Carriage, Execute := FALSE);
Step := 90;
END_IF;
90: // Wait for a restart after an error, then reset the axis and home it again.
Home(Axis := Carriage, Execute := FALSE);
Reset(Axis := Carriage, Execute := Restart);
IF Reset.Done THEN
Reset(Axis := Carriage, Execute := FALSE);
Step := 0;
END_IF;
END_CASE;
AxisError := Step = 90;
END_PROGRAMEach command is started by a rising edge of Execute. To issue the same command again, the program calls the block with Execute := FALSE once, so that the next call with Execute := TRUE produces a new rising edge.
Axis States
The current state is reported by MC_ReadStatus.
| State | Description |
|---|---|
| Disabled | The axis is not powered. This is the initial state. |
| Standstill | The axis is powered and not moving. |
| Homing | A homing command is active. |
| DiscreteMotion | A move to a position is active, such as MC_MoveAbsolute, MC_MoveRelative, MC_MoveAdditive or MC_Halt. MC_MoveContinuousAbsolute and MC_MoveContinuousRelative are in this state until the axis passes their position. MC_MoveSuperimposed also enters this state when the axis is at standstill. |
| ContinuousMotion | A continuous move is active, such as MC_MoveVelocity or MC_TorqueControl, or MC_MoveContinuousAbsolute or MC_MoveContinuousRelative after the axis has passed their position. A slave also enters this state after MC_GearOut, and keeps moving at its current velocity. |
| SynchronizedMotion | The axis is a slave of a gearing command, or an axes group moves it. |
| Stopping | MC_Stop is active. Other motion commands are rejected until MC_Stop is done and its Execute is FALSE. |
| ErrorStop | The axis has a fault, and decelerates to a stop. MC_Reset clears the fault. |
The MC_Power function block moves the axis from Disabled to Standstill. Motion commands are accepted in Standstill, DiscreteMotion, ContinuousMotion and SynchronizedMotion. Homing commands are accepted in Standstill and Homing. A command that is not allowed in the current state reports the StateNotAllowed error.
Command Behavior
Most motion function blocks start a command on a rising edge of their Execute input. The inputs are read at the rising edge, so changing them while the command is running has no effect, unless ContinuousUpdate is TRUE. The outputs report the progress of the command:
| Output | Description |
|---|---|
Busy | TRUE while the command has not finished. |
Active | TRUE while the command controls the axis. |
Done | TRUE when the command has completed. |
CommandAborted | TRUE when another command aborted the command. |
Error | TRUE when the block has reported an error. |
ErrorID | The error identifier while Error is TRUE. |
The Done, CommandAborted and Error outputs remain TRUE while Execute is TRUE. If Execute is already FALSE when the command finishes, they are TRUE for one call. A command that is started while another command controls the axis aborts the previous command, unless its buffer mode says otherwise.
Function blocks that read values, such as MC_ReadActualPosition, have an Enable input instead of Execute. They update their outputs in every call while Enable is TRUE, and set Valid when the outputs hold valid values.
Command Completion
The Done output becomes TRUE when the setpoint of the axis reaches the target, rather than the actual position of the motor. The motor may therefore still be settling when Done becomes TRUE. Some PLCs, such as TwinCAT with target position monitoring enabled, instead wait until the actual position has settled within a window of the target. A program that must wait for the motor can compare the output of MC_ReadActualPosition with the target.
Buffer Modes
The BufferMode input of a motion command determines how the command takes over from the command that is currently active:
| Buffer Mode | Description |
|---|---|
mcAborting | Starts immediately, aborting the active command. This is the default. |
mcBuffered | Starts when the active command is done. |
mcBlendingLow | Starts when the active command reaches its target, at the lower of the two commanded velocities. |
mcBlendingPrevious | Starts when the active command reaches its target, at the velocity of the active command. |
mcBlendingNext | Starts when the active command reaches its target, at the velocity of the new command. |
mcBlendingHigh | Starts when the active command reaches its target, at the higher of the two commanded velocities. |
Blending allows a sequence of moves to run without stopping between them. Blending only applies when the next move continues in the same direction. A buffered command waits for Done of a position move, for InVelocity of MC_MoveVelocity, for InEndVelocity of MC_MoveContinuousAbsolute and MC_MoveContinuousRelative, and for Status of MC_Power.
An axis fault, such as a following error or a software limit, stops the whole sequence. The active command reports the AxisFault error, and every buffered command reports the StateNotAllowed error. If the active command instead ends with a function block error, the next buffered command still starts. For example, a homing step that does not find its reference reports the ReferenceNotFound error, and a buffered MC_FinishHoming then runs anyway. Buffering therefore cannot prevent the next command from running after a function block error. Moves rarely end with such errors, since the errors that occur during a move are usually axis faults, so a sequence of moves can be buffered safely. Function block errors mostly occur during homing. If a homing sequence must stop when a step fails, start the next step from the Done output of the previous step instead of buffering it.
Motion Profiles
Moves follow a trapezoidal velocity profile, which accelerates at Acceleration, cruises at up to Velocity and decelerates at Deceleration. When Jerk is greater than zero, the profile is an S-curve that also limits the rate of change of acceleration, which gives smoother motion. An input of zero uses the corresponding maximum of the axis. Other PLCs may treat zero differently, so assign a non-zero value to each of these inputs if the program will be transferred to a real PLC. A value above the maximum of the axis is rejected with an error.
When a command takes over from another command, for example by aborting a move that is still running, the new profile starts from the current position and velocity of the axis. The axis therefore changes smoothly to the new motion, rather than stopping abruptly. With a jerk limit, the profile also starts from the current acceleration, so the acceleration changes smoothly as well. The MC_SetOverride function block scales the velocity, acceleration and jerk of all motion on an axis, which is useful for a speed override on an operator panel.
Limits and Errors
There are two kinds of error:
- Function block errors: The block rejects a command, for example because an input is invalid or the axis is in the wrong state. The block sets
ErrorandErrorID, but the axis state does not change. - Axis faults: The axis enters ErrorStop and decelerates to a stop at its maximum deceleration. The active command reports the
AxisFaulterror. UseMC_ReadAxisErrorto read the fault, andMC_Resetto clear it.
The following conditions cause an axis fault:
- Following error: The following error exceeds the maximum position lag, when monitoring is enabled. This usually indicates that the motor is blocked, or that its force limit is too low to follow the profile. Another common cause is a move without an acceleration or deceleration limit. If the
AccelerationorDecelerationinput is zero and the axis has no maximum, the velocity changes instantly, which a motor cannot follow. - Software limit: A velocity command reaches an enabled software limit. Position commands with a target beyond an enabled software limit are rejected instead.
- Hardware limit: The axis moves towards an active limit switch. After
MC_Reset, the axis can move away from the switch.
Homing
Homing establishes the position of an axis relative to the machine. A motor’s position is relative to where it was placed in the model, so a program should home each axis before relying on its absolute position. There are three approaches:
- MC_Home: Runs the homing procedure configured in the axis file. The axis searches for its home switch, assigns the
Positioninput at the switch, and finishes in Standstill. - Homing steps: The program builds its own homing procedure from a sequence of steps, as described in Homing Steps.
- Passive homing: The axis is referenced on the fly when it passes a switch, while other commands move it, as described in Passive Homing.
When a search detects its reference, such as the edge of the home switch, the position is assigned at that moment, and the axis then decelerates to a stop at its maximum deceleration. The axis therefore stops a short distance beyond the reference, and does not move back. For example, an axis homed by MC_Home with Position := 0.0 reports its stopping distance from the reference once Done is TRUE, rather than zero. To return to the reference, move the axis to the homed position with MC_MoveAbsolute after homing. Note that MC_FinishHoming, which completes a sequence of homing steps, moves the axis by a distance relative to where it stopped. It is therefore used to move a fixed distance, for example away from the switch, rather than back to the reference.
The switches are read once per scan, so an edge is detected in the first scan after it occurs. The assigned position can therefore differ from the true position of the edge by up to the distance that the axis travels in one timestep, which is the homing velocity multiplied by the timestep. For example, homing at 50 mm/s with a timestep of 10 ms can be off by up to 0.5 mm. A lower homing velocity or a shorter timestep makes homing more accurate. Real drives often latch the position in hardware when the switch changes, which makes them slightly more accurate at the same velocity.
The MC_HomeDirect function block assigns a position without moving, which is the simplest way to home an axis in a simulation. Please see the motion function blocks page for details of each homing block.
Homing Steps
Homing steps allow the program to define its own homing procedure, when the search performed by MC_Home is not enough. For example, a machine may have no home switch, or the axis may need to move to a limit switch before searching for the home switch. Each step searches for one reference, using the direction, velocity and switch mode given by its inputs rather than the axis settings:
MC_StepAbsoluteSwitch: Searches for the home switch.MC_StepLimitSwitch: Searches for a limit switch, which is useful for machines without a home switch.MC_StepBlock: Drives against a mechanical stop, which is detected from the measured force or torque.
The axis remains in the Homing state between steps, until MC_HomeDirect, MC_HomeAbsolute or MC_FinishHoming completes the procedure and returns the axis to Standstill. Only a step whose SetPosition input is assigned changes the position of the axis.
The following program first moves the Carriage axis to its negative limit switch, so that the home switch is always approached from the same side. It then searches for the home switch in the positive direction, assigns position zero at its rising edge, and completes homing by moving 10 units away from the switch:
PROGRAM Main
VAR
Power : MC_Power;
ToLimit : MC_StepLimitSwitch;
ToSwitch : MC_StepAbsoluteSwitch;
Finish : MC_FinishHoming;
Step : INT;
Homed AT %QX0.1 : BOOL; // On once the axis is homed.
END_VAR
Power(Axis := Carriage, Enable := TRUE);
CASE Step OF
0: // Move to the negative limit switch, starting once MC_Power reports that the axis is powered.
ToLimit(Axis := Carriage, Execute := Power.Status, Direction := mcNegativeDirection, LimitSwitchMode := mcRisingEdge, Velocity := 50.0);
IF ToLimit.Done THEN
Step := 10;
ELSIF ToLimit.Error THEN
Step := 90;
END_IF;
10: // Search for the home switch, and assign position zero at its rising edge.
ToSwitch(Axis := Carriage, Execute := TRUE, Direction := mcPositiveDirection, SwitchMode := mcRisingEdge, Velocity := 20.0, SetPosition := 0.0);
IF ToSwitch.Done THEN
Step := 20;
ELSIF ToSwitch.Error THEN
Step := 90;
END_IF;
20: // Complete homing, and move away from the switch.
Finish(Axis := Carriage, Execute := TRUE, Distance := 10.0, Velocity := 20.0);
IF Finish.Done THEN
Step := 30;
ELSIF Finish.Error THEN
Step := 90;
END_IF;
30: // The axis is homed.
;
90: // Homing failed.
;
END_CASE;
Homed := Step = 30;
END_PROGRAMEach step is started from the Done output of the previous step, rather than buffered, so that the procedure stops if a step fails.
Passive Homing
Passive homing references the axis on the fly, while it is moved by other commands, without a separate homing procedure. This is useful for axes that run continuously, where stopping to home would stop the machine, and for axes driven by belts or wheels that may slip, whose position drifts over time. The MC_StepReferenceFlyingSwitch function block watches a switch, and assigns its SetPosition input when the switch condition is met. It starts no motion and does not change the state of the axis.
Unlike MC_SetPosition, passive homing does not change the absolute targets of the motion. A move that is running when the reference is found continues to its target in the corrected coordinate, so the axis still stops at the commanded position. If the correction is large, the target may then lie behind the axis, which makes the move reverse. MC_AbortPassiveHoming ends passive homing that has not found its reference.
The following program moves the belt-driven Carriage axis back and forth between 0 and 500. A sensor at position 250, bound to the HomeSwitch tag, detects a flag on the carriage. The program references the axis each time the carriage passes the sensor, which corrects any slip of the belt. The mcEdgeSwitchPositive switch mode uses the same end of the flag in both directions:
PROGRAM Main
VAR
Power : MC_Power;
Move : MC_MoveAbsolute;
Reference : MC_StepReferenceFlyingSwitch;
Target : LREAL := 500.0;
END_VAR
Power(Axis := Carriage, Enable := TRUE);
// Execute is FALSE for one call after each reference, which starts the block again.
Reference(Axis := Carriage, Execute := Power.Status AND NOT Reference.Done, SwitchMode := mcEdgeSwitchPositive, SetPosition := 250.0);
// Move between 0 and 500, starting a new move once the previous one is done.
Move(Axis := Carriage, Execute := Power.Status, Position := Target, Velocity := 250.0);
IF Move.Done THEN
Move(Axis := Carriage, Execute := FALSE);
Target := 500.0 - Target;
END_IF;
END_PROGRAMModulo Axes
An axis with a modulo period is a rotary axis, such as a turntable, a rotary knife or an endless conveyor. Its positions are reported within the range from 0 to the period, while the axis can rotate continuously in either direction. The target of MC_MoveAbsolute and MC_MoveContinuousAbsolute must lie within one period, and their Direction input chooses the route:
- mcPositiveDirection: Moves in the positive direction.
- mcNegativeDirection: Moves in the negative direction.
- mcShortestWay: Takes the shorter route.
- mcCurrentDirection: Continues in the current direction of motion, or moves in the positive direction from rest.
The MC_MoveRelative, MC_MoveAdditive and MC_MoveContinuousRelative function blocks can move by more than one period. The positive and negative position software limits are ignored on a modulo axis, since its position wraps around at the end of each period, so there is no highest or lowest position.
Limitations
The following parts of PLCopen Motion Control are not currently supported:
- Camming and phasing:
MC_CamTableSelect,MC_CamIn,MC_CamOut,MC_PhasingAbsoluteandMC_PhasingRelative. - Other multi-axis motion:
MC_CombineAxes. - Profile blocks:
MC_PositionProfile,MC_VelocityProfileandMC_AccelerationProfile. - Homing:
MC_StepReferencePulse,MC_StepDistanceCodedandMC_StepReferenceFlyingRefPulse. - Drive digital IO:
MC_ReadDigitalInput,MC_ReadDigitalOutputandMC_WriteDigitalOutput. Bind the signals to tags instead. - Fluid power: The extensions for hydraulic and pneumatic axes.