Coordinated Motion

The motion control function blocks move each axis on its own. Many machines need several axes to move together, so that a tool follows a path. For example, a gantry may need to apply glue along the edge of a part, a SCARA robot may need to move a part along a straight line, or a robot may need to pick products from a moving conveyor. Coordinated motion moves a group of axes along a path, such as a line or an arc, with all of the axes starting and arriving together.

The SoftPLC supports the PLCopen Motion Control function blocks for coordinated motion. This page assumes that you are familiar with axes, as described on the motion control page. Please see the motion function blocks page for a reference of each function block.

Contents

Axes Groups

An axes group is a set of up to 16 axes that move together, such as the X, Y and Z axes of a gantry, or the joints of a robot. Each axis is still defined by its own axis definition file and bound to its own motor, as described in Axes. An axis can belong to at most one group.

To create a group, click the add button in the file explorer of the script editor, select SoftPLC in the template window and then select Axes Group. The name of the file is the name of the group, so it must be a valid identifier, such as Gantry or Scara. Opening the file displays a graphical user interface with two settings:

  • Axes: The axes of the group. Click Add axis to add an axis, and drag the rows to change their order. The order matters, since the first axis is axis 1 of the group, the second is axis 2, and so on. The kinematic model relies on this order, for example to know which axis moves the tool along X.
  • Kinematic model: The kinematic model that describes the machine, which is chosen from the kinematics files of the project. A group without a kinematic model rejects motion commands with the KinematicsNotSet error.

Each group is automatically available to every Structured Text program as a global variable of type AXES_GROUP_REF, with the same name as the group. The group is passed to the coordinated motion function blocks through their AxesGroup input, in the same way that an axis is passed through the Axis input:

Move(AxesGroup := Gantry, Execute := TRUE, Position := Target, Velocity := 200.0, CoordSystem := MCS);

The coordinated motion function blocks are only available when the project contains at least one axes group file. A group name must be unique, and must not be the same as the name of an axis, a POU or a data type.

Coordinate Systems

A position of a group can be given in three coordinate systems, which the CoordSystem input of a function block selects. For example, a robot can be moved by giving the angle of each joint, or by giving the position that its tool should move to:

  • ACS (axis coordinate system): The positions of the axes themselves. Entry 1 is the position of axis 1 of the group, entry 2 is the position of axis 2, and so on.
  • MCS (machine coordinate system): The position and orientation of the tool center point (TCP), which is the point of the tool that follows the path, such as the tip of a glue nozzle or the centre of a gripper. The kinematic model of the group calculates it from the positions of the axes. The origin and directions depend on the model, such as the axis of the base of a SCARA robot.
  • PCS (product coordinate system): A coordinate system attached to a product, such as a pallet or a part on a conveyor. It is the machine coordinate system moved and turned to the product, as described in Product Coordinate Systems. Until it is set, it is the same as the machine coordinate system.

Positions, distances and velocities of a group are values of type MC_POSITION, which is an ARRAY[1..16] OF LREAL. The meaning of each entry depends on the coordinate system:

Entry ACS MCS and PCS
1 Axis 1 X
2 Axis 2 Y
3 Axis 3 Z
4 Axis 4 RX, the rotation about X in degrees
5 Axis 5 RY, the rotation about Y in degrees
6 Axis 6 RZ, the rotation about Z in degrees
7 to 16 Axes 7 to 16 The additional axes, in order

When calling a function block, a position, distance or auxiliary point input also accepts any one-dimensional REAL or LREAL array, such as an ARRAY[0..5] OF REAL. The entries are taken in order from the lowest index of the array, so its first element is entry 1. Entries beyond the end of the array are zero, and entries beyond the sixteenth are not used. Likewise, the Position, Velocity and Acceleration outputs of the read function blocks can be connected to any one-dimensional REAL or LREAL variable, which receives as many entries as it holds. Accessing these pins as members of the instance outside of a call, as in Move.Position := Target;, requires an MC_POSITION.

The orientation of the tool is given by three angles. The tool is first turned by RX about X, then by RY about Y, and then by RZ about Z, where each rotation is about the fixed axes of the coordinate system. A model that only controls the position of the tool, such as a gantry, ignores the orientation entries of a target.

Machine and World Coordinates

The machine coordinate system belongs to the machine, not to the world coordinate system of ProtoTwin. The SoftPLC only knows the positions of the axes, so the X, Y and Z of the machine are the directions in which its axes move the tool, as defined by the kinematic model. The built-in models, like those of other PLCs, use Z as the vertical direction. For example, the Z axis of a gantry and the Z column of a SCARA robot move the tool up and down. ProtoTwin instead uses Y as the vertical direction of its world coordinates.

The two coordinate systems are therefore usually different, even when the machine is placed at the world origin:

  • Directions: A height is a Y coordinate in world coordinates, but a Z coordinate in MCS. Rotations differ in the same way, so a rotation about the vertical direction is a rotation about Y in world coordinates, but a rotation about Z (RZ) in MCS.
  • Origin: The origin of MCS is defined by the kinematic model and the positions of the axes, such as the axis of the base of a robot, rather than by the world origin.
  • Units: World positions are in meters, while positions in MCS are in the PLC units of the axes, such as millimeters.

A world position, such as the position of a pallet or a conveyor, must therefore be converted to machine coordinates before it is used in a program. There are two ways to find the machine coordinates of a position:

  • Calculate them: Subtract the world position of the origin of MCS from the world position, swap the axes, and convert from meters to PLC units, as shown below.
  • Teach them: Move the tool to the position, for example by jogging the axes, and read its position with MC_GroupReadActualPosition in MCS. This is how positions are usually found on a real machine.

For example, consider a machine whose X axis points along the world x-axis, whose Z axis points up, and whose PLC units are millimeters. If (x, y, z) is a world position, and (x0, y0, z0) is the world position of the origin of MCS, then the machine coordinates (X, Y, Z) of the position are:

$$\begin{aligned} X &= 1000\,(x - x_0) \\ Y &= -1000\,(z - z_0) \\ Z &= 1000\,(y - y_0) \end{aligned}$$
Machine and World Coordinates

The world z changes sign because both coordinate systems are right-handed. A machine that is turned in the world also needs that rotation to be undone.

It is rarely necessary to convert every position. For example, to place parts in the slots of a pallet, only the position of one corner of the pallet needs to be converted. A product coordinate system can then be placed at that corner, and the positions of the slots can be given relative to the corner, such as 100 millimeters along the edge of the pallet, without any conversion.

Kinematic Models

A kinematic model describes how the positions of the axes relate to the position of the tool center point, and therefore converts between the ACS and MCS coordinate systems. On a gantry, each axis moves the tool along one direction, so the X axis simply moves the tool along X. On a SCARA robot, the tool is carried by two rotating arms. Moving the tool along a straight line then requires both arms to turn by changing amounts, which the kinematic model calculates for every point of the path.

To create a kinematic model, click the add button in the file explorer of the script editor, select SoftPLC in the template window and then select Kinematics. The name of the file is the name of the model. Opening the file displays a graphical user interface, where you can choose the Type of the model and set its parameters.

The kinematic model is then selected in the axes group file. Several groups can use the same kinematic model, for example two identical robots. Each kinematics file is also available to programs as a global variable of type MC_KIN_REF, with the same name as the model, which MC_SetKinTransform can select while the program runs.

Units

Lengths, such as the length of an arm, are in the PLC units of the linear axes, which you choose with the scaling factor in the axis settings of each axis. Use the same units for every linear axis of a group, such as millimeters. The rotary axes of a model, such as the joints of a robot, must be in degrees, so use the Degrees scaling preset for them. The position of the tool is then in the same units as the lengths, and its orientation is in degrees.

Joints and Additional Axes

The axes that a model drives are its joints, which are the first axes of the group. A model with three joints, such as a gantry with X, Y and Z axes, uses axes 1 to 3 of the group. Up to ten further axes can follow the joints as additional axes, such as a rotary table or a glue pump that should move along with the path. Apart from the Cartesian and empty models, a group must have at least as many axes as its model has joints, and at most ten more, otherwise an error is reported.

For example, a gantry may place parts on a rotary table, which should turn while the tool moves. The group has four axes, and its kinematic model is Gantry XYZ, which has three joints. The fourth axis is therefore an additional (external) axis:

Axis of the Group Axis Role Entry in ACS Entry in MCS and PCS
1 GantryX Joint, which moves the tool along X 1 1 (X)
2 GantryY Joint, which moves the tool along Y 2 2 (Y)
3 GantryZ Joint, which moves the tool along Z 3 3 (Z)
4 Table First additional axis 4 7

In MCS and PCS, entries 4 to 6 always hold the orientation of the tool, so the additional axes use entries 7 to 16, whatever the number of joints. A linear move in MCS to [200.0, 100.0, 50.0, 0.0, 0.0, 0.0, 90.0] therefore moves the tool to X = 200, Y = 100 and Z = 50, and turns the table to 90. The additional axes change evenly along the path, so the table arrives at the same time as the tool.

Configurations

A robot with rotary joints can often reach the same position of the tool in more than one way. For example, a SCARA robot can reach most positions with its elbow to the left or to the right of the line from its base to the tool. These are called configurations. A model with several configurations has a parameter, such as Elbow, which chooses the configuration that the robot uses. A straight line or arc cannot change the configuration, so the robot must already be in the chosen configuration before a linear or circular move. Otherwise, the move is rejected with the ConfigurationMismatch error. A direct move moves each joint to a given angle, so it can be used to place the robot in its configuration, for example after startup.

The following program controls a three-axis SCARA robot, whose axes are named Shoulder, Elbow and Lift, with arm lengths of 300 and 200 and the elbow to the right. It first moves the joints to a known pose with a direct move, where the elbow is bent by 90 degrees to the right. It then moves the tool back and forth between two positions along straight lines:

PROGRAM Main
VAR
    PowerShoulder : MC_Power;
    PowerElbow : MC_Power;
    PowerLift : MC_Power;
    Enable : MC_GroupEnable;
    Ready : MC_MoveDirectAbsolute;
    Move : MC_MoveLinearAbsolute;
    Joints : MC_POSITION := [0.0, 90.0, 0.0]; // The joint angles of the starting pose, in ACS.
    Pick : MC_POSITION := [350.0, 100.0, 0.0]; // The positions of the tool, in MCS.
    Place : MC_POSITION := [100.0, 350.0, 0.0];
    Target : MC_POSITION;
    Step : INT;
END_VAR

PowerShoulder(Axis := Shoulder, Enable := TRUE);
PowerElbow(Axis := Elbow, Enable := TRUE);
PowerLift(Axis := Lift, Enable := TRUE);
Enable(AxesGroup := Scara, Execute := PowerShoulder.Status AND PowerElbow.Status AND PowerLift.Status);

CASE Step OF
    0: // Moves the joints to the starting pose, which places the elbow on the right.
        Ready(AxesGroup := Scara, Execute := Enable.Done, Position := Joints, CoordSystem := ACS);
        IF Ready.Done THEN
            Target := Pick;
            Step := 10;
        END_IF;

    10: // Moves the tool along a straight line to the target, and then swaps the target.
        Move(AxesGroup := Scara, Execute := TRUE, Position := Target, Velocity := 250.0, Acceleration := 2000.0, Deceleration := 2000.0, CoordSystem := MCS);
        IF Move.Done THEN
            Move(AxesGroup := Scara, Execute := FALSE);
            IF Target[1] = Pick[1] THEN
                Target := Place;
            ELSE
                Target := Pick;
            END_IF;
        END_IF;
END_CASE;
END_PROGRAM

Built-In Models

Each model has a name in parenthesis, such as Kin_Gantry3. A function block of the same name is available to programs, as described in Custom Kinematics. The parameters are listed with their names in the function block. Lengths, and the offsets of linear joints such as Offset Z, are in the PLC units of the linear axes. The offsets of rotary joints are in degrees.

Empty (Kin_Empty)

A group of independent axes without any machine geometry. The tool has no position, so the group can only be moved with direct moves in axis coordinates, where entry n of the position is the target of axis n. This is useful to move several unrelated axes to their targets, so that they start and arrive together. It has no parameters.

Empty Kinematics

Cartesian

Axes 1 to 6 are the X, Y, Z, RX, RY and RZ coordinates of the tool. A group with fewer axes uses the first coordinates, so a group with three axes moves along X, Y and Z. This model is useful for machines whose axes are independent linear axes, such as a simple gantry. It has no parameters.

Cartesian Kinematics

Gantry XY (Kin_Gantry2)

A gantry whose axes move the tool along X and Y. Axis 1 moves the bridge along X, and axis 2 moves the carriage along the bridge in Y. The tool does not turn, and its Z coordinate is always zero, so use Gantry XYZ when the tool also moves up and down. It has no parameters.

Gantry XY Kinematics

Gantry XYZ (Kin_Gantry3)

A gantry whose axes move the tool along X, Y and Z. Axis 1 moves the bridge along X, axis 2 moves the carriage along the bridge in Y, and axis 3 moves the tool up and down in Z. The tool does not turn. It has no parameters.

Gantry XYZ Kinematics

Three-Axis SCARA (Kin_Scara2_Z)

A SCARA robot with two rotary arms and a linear Z axis. Axis 1 turns the first arm about the base, axis 2 turns the second arm at the elbow, and axis 3 moves the tool along Z. The origin is on the axis of the base. The tool turns with the arms, so only its position can be controlled. The RX, RY and RZ entries of a target are ignored.

Three-Axis SCARA Kinematics
Parameter Description
Arm length 1 (dArmLength1) The length of the first arm, from axis 1 to axis 2.
Arm length 2 (dArmLength2) The length of the second arm, from axis 2 to the tool.
Offset A1 (dOffsetA1) The value of axis 1 while the first arm points along X.
Offset A2 (dOffsetA2) The value of axis 2 while the second arm is in line with the first.
Offset Z (dOffsetZ) The value of axis 3 while the tool is at Z = 0.
Elbow (xElbowRight) The configuration: Right when the elbow is to the right of the line from the base to the tool, seen from the base, and Left otherwise. With the elbow to the right, the angle of axis 2 is positive.

Four-Axis SCARA (Kin_Scara3_Z)

A SCARA robot like the three-axis SCARA, with a rotary axis that turns the tool at the end of the second arm. This is the most common type of SCARA robot. Axis 3 turns the tool and axis 4 moves it along Z, so both the position of the tool and its rotation about Z (RZ) are controlled.

Four-Axis SCARA Kinematics
Parameter Description
Arm length 1 (dArmLength1) The length of the first arm, from axis 1 to axis 2.
Arm length 2 (dArmLength2) The length of the second arm, from axis 2 to axis 3.
Tool offset (dArmLength3) The distance from axis 3 to the tool center point, or zero when the tool center point is on axis 3.
Offset A1 (dOffsetA1) The value of axis 1 while the first arm points along X.
Offset A2 (dOffsetA2) The value of axis 2 while the second arm is in line with the first.
Offset A3 (dOffsetA3) The value of axis 3 while the tool offset is in line with the second arm.
Offset Z (dOffsetZ) The value of axis 4 while the tool is at Z = 0.
Elbow (xElbowRight) The configuration, as for the three-axis SCARA.

Polar (Kin_Polar)

A beam that a rotary axis C turns about the base, with a carriage that a linear axis R moves along the beam. Axis 1 is C and axis 2 is R. The R axis is the distance of the tool from the centre, so it is never negative. The tool turns with the beam, so only its position can be controlled, and its Z coordinate is always zero. It has no parameters.

Polar Kinematics

Polar with Z (Kin_Polar_Z)

A polar model like Kin_Polar, with a linear axis that moves the beam up and down. Axis 1 is Z, axis 2 is C and axis 3 is R. The tool turns with the beam, so only its position can be controlled. It has no parameters.

Polar with Z Kinematics

Six-Axis Articulated Robot (Kin_ArticulatedRobot_6DOF)

A six-axis industrial robot with a spherical wrist, where axes 4, 5 and 6 cross at the wrist centre. Both the position and the orientation of the tool are controlled. The drawing shows the robot in its reference position, with the upper arm pointing up and the forearm pointing forward along X. The origin is at the bottom of the base, on axis 1.

Six-Axis Articulated Robot Kinematics
Parameter Description
d1 The height of axis 2 above the bottom of the base.
a1 The distance of axis 2 in front of axis 1.
a2 The length of the upper arm, from axis 2 to axis 3.
d3 The sideways offset of the forearm from the upper arm, or zero when the forearm lies in the plane of the upper arm.
a3 The offset of the forearm from axis 3 along the upper arm, or zero when the axis of the forearm crosses axis 3.
d4 The length of the forearm, from axis 3 to the wrist centre.
d6 The distance from the wrist centre to the flange, along axis 6.
Offset A0 to Offset A5 (dOffsetA0 to dOffsetA5) The value of each axis in the reference position. Axis 1 uses dOffsetA0, axis 2 uses dOffsetA1, and so on.
Arm (xArmForward) The configuration of the arm: Forward when the wrist centre is in front of axis 1, and Backward when axis 1 is turned round so that the arm reaches back over the base.
Elbow (xElbowUp) The configuration of the elbow: Up or Down.
Hand (xHandDown) The configuration of the wrist: Down when the angle of axis 5 is positive, and Up when it is negative.

Coupled Position and Orientation (Kin_Coupled)

A coupled model combines a position kinematics, which places a flange, with an orientation kinematics mounted on the flange, which turns the tool. For example, a gantry with a gripper that turns about Z is a Gantry XYZ with a C axis. The editor shows the type and parameters of each part. The axes of the position kinematics come first, followed by the axes of the orientation kinematics. The position kinematics can be a gantry, a three-axis SCARA or a polar model. The orientation kinematics can be one of the following models.

C Axis (Kin_CAxis)

A single rotary axis that turns the tool about Z, without moving the tool center point. It controls the rotation RZ of the tool.

C Axis Kinematics
Parameter Description
Offset C (dOffsetC) The value of the C axis while the tool points along X.
Two-Axis Wrist (Kin_Wrist2)

A fork head, where axis A turns the fork about Z of the flange, and axis B tilts the tool between the arms of the fork.

Two-Axis Wrist Kinematics
Parameter Description
Tool length (dToolLength) The distance along the tool from the B axis to the tool center point. With both axes at zero, the tool points along Z, so a tool that hangs down from a gantry has a negative length.
Roll axis offset X and Y (dRollAxisOffsetX, dRollAxisOffsetY) The offset of the B axis from the A axis, along X and Y of the fork, or zero when the B axis crosses the A axis.
Roll axis offset Z (dRollAxisOffsetZ) The height of the B axis above the flange.
Bend (xPositive) The configuration: Positive when the angle of axis B is positive, and Negative otherwise.
Three-Axis Wrist (Kin_Wrist3)

A spherical wrist, where axis A turns the fork about Z, axis B tilts the tool, and axis C turns the tool about its own axis. All three axes cross at the wrist centre, so the wrist can give the tool any orientation.

Three-Axis Wrist Kinematics
Parameter Description
Tool offset X and Y (dToolOffsetX, dToolOffsetY) The offset of the tool center point from the axis of the tool, or zero when it is on the axis.
Tool offset Z (dToolOffsetZ) The distance along the tool from the wrist centre to the tool center point. A tool that hangs down from a gantry has a negative offset.
Offset A (dOffsetA) The value of axis A while the B axis lies along Y.
Offset B (dOffsetB) The value of axis B while the tool points along Z.
Offset C (dOffsetC) The value of axis C while Y of the tool lies along the B axis.
Hand (xHandDown) The configuration: Down when the angle of axis B is positive, and Up when it is negative.

Writing a Coordinated Motion Program

The following steps set up a gantry with three axes named GantryX, GantryY and GantryZ:

  1. Create an axis definition file for each axis, and bind each axis to its motor. Set the maximum velocity, acceleration and deceleration of each axis to values that suit the machine.
  2. Create a kinematics file named GantryKinematics, and set its type to Gantry XYZ.
  3. Create an axes group file named Gantry. Add the three axes in the order X, Y and Z, and select GantryKinematics as the kinematic model.

A coordinated motion program powers each axis with MC_Power, enables the group with MC_GroupEnable, and then issues motion commands to the group. The group does not power its axes, so each axis still needs its own MC_Power instance. The following program moves the tool around the corners of a square, at a height of 50 above the origin:

PROGRAM Main
VAR
    PowerX : MC_Power;
    PowerY : MC_Power;
    PowerZ : MC_Power;
    Enable : MC_GroupEnable;
    Move : MC_MoveLinearAbsolute;
    Corners : ARRAY[1..4] OF MC_POSITION := [[0.0, 0.0, 50.0], [200.0, 0.0, 50.0], [200.0, 200.0, 50.0], [0.0, 200.0, 50.0]];
    Corner : INT := 1;
END_VAR

PowerX(Axis := GantryX, Enable := TRUE);
PowerY(Axis := GantryY, Enable := TRUE);
PowerZ(Axis := GantryZ, Enable := TRUE);

// Enables the group once every axis is powered.
Enable(AxesGroup := Gantry, Execute := PowerX.Status AND PowerY.Status AND PowerZ.Status);

// Moves to each corner of the square in turn, once the group is enabled.
Move(AxesGroup := Gantry, Execute := Enable.Done, Position := Corners[Corner], Velocity := 200.0, Acceleration := 1000.0, Deceleration := 1000.0, CoordSystem := MCS);
IF Move.Done THEN
    Move(AxesGroup := Gantry, Execute := FALSE);
    Corner := Corner MOD 4 + 1;
END_IF;
END_PROGRAM

As with the single-axis function blocks, each command is started by a rising edge of Execute, so the program calls the block with Execute := FALSE once after each move. The tool stops at each corner, since each move ends at rest. Blending can join the moves without stopping. A real program should also handle the Error output of each block, as shown in Writing a Motion Program.

Group States

A group has a state of its own, which is reported by MC_GroupReadStatus.

State Description
GroupDisabled The group is not enabled. This is the initial state. The axes can still be moved individually.
GroupStandby The group is enabled and at rest.
GroupMoving A command moves the group, or the group follows a moving product.
GroupHoming MC_GroupHome is homing the axes.
GroupStopping MC_GroupStop is active. Other commands are rejected until the group has stopped and the Execute input of MC_GroupStop is FALSE.
GroupErrorStop The group has an error, and decelerates to a stop along its path. MC_GroupReset clears the error.

The MC_GroupEnable function block moves the group from GroupDisabled to GroupStandby, and MC_GroupDisable returns it to GroupDisabled from any state. Motion commands are accepted in GroupStandby and GroupMoving, and a command that is not allowed in the current state reports the GroupStateNotAllowed error. A motion command is also rejected with the AxisNotReady error while an axis of the group is not powered, or is moving on its own.

While the group moves, its axes are in the SynchronizedMotion axis state. When the group comes to rest in GroupStandby, its axes return to Standstill. If an axis of the group loses power, the group returns to GroupDisabled.

Moves

There are three kinds of move, which each have an absolute and a relative function block. An absolute move goes to a position. A relative move goes by a distance from the end of the previous command when it is buffered or blended, and otherwise from the current position.

Linear Moves

The MC_MoveLinearAbsolute and MC_MoveLinearRelative function blocks move the tool center point along a straight line. The Velocity input is the path velocity, which is the speed of the tool along the path, in PLC units per second. The Acceleration, Deceleration and Jerk inputs are also measured along the path, and a value of zero uses the limits of the axes. These inputs only limit the motion of the tool center point. A move in MCS or PCS that only turns the tool, or only moves the additional axes, therefore ignores them, and moves with the maximum velocity, acceleration and deceleration of the axes instead, like a direct move. Such a move is rejected with the InvalidVelocity error when none of the axes that it moves has a maximum velocity.

The group keeps every axis within its own maximum velocity, acceleration and deceleration. When a move would exceed the limit of an axis, the group moves more slowly along the path, rather than rejecting the command. All of the axes therefore start and arrive together, and the tool stays exactly on its path. Note that this differs from the single-axis function blocks, which reject an input that exceeds a maximum of the axis. A move is rejected with the PositionOutsideLimits error, before anything moves, when its target or any point along its path lies beyond an enabled software limit of an axis. The whole path is checked, so an arc that bulges past a limit, or a straight line in MCS that takes a joint of a robot past its limit between the two ends, is rejected even when both ends are within the limits.

Circular Moves

The MC_MoveCircularAbsolute and MC_MoveCircularRelative function blocks move the tool center point along an arc. The arc is defined by the start point, the EndPoint input and an auxiliary point, AuxPoint, whose meaning is chosen by the CircMode input:

  • BORDER: The auxiliary point is a point on the arc, between the start point and the end point. The arc runs from the start point through the auxiliary point to the end point. This is the simplest mode, since the three points define both the circle and the direction of travel.
  • CENTER: The auxiliary point is the centre of the circle. There are two arcs from the start point to the end point around the centre, and PathChoice chooses between them: COUNTERCLOCKWISE takes the shorter arc, and CLOCKWISE takes the longer arc. Note that PathChoice is CLOCKWISE when it is not assigned. A half circle cannot be defined in this mode, since both arcs are equally long, so it is rejected with the InvalidCircle error. Use BORDER or RADIUS mode for a half circle.
  • RADIUS: The auxiliary point is a vector that is perpendicular to the plane of the circle, and whose length is the radius. For example, [0.0, 0.0, 50.0] defines an arc with a radius of 50 in the XY plane. Seen from the tip of the vector, the arc turns counterclockwise from the start point to the end point. There are two circles with this radius through both points, and PathChoice chooses between them: COUNTERCLOCKWISE takes the shorter arc, and CLOCKWISE takes the longer arc.

The arc lies in the plane of the X, Y and Z coordinates, and the other entries, such as the orientation of the tool, change evenly along the arc. In RADIUS mode, an end point that lies above or below the plane of the circle produces a helix. A full circle needs two moves, since the start point and the end point of an arc must differ. A set of points that defines no arc, such as three points on a line, is rejected with the InvalidCircle error. In MC_MoveCircularRelative, the auxiliary point and the end point are relative to the start point.

The following call moves the tool from [0.0, 0.0, 0.0] along a half circle with a radius of 100 to [200.0, 0.0, 0.0], through the point [100.0, 100.0, 0.0] at the top of the half circle:

Arc(AxesGroup := Gantry, Execute := TRUE, CircMode := BORDER, AuxPoint := Through, EndPoint := ArcEnd, Velocity := 100.0, Acceleration := 1000.0, Deceleration := 1000.0, CoordSystem := MCS);

Here, Through is [100.0, 100.0, 0.0] and ArcEnd is [200.0, 0.0, 0.0].

Direct Moves

The MC_MoveDirectAbsolute and MC_MoveDirectRelative function blocks move each axis directly to its target, without a path for the tool. All of the axes start and arrive together, but the tool does not move along a straight line, unless the model is a Cartesian or gantry model. Direct moves are usually the fastest way to move between two positions, since every axis moves the shortest distance. They are useful when the path does not matter, such as when a robot moves through free space, and to place a robot in its configuration. A target in MCS or PCS is converted to the positions of the axes before the move.

Direct moves have no velocity, acceleration or deceleration inputs. They move with the maximum velocity, acceleration and deceleration of the axes, so these must be set in the axis definition file of every axis of the group. The axis that needs the most time moves at its limits, and the other axes move more slowly, so that all of them arrive together. A direct move is rejected with the InvalidVelocity error when none of the axes that it moves has a maximum velocity.

There are two ways to make direct moves, and moves that only turn the tool, slower than the maximums of the axes:

  • MC_GroupSetOverride: The velocity, acceleration and jerk factors scale all motion of the group, including direct moves. The factors remain in effect until they are changed, so this suits a slower phase of a program, such as a setup mode.
  • MC_WriteParameter: Lowers the maximum velocity (parameter 9), acceleration (parameter 13) or deceleration (parameter 15) of an axis while the program runs. Direct moves use the new values, so the limits of each axis can be changed separately.

Blending

A path with a sharp corner, such as the corner of a square, can only be followed by stopping at the corner, since the direction of travel changes instantly there. Blending replaces the corner with a smooth curve, so the tool can travel around it without stopping. This is much faster, and gives a smoother motion, at the cost of not reaching the corner exactly.

The BufferMode input of a move determines how the move takes over from the previous move, using the same buffer modes as the single-axis function blocks. With mcBuffered, the move starts once the previous move is done, so the group stops at the corner. With a blending buffer mode, such as mcBlendingPrevious, the group travels around the corner along a transition curve. The blending buffer mode chooses the velocity at the corner, such as the velocity of the previous move with mcBlendingPrevious. The velocity is reduced if needed, so that the axes stay within their acceleration limits around the curve.

The TransitionMode input chooses the size of the curve, and the TransitionParameter input gives its value. TransitionParameter accepts a number, such as 20.0, or any one-dimensional REAL or LREAL array, such as an MC_POSITION; only its first entry is used:

Transition Mode Parameter Description
TMNone No curve. The group stops at the corner, even with a blending buffer mode. This is the default.
TMCornerDistance Distance The curve leaves the previous move at this distance before the corner, and joins the next move at this distance after the corner.
TMMaxCornerDeviation Distance The curve is as large as possible, while passing no further than this distance from the corner.
TMStartVelocity Percentage The previous move starts to decelerate towards the corner as usual, and the curve starts once its velocity has fallen to this percentage of its velocity. A higher percentage gives a larger curve. The blending buffer modes have no effect with this transition mode.
TMConstantVelocity Percentage The tool travels around the curve at this percentage of the blending velocity, and the curve is made large enough for the axes to keep this velocity within their acceleration limits.

The curve reaches at most halfway along each of the two moves, so a short move limits the size of the curves at its ends. Two moves that continue in the same direction blend without a curve, provided that the orientation of the tool and the additional axes also continue at the same rate. Otherwise, a short curve smooths the change, for example when the second move starts to turn the tool. A curve that would take an axis beyond an enabled software limit is not used, and the group stops at the corner instead. The transition modes that need a corner, TMCornerDistance and TMMaxCornerDeviation, are rejected with the InvalidTransitionMode error when used with mcAborting or mcBuffered, and TMConstantVelocity is also rejected with mcBuffered. Other PLCs may treat some combinations differently. For example, some reject a blending buffer mode with TMNone, and some ignore the transition mode of a move with mcBuffered rather than rejecting it.

A blending move must be started before the group reaches the start of the curve, otherwise the moves are joined at rest. The simplest approach is to start all of the moves of a sequence in the same scan, each with its own function block instance. The following program travels around the square from the previous example without stopping, with curves that start 20 units before each corner. It starts all four sides together, and starts them again each time the last side is done, so the tool goes around the square repeatedly:

PROGRAM Main
VAR
    PowerX : MC_Power;
    PowerY : MC_Power;
    PowerZ : MC_Power;
    Enable : MC_GroupEnable;
    Side1 : MC_MoveLinearAbsolute;
    Side2 : MC_MoveLinearAbsolute;
    Side3 : MC_MoveLinearAbsolute;
    Side4 : MC_MoveLinearAbsolute;
    Corner1 : MC_POSITION := [200.0, 0.0, 50.0];
    Corner2 : MC_POSITION := [200.0, 200.0, 50.0];
    Corner3 : MC_POSITION := [0.0, 200.0, 50.0];
    Corner4 : MC_POSITION := [0.0, 0.0, 50.0];
    Rounding : LREAL := 20.0; // The corner distance.
    Start : BOOL;
END_VAR

PowerX(Axis := GantryX, Enable := TRUE);
PowerY(Axis := GantryY, Enable := TRUE);
PowerZ(Axis := GantryZ, Enable := TRUE);
Enable(AxesGroup := Gantry, Execute := PowerX.Status AND PowerY.Status AND PowerZ.Status);

// Starts the four sides together, and again each time the last side is done, so that the motion repeats.
Start := Enable.Done AND NOT Side4.Busy;
Side1(AxesGroup := Gantry, Execute := Start, Position := Corner1, Velocity := 200.0, Acceleration := 1000.0, Deceleration := 1000.0, CoordSystem := MCS);
Side2(AxesGroup := Gantry, Execute := Start, Position := Corner2, Velocity := 200.0, Acceleration := 1000.0, Deceleration := 1000.0, CoordSystem := MCS, BufferMode := mcBlendingPrevious, TransitionMode := TMCornerDistance, TransitionParameter := Rounding);
Side3(AxesGroup := Gantry, Execute := Start, Position := Corner3, Velocity := 200.0, Acceleration := 1000.0, Deceleration := 1000.0, CoordSystem := MCS, BufferMode := mcBlendingPrevious, TransitionMode := TMCornerDistance, TransitionParameter := Rounding);
Side4(AxesGroup := Gantry, Execute := Start, Position := Corner4, Velocity := 200.0, Acceleration := 1000.0, Deceleration := 1000.0, CoordSystem := MCS, BufferMode := mcBlendingPrevious, TransitionMode := TMCornerDistance, TransitionParameter := Rounding);
END_PROGRAM

The first side uses the default buffer mode, mcAborting, so it starts immediately. The group stops at the end of the fourth side, before the sequence starts again. A path is a more convenient way to define a long sequence of moves.

The velocity of a curve is the velocity of the tool center point, so the tool keeps the blending velocity around the corner even when the tool turns or the additional axes move along the curve. Their motion is spread along the curve, and the velocity is only reduced when an axis would otherwise exceed its own limits.

A move that only turns the tool, or only moves the additional axes, has no path for the tool center point, so no curve can join it to a move that travels. When one of these moves blends with a move that travels, the move that travels keeps its own profile and comes to rest at its end, while the other move starts gently within the transition distance before that end. For example, a gripper that should turn after a linear move starts to turn while the tool is still travelling to its target, rather than waiting for it to stop.

An aborting move can also blend. When a moving group is aborted by a move with TMStartVelocity or TMConstantVelocity, the group turns smoothly from its current direction onto the path of the new move. With TMNone, the group first stops along its current path, and then moves to the new target. The group also stops first when the curve onto the new path would take an axis beyond an enabled software limit.

Moves in different coordinate systems can also blend, such as a direct move in ACS into a linear move in MCS, or a move into or out of a moving product coordinate system. When the two paths cannot be joined by a curve, because one is in axis coordinates and the other passes through a kinematic model, or because one of them moves with a product, the two moves overlap instead. Over the corner distance, the first move slows down while the second speeds up, and the axes follow the sum of both motions, so the group passes near the corner without stopping. The corner distance is measured along each move in its own units, so for a direct move it is in the units of the axes, and TMMaxCornerDeviation limits the deviation from the corner in the coordinates of the axes.

Stopping

Every stop keeps the tool on its path, including around the curves of blended moves, so the tool never cuts a corner while it stops.

  • MC_GroupHalt: Stops the group with a controlled deceleration, for a normal stop. Another motion command can take over during the deceleration.
  • MC_GroupStop: Stops the group for an emergency stop, and discards any buffered commands. The group stays in GroupStopping, and rejects other motion commands, while the Execute input of MC_GroupStop is TRUE.
  • MC_GroupInterrupt and MC_GroupContinue: MC_GroupInterrupt pauses the group on its path without ending the active command, which remains busy. MC_GroupContinue then resumes the command from where the group stopped. This is useful to pause a machine, for example while a safety door is open.

The MC_GroupSetOverride function block scales the velocity, acceleration and jerk of all motion of the group, which is useful for a speed override on an operator panel. A velocity factor of zero holds the group still on its path, without ending its commands. The override does not affect MC_GroupStop.

Product Coordinate Systems

A product coordinate system (PCS) is attached to a product, such as a pallet, a part or a fixture. Positions in PCS are relative to the product, so a program can describe its moves in the coordinates of the product, regardless of where the product is placed. For example, the positions of the slots of a pallet are the same for every pallet, even if each pallet is placed at a slightly different position.

MC_SetCartesianTransform and MC_SetCoordinateTransform place the product coordinate system in the machine coordinate system. TransX, TransY and TransZ give the position of its origin, and RotAngle1, RotAngle2 and RotAngle3 give its rotation about X, Y and Z in degrees, applied in that order. Setting every value to zero makes the product coordinate system the same as the machine coordinate system again. The following program places the product coordinate system at the corner of a pallet, turned by 30 degrees about Z, and then moves to a slot of the pallet, 100 units along its edge:

PROGRAM Main
VAR
    PowerX : MC_Power;
    PowerY : MC_Power;
    PowerZ : MC_Power;
    Enable : MC_GroupEnable;
    SetPallet : MC_SetCartesianTransform;
    Move : MC_MoveLinearAbsolute;
    Slot : MC_POSITION := [100.0, 0.0, 0.0];
END_VAR

PowerX(Axis := GantryX, Enable := TRUE);
PowerY(Axis := GantryY, Enable := TRUE);
PowerZ(Axis := GantryZ, Enable := TRUE);
Enable(AxesGroup := Gantry, Execute := PowerX.Status AND PowerY.Status AND PowerZ.Status);

// Places the product coordinate system at the corner of the pallet.
SetPallet(AxesGroup := Gantry, Execute := Enable.Done, TransX := 500.0, TransY := 200.0, RotAngle3 := 30.0, ExecutionMode := mcImmediately);

// Moves to the slot, given in the coordinates of the pallet.
Move(AxesGroup := Gantry, Execute := SetPallet.Done, Position := Slot, Velocity := 200.0, Acceleration := 1000.0, Deceleration := 1000.0, CoordSystem := PCS);
END_PROGRAM

The ExecutionMode input chooses when a new coordinate system takes effect: immediately (mcImmediately), once the active command is done (mcDelayed), or once all buffered commands are done (mcQueued). A coordinate system cannot be changed while the group moves along a path in that coordinate system, since the axes would have to jump. Such a change is rejected with the GroupStateNotAllowed error. The same applies to MC_SetKinTransform, which selects another kinematic model while the program runs.

Tracking Moving Products

The product coordinate system can also move, so that the tool follows a product that moves, such as a box on a conveyor. Moves in PCS then target positions on the moving product, and the group moves with the product to reach them. There are three function blocks that make the product coordinate system move:

  • MC_TrackConveyorBelt: Follows an object on a conveyor belt, which is driven by an axis.
  • MC_TrackRotaryTable: Follows an object on a rotary table, which is turned by an axis in degrees.
  • MC_SetDynCoordTransform: Follows the tool of another group, for example so that one robot can work on a part that another robot holds.

For a conveyor belt, ConveyorBeltOrigin gives the position and orientation of the belt in the machine coordinate system, with its X axis pointing in the direction of travel. The origin of the belt can be any point on the belt, but the centre of the start of the belt is usually the simplest choice. InitialObjectPosition gives the position of the object relative to the origin of the belt, at the moment that tracking starts. The position of the object is usually known from a sensor that detects it at a known position along the belt. From then on, the product coordinate system moves with the distance that the belt axis travels. The CoordSystem input of these blocks must be PCS.

The following program runs the conveyor axis Belt with MC_MoveVelocity. The belt travels in the direction of the machine’s X axis, and the centre of the start of the belt is at [-500.0, 300.0, 0.0] in machine coordinates, as given by BeltOrigin. The sensor bound to BoxSensor is 300 units along the belt, so a box that it detects is at [300.0, 0.0, 0.0] relative to the start of the belt, as given by SensorPosition. When the sensor detects a box, the program starts to track the box, and moves the tool to 50 units above it. The tool then follows the box until the next move in MCS or ACS:

PROGRAM Main
VAR
    PowerX : MC_Power;
    PowerY : MC_Power;
    PowerZ : MC_Power;
    PowerBelt : MC_Power;
    Enable : MC_GroupEnable;
    Run : MC_MoveVelocity;
    Track : MC_TrackConveyorBelt;
    Follow : MC_MoveLinearAbsolute;
    BeltOrigin : MC_POSITION := [-500.0, 300.0, 0.0];
    SensorPosition : MC_POSITION := [300.0, 0.0, 0.0];
    AboveBox : MC_POSITION := [0.0, 0.0, 50.0];
    BoxSensor AT %IX0.0 : BOOL;
END_VAR

PowerX(Axis := GantryX, Enable := TRUE);
PowerY(Axis := GantryY, Enable := TRUE);
PowerZ(Axis := GantryZ, Enable := TRUE);
PowerBelt(Axis := Belt, Enable := TRUE);
Enable(AxesGroup := Gantry, Execute := PowerX.Status AND PowerY.Status AND PowerZ.Status);
Run(Axis := Belt, Execute := PowerBelt.Status, Velocity := 100.0, Acceleration := 500.0, Deceleration := 500.0);

// Starts tracking the box when the sensor detects it.
Track(AxesGroup := Gantry, ConveyorBelt := Belt, Execute := BoxSensor AND Enable.Done, ConveyorBeltOrigin := BeltOrigin, InitialObjectPosition := SensorPosition, CoordSystem := PCS);

// Moves above the box, once the product coordinate system moves with it.
Follow(AxesGroup := Gantry, Execute := Track.Active, Position := AboveBox, Velocity := 300.0, Acceleration := 2000.0, Deceleration := 2000.0, CoordSystem := PCS);
END_PROGRAM

A tracking block never reports Done. It remains Busy and Active for as long as the product coordinate system moves, so a program should wait for Active rather than Done. Tracking ends when another transformation block replaces the product coordinate system, and the tracking block then reports CommandAborted.

After a move in PCS, the group keeps following the product while it rests on it, and stays in GroupMoving with its axes in SynchronizedMotion. A move in MCS or ACS ends the following, and the group rests in GroupStandby once that move is done. The product coordinate system keeps moving, so the next move in PCS follows the product again. A move into the moving coordinate system gradually takes on the motion of the product along its path, so the axes do not jump to the velocity of the product.

While the group follows a product, MC_GroupHalt, MC_GroupStop and an error stop the group in the machine coordinate system, so it comes to rest while the product moves on. MC_GroupInterrupt instead stops the group relative to the product, so it keeps following the product, and MC_GroupContinue resumes the move.

Paths

A path is a sequence of linear and circular moves, which is defined as an array of MC_PATH_POINT values. Each point describes one move to that point: whether the tool moves there along a straight line or an arc, the position it moves to, its velocity and limits, and how the move joins the previous move. MC_PathSelect prepares the path, and MC_MovePath then moves the group along it, joining the points with their transitions. This is more convenient than one function block instance for each move, especially for long paths. The following program moves around a rectangle with a rounded end:

PROGRAM Main
VAR
    PowerX : MC_Power;
    PowerY : MC_Power;
    PowerZ : MC_Power;
    Enable : MC_GroupEnable;
    Select : MC_PathSelect;
    Run : MC_MovePath;
    Path : MC_PATH_DATA_REF;
    Points : ARRAY[1..4] OF MC_PATH_POINT := [
        (Segment := mcPathLinear, Position := [200.0, 0.0, 50.0], Velocity := 200.0),
        (Segment := mcPathCircular, Position := [200.0, 200.0, 50.0], AuxPoint := [300.0, 100.0, 50.0], CircMode := BORDER, Velocity := 100.0, TransitionMode := TMCornerDistance, TransitionParameter := [10.0]),
        (Segment := mcPathLinear, Position := [0.0, 200.0, 50.0], Velocity := 200.0, TransitionMode := TMCornerDistance, TransitionParameter := [10.0]),
        (Segment := mcPathLinear, Position := [0.0, 0.0, 50.0], Velocity := 200.0, TransitionMode := TMCornerDistance, TransitionParameter := [20.0])
    ];
END_VAR

PowerX(Axis := GantryX, Enable := TRUE);
PowerY(Axis := GantryY, Enable := TRUE);
PowerZ(Axis := GantryZ, Enable := TRUE);
Enable(AxesGroup := Gantry, Execute := PowerX.Status AND PowerY.Status AND PowerZ.Status);

// Prepares the path, and then moves along it from where the group is.
Select(AxesGroup := Gantry, PathData := Path, PathDescription := Points, Execute := Enable.Done, CoordSystem := MCS);
Run(AxesGroup := Gantry, PathData := Path, Execute := Select.Done, CoordSystem := MCS);
END_PROGRAM

The first point joins the previous command using the BufferMode, TransitionMode and TransitionParameter inputs of MC_MovePath. Each following point joins the previous point using its own transition, at the velocity of the new point, or at rest when its transition mode is TMNone. The points are given in the coordinate system of MC_PathSelect, and the CoordSystem input of MC_MovePath must be the same. A path can have any number of points.

Synchronizing Axes and Groups

Two function blocks couple a group to a single axis, in a similar way to gearing:

  • MC_SyncAxisToGroup: Couples an axis to the distance that the group travels along its paths. For example, a glue pump can deliver an amount of glue proportional to the distance that the nozzle travels, whatever the speed of the nozzle. The axis must not be an axis of the group.
  • MC_SyncGroupToAxis: Moves the group along a prepared path, with its position along the path coupled to a master axis, like a cam. For example, a cutting head can follow a path at a rate set by the conveyor that carries the material. With mcPeriodic, the path repeats as the master moves on, which suits a closed path. With mcNonPeriodic, the group stops at the end of the path.

Single-Axis Commands

The axes of a group can still be commanded individually with the single-axis function blocks, while the group is not moving. For example, an axis can be jogged with MC_Jog while the group is in GroupStandby. A group move is rejected with the AxisNotReady error while an axis of the group moves on its own.

A single-axis motion command or MC_Stop on an axis that the group is moving takes the axis away from the group. The group then enters GroupErrorStop with the GroupInterruptedBySingleAxis error, and stops its other axes along the path. An axis fault, such as a following error, also stops the group with the GroupAxisFault error.

Homing and Setting Positions

The MC_GroupHome function block homes every axis of the group at the same time, with the homing procedure configured in the homing settings of each axis. Its Position input gives the position assigned to each axis, in ACS. If the homing of an axis fails, the group enters GroupErrorStop with the GroupHomingFailed error. The axes of a group can also be homed individually with the single-axis homing function blocks, while the group is not moving.

The MC_GroupSetPosition function block sets the coordinates of every axis without moving, like MC_SetPosition for each axis. In ACS, Position gives the new coordinate of each axis. In MCS or PCS, Position is first converted to the coordinates of the axes, so that the tool then reads as the given position, and no coordinate system changes. A position that the kinematic model cannot reach is rejected with the TargetUnreachable error. With Relative, the converted position is added to the coordinates of the axes. This only adds the given distance in ACS, or in MCS with a Cartesian or gantry model, so use Relative in ACS for other models and for PCS.

Custom Kinematics

A machine that none of the built-in models describes can be described by a function block of the program, which implements the MC_KIN_REF interface. The interface has a property and two methods:

  • NumAxes: The number of axes that the model drives.
  • AxesToCartesian: Calculates the position of the tool in the machine coordinate system from the positions of the axes. This is known as forward kinematics.
  • CartesianToAxes: Calculates the positions of the axes that place the tool at a position in the machine coordinate system. This is known as inverse kinematics. The AxesPosition argument holds the current positions of the axes on entry, which can be used to choose between several solutions, and the solution on exit. The method returns FALSE when the position cannot be reached.

The following function block describes a planar arm with two rotary joints, in degrees. Axis 1 turns the first arm, of length Length1, from the X axis. Axis 2 turns the second arm, of length Length2, from the line of the first arm. AxesToCartesian calculates the position of the tool from the two angles, and CartesianToAxes calculates the two angles from the position of the tool. With only two joints, the arm can reach a position in the XY plane, but cannot also choose the orientation of the tool. The tool turns with the arms, so AxesToCartesian reports its rotation about Z (RZ) as the sum of the two angles, and CartesianToAxes ignores the orientation of the target:

Planar Arm Kinematics

Here, θ1 and θ2 are the two joint angles, AxesPosition[1] and AxesPosition[2], and L1 and L2 are Length1 and Length2. The AxesToCartesian method calculates the forward kinematics, which give the position of the tool from the joint angles. The first arm starts at the origin and points at the angle θ1 from the X axis, so the elbow is at:

$$x_e = L_1 \cos\theta_1, \quad y_e = L_1 \sin\theta_1$$

The second arm starts at the elbow. Its angle θ2 is measured from the line of the first arm, so it points at the angle θ1 + θ2 from the X axis. Adding the second arm to the position of the elbow gives the position of the tool. The tool turns with the second arm, so its rotation about Z is the angle of the second arm:

$$\begin{aligned} X &= L_1 \cos\theta_1 + L_2 \cos(\theta_1 + \theta_2) \\ Y &= L_1 \sin\theta_1 + L_2 \sin(\theta_1 + \theta_2) \\ R_Z &= \theta_1 + \theta_2 \end{aligned}$$

The CartesianToAxes method calculates the inverse kinematics, which give the joint angles from the position of the tool. The base, the elbow and the tool form a triangle, whose sides are L1, L2, and the distance from the base to the tool, whose square is X2 + Y2. The angle of the triangle at the elbow is 180° - θ2, since θ2 is measured from the line of the first arm. The law of cosines relates the three sides to this angle, and cos(180° - θ2) = -cos θ2:

$$X^2 + Y^2 = L_1^2 + L_2^2 - 2 L_1 L_2 \cos(180^\circ - \theta_2) = L_1^2 + L_2^2 + 2 L_1 L_2 \cos\theta_2$$

Solving for θ2 gives the elbow angle:

$$\theta_2 = \pm \arccos\left(\frac{X^2 + Y^2 - L_1^2 - L_2^2}{2 L_1 L_2}\right)$$

The angles θ2 and -θ2 have the same cosine, so there are two solutions, with the elbow on either side. The sign therefore chooses the configuration of the arm, and the function block keeps the sign of the current angle, so that the elbow stays on the side that it is on. When the fraction inside the arccos is greater than 1 or less than -1, the tool is further away than the two arms can reach, or closer than they can fold, so CartesianToAxes returns FALSE.

With θ2 known, the shoulder angle θ1 follows from two directions. The direction from the base to the tool is atan2(Y, X) from the X axis. Measured from the first arm instead, the tool is at the following position, which is the forward kinematics with θ1 set to zero:

$$(L_1 + L_2 \cos\theta_2,\ L_2 \sin\theta_2)$$

So the tool lies at the angle atan2(L2 sin θ2, L1 + L2 cos θ2) from the first arm. The first arm is turned by θ1 from the X axis, so θ1 is the difference between the two directions:

$$\theta_1 = \text{atan2}(Y, X) - \text{atan2}(L_2 \sin\theta_2,\ L_1 + L_2 \cos\theta_2)$$

The atan2 function gives the angle of a point from its coordinates, in the correct quadrant, unlike atan(Y / X). The function block uses radians for the trigonometric functions, so it converts the angles from degrees.

FUNCTION_BLOCK PlanarArm IMPLEMENTS MC_KIN_REF
VAR_INPUT
    Length1 : LREAL; // The length of the first arm.
    Length2 : LREAL; // The length of the second arm.
END_VAR
VAR CONSTANT
    Radians : LREAL := 0.017453292519943295; // Radians per degree.
END_VAR

PROPERTY_GET PUBLIC NumAxes : UDINT
NumAxes := 2;
END_PROPERTY

METHOD PUBLIC AxesToCartesian : BOOL
VAR_INPUT
    AxesPosition : MC_POSITION;
END_VAR
VAR_OUTPUT
    CartesianPosition : MC_POSITION;
END_VAR
VAR
    First : LREAL;
    Sum : LREAL;
END_VAR
First := AxesPosition[1] * Radians;
Sum := (AxesPosition[1] + AxesPosition[2]) * Radians;
CartesianPosition[1] := Length1 * COS(First) + Length2 * COS(Sum);
CartesianPosition[2] := Length1 * SIN(First) + Length2 * SIN(Sum);
CartesianPosition[6] := AxesPosition[1] + AxesPosition[2]; // The tool turns with the arms.
AxesToCartesian := TRUE;
END_METHOD

METHOD PUBLIC CartesianToAxes : BOOL
VAR_INPUT
    CartesianPosition : MC_POSITION;
END_VAR
VAR_IN_OUT
    AxesPosition : MC_POSITION;
END_VAR
VAR
    Cosine : LREAL;
    Elbow : LREAL;
END_VAR
Cosine := (CartesianPosition[1] * CartesianPosition[1] + CartesianPosition[2] * CartesianPosition[2] - Length1 * Length1 - Length2 * Length2) / (2.0 * Length1 * Length2);
IF Cosine > 1.0 OR Cosine < -1.0 THEN
    CartesianToAxes := FALSE; // The position is out of reach.
    RETURN;
END_IF;
Elbow := ACOS(Cosine);
IF AxesPosition[2] < 0.0 THEN
    Elbow := -Elbow; // Keeps the elbow on the side that it is on.
END_IF;
AxesPosition[1] := (ATAN2(CartesianPosition[2], CartesianPosition[1]) - ATAN2(Length2 * SIN(Elbow), Length1 + Length2 * COS(Elbow))) / Radians;
AxesPosition[2] := Elbow / Radians;
CartesianToAxes := TRUE;
END_METHOD
END_FUNCTION_BLOCK

To use the function block as the kinematic model of a group, choose it as the Type of a kinematics file, where it is listed under Custom. The inputs of the function block are then shown as the parameters of the model, and every input must be set. The methods are called in every simulation step while the group moves, so they should be kept simple and fast.

A program can also select a kinematic model at runtime with MC_SetKinTransform, by passing an instance of a function block that implements MC_KIN_REF. This includes the built-in models, which are available as function blocks with the same names, such as Kin_Scara2_Z. The inputs of the instance are set before it is passed:

VAR
    Arm : PlanarArm;
    SetModel : MC_SetKinTransform;
END_VAR

Arm.Length1 := 300.0;
Arm.Length2 := 200.0;
SetModel(AxesGroup := Robot, KinTransform := Arm, Execute := TRUE);

Errors

As with single axes, there are two kinds of error:

  • Function block errors: The block rejects a command, for example because an input is invalid or the group is in the wrong state. The block sets Error and ErrorID, but the group state does not change.
  • Group errors: The group enters GroupErrorStop and decelerates to a stop along its path. The active command reports the GroupFault error. Use MC_GroupReadError to read the error, and MC_GroupReset to clear it. The MC_GroupReset function block also resets any axis of the group that has a fault, like MC_Reset.

A group error occurs when an axis of the group has a fault, when a single-axis command takes an axis away from the moving group, when the homing of an axis fails, or when the kinematic model cannot calculate the positions of the axes while the group moves. A move whose path the kinematic model cannot reach is rejected with the TargetUnreachable error before anything moves. Please see the error identifiers for the full list.

Limitations

  • A group can have at most 16 axes, of which at most ten are additional axes.