Skip to content

Function Blocks

Axis Types

FB_BasicAxis

(extends FB_CyclicFB, implements I_BasicAxis)

Complete implementation of I_BasicAxis. For use as a PackML component, use FB_Component_BasicAxis.

READ ALL OF ME

  • The Initialize() method checks to see if the underlying AXIS_REF has been linked to an NC axis. If not, Initialize() will not return TRUE.
  • This behavior can be inhibited by setting the library parameter ALLOW_UNLINKED_NC_AXES to TRUE.
  • The Initialize() method automatically reads all of the axis' NC parameters, which can be accessed via the NCParameters property.
  • CyclicLogic() should be called so that underlying function block calls are made
  • BOOL return values from command methods should be interpreted as "COMMAND ACCEPTED". This is not "COMMAND COMPLETED". Monitor the Busy property to detect when a command has finished (see example below).
  • Most commands are internally interlocked with _Busy such that a command will not be accepted (return TRUE) if a command is already in process. This can be bypassed (move interrupted) by passing TRUE to the AbortPrevious argument of the move method call. If the AbortPrevious argument is not included in the method signature, this should be interpreted to mean the command will take place immediately.

Properties

Axis

PROPERTY Axis : REFERENCE TO AXIS_REF

Returns a reference to the underlying NC axis for use in other axes or otherwise external motion functions.

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
PROGRAM MAIN
VAR
    MyBasicAxis : FB_BasicAxis;
    MyBasicSlaveAxis : FB_BasicSlaveAxis;
    MySlaveAxis : AXIS_REF;
    MC_GearIn : MC_GearIn;
END_VAR

//Mixing basic MC2 and FB_BasicAxis
MC_GearIn(
    Master:= MyBasicAxis.Axis, 
    Slave:= MySlaveAxis, 
    Execute:= TRUE, 
    RatioNumerator:= 1, 
    RatioDenominator:= 1);

//Assigning a FB_BasicAxis to an FB_BasicSlaveAxis
MyBasicSlaveAxis.Master1 REF= MyBasicAxis.Axis;

ExternalSequence

PROPERTY ExternalSequence : I_MotionSequence

The standard motion methods all execute function blocks with the BufferMode input set to MC_Aborting. In the case that your motion sequence requires some sort of buffering or blending, you can create a function block that implements I_MotionSequence and contains any sequence of motion commands you desire. RunExternalSequence() will call Execute() on your custom sequence function block.

HomeMethod

PROPERTY HomeMethod : I_MotionSequence

You can optionally assign an external sequence of events to occur when the Home() method is called. Assigning a function block which implements I_MotionSequence will automatically assign the axis' AXIS_REF for use in whatever function blocks you choose. The instantiation of custom home routine function block should take place in the parent of the FB_BasicAxis instance.

Default Home() Behavior

The default behavior is to set the current position as zero when this property is not set and Home() is called. There is an internal instance of FB_HomeRoutine_SetZeroHere which, if not overridden, is call by Home().

ResetMethod

PROPERTY ResetMethod : I_MotionSequence

You can optionally assign an external sequence of events to occur when the Reset() method is called. This can be useful, for instance, when using an AX5000 or some drive that needs a separate reset routine to be called in addition to MC_Reset. Assigning a function block which implements I_MotionSequence will automatically assign the axis' AXIS_REF for use in whatever function blocks you choose. The instantiation of custom reset routine function block should take place in the parent of the FB_BasicAxis instance.

Default Home() Behavior

The default behavior is to call MC_Reset when this property is not set and the Reset() method is called.

Methods

MoveVelocity()
1
2
3
4
5
METHOD MoveVelocity : BOOL
VAR_INPUT
    Velocity      : LREAL;
    AbortPrevious : BOOL;
END_VAR

Important

The Velocity argument is allowed to be <= 0 (axis will stop--does not call MC_Halt). The Velocity argument will also be automatically transferred to the Velocity property of the function block!

Stop()

METHOD Stop : BOOL

Important

Stop() makes a call MC_Halt internally. MC_Halt can be interruped by a further motion command, whereas MC_Stop cannot.

Examples

Enabling Axis
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
MyAxis.CyclicLogic();

CASE State OF
  0:
    IF MyAxis.Enable() THEN
      State := State + 10;
    END_IF
  10:
    IF MyAxis.Enabled THEN
      State := State + 10;
    END_IF
  20:
    //Do things 
END_CASE
Command a discrete move
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
CASE State OF
  0:
    MyAxis.Velocity := 10;
    IF MyAxis.MoveAbsolute(100, FALSE) THEN
      State := State + 10;
    END_IF

  10:
    IF NOT MyAxis.Busy THEN
      State := State + 10;
    END_IF

  20:
    //More things
END_CASE
Command a velocity move and then change velocity
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
CASE State OF
  0:
    IF MyAxis.MoveVelocity(100, FALSE) THEN
      State := State + 10;
    END_IF

  10:
    IF ChangeVelocity THEN
      MyAxis.MoveVelocity(10, TRUE);
      State := State + 10;
    END_IF

  20:
    //More things
END_CASE

Proper sequencing of multiple axes

Resist the temptation to combine commands to multiple axes in the same state/line. Depending on the command, you can find yourself in a race condition.

Less typing, more headaches:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
CASE State OF
  0:
    //Move is issued to both axes--okay
    IF MyAxis.MoveRelative(10, FALSE) AND MyOtherAxis.MoveRelative(5, FALSE) THEN
      State := State + 10;
    END_IF
  10:
    //MyOtherAxis finishes its move first and second command is issued
    //MyAxis is still busy at this point, so command is ignored until first move is complete
    //Commands end up flip-flopping and axes goes nowhere near where you intended
    IF MyAxis.MoveRelative(1, FALSE) AND MyOtherAxis.MoveRelative(5, FALSE) THEN
      State := State + 10;
    END_IF

  20:
    //You may or may not ever get here...
    IF NOT MyAxis.Busy AND NOT MyOtherAxis.Busy THEN
    State := State + 10;
    END_IF
END_CASE
Result

image

More states, but axes go where you want them to:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
CASE State OF
  0:
    IF MyAxis.MoveRelative(10, FALSE) THEN
      State := State + 10;
    END_IF
  10:
    IF MyOtherAxis.MoveRelative(5, FALSE) THEN
      State := State + 10;
    END_IF
  20:
    //Wait for both axes to be done
    IF NOT MyAxis.Busy AND NOT MyOtherAxis.Busy THEN
      State := State + 10;
    END_IF
  30:
    IF MyAxis.MoveRelative(1, FALSE) THEN
      State := State + 10;
    END_IF
  40:
    IF MyOtherAxis.MoveRelative(5, FALSE) THEN
      State := State + 10;
    END_IF
  50:
    IF NOT MyAxis.Busy AND NOT MyOtherAxis.Busy THEN
      State := State + 10;
    END_IF
END_CASE
Result

image

FB_BasicSlaveAxis

(extends FB_BasicAxis, implements I_BasicSlaveAxis)

Complete implementation of I_BasicSlaveAxis. For use as a PackML component, use FB_Component_BasicSlaveAxis.

Note

See FB_BasicAxis for documentation of base motion funcntions

Examples

Couple two axes at 1:1 ratio
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
CASE State OF
  0:
    MySlaveAxis.Master1 REF= MyMasterAxis.Axis;
    MySlaveAxis.RatioMaster1 := 1.0;
    IF MySlaveAxis.GearIn() THEN
      State := State + 10;
    END_IF

  10:
    IF MySlaveAxis.InGear THEN
      State := State + 10;
    END_IF
END_CASE
Adjusting ratio on the fly
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
CASE State OF
  0:
    MySlaveAxis.Master1 REF= MyMasterAxis.Axis;
    MySlaveAxis.RatioMaster1 := 1.0;
    IF MySlaveAxis.GearIn() THEN
      State := State + 10;
    END_IF

  10:
    IF MySlaveAxis.InGear THEN
      State := State + 10;
    END_IF

  20:
    IF MyMasterAxis.MoveVelocity(100, FALSE) THEN
      State := State + 10;
    END_IF

  30:
    IF AdjustRatio THEN
      MySlaveAxis.RatioMaster1 := 5.0;
      State := State + 10;
    END_IF  
END_CASE

Result

image

Phase adjustments using multimaster gearing

You can gear a second (and third/fourth) master to the same slave axis. This can be useful when you need to make phase adjustments to a master/slave coupling (conveyor gapping, etc.) Moves made to the additional masters are superimposed against the other masters according to the dynamics of the phase adjustment moves.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
CASE State OF
  0:
    MySlaveAxis.Master1 REF= MyMasterAxis.Axis;
    MySlaveAxis.Master2 REF= MyPhaseAdjustAxis.Axis;
    MySlaveAxis.RatioMaster1 := 1.0;
    MySlaveAxis.RatioMaster2 := 1.0;

    IF MySlaveAxis.GearIn() THEN
      State := State + 10;
    END_IF

  10:
    IF MySlaveAxis.InGear THEN
      State := State + 10;
    END_IF

  20:
    //Start master axis
    IF MyMasterAxis.MoveVelocity(100, FALSE) THEN
      State := State + 10;
    END_IF
  30:
    IF AdjustPhase THEN
      //Advance phase of slave by +100 units
      IF MyPhaseAdjustAxis.MoveRelative(100, FALSE) THEN
        State := State + 10;
      END_IF
    END_IF
  40:
    IF NOT MyPhaseAdjustAxis.Busy THEN
      //Advance phase of slave by -200 units
      IF MyPhaseAdjustAxis.MoveRelative(-200, FALSE) THEN
        State := State + 10;
      END_IF            
    END_IF
END_CASE

Result image

FB_CamSlaveAxis

(extends FB_BasicAxis, implements I_CamSlaveAxis)

Complete implementation of I_CamSlaveAxis. For use as a PackML component, use FB_Component_CamSlaveAxis.

Important

  • See FB_BasicAxis for documentation of base motion functions
  • CamParameters.CamTable[] holds cam definition data for 1 to Parameters_NCCamAxis.CAM_SLAVE_AXIS_TABLES cam tables
  • Each instance of ST_CamPoints holds 1 to 1..Parameters_NCCamAxis.CAM_SLAVE_AXIS_MAX_CAM_POINTS of MC_MotionFunctionPoints (see Infosys)
  • Once a slave is coupled to its master, CamParameters.TableSelect specifies which CamParameters.CamTable[] is to be run. The switch-out happens automatically and according to CamParameters.ChangeOptions. The default behavior is an instantaneous switch
  • Update CamParameters.ChangeOptions and use ChangeMode() to modify this behavior
  • Table data of the currently running cam can be updated on the fly using UpdateTable() after updating CamParameters.CamTable[]. Same online change behavior mentioned above applies.

Examples

Hello, Camming!

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
CamParameters.CamTableId                              := Slave.Axis.NcToPlc.AxisId;

//Table 1
CamParameters.CamTable[1].NumberOfPoints              := 3;
CamParameters.CamTable[1].Points[1].PointIndex        := 1;
CamParameters.CamTable[1].Points[1].FunctionType      := MC_MotionFunctionType.MOTIONFUNCTYPE_POLYNOM5;
CamParameters.CamTable[1].Points[1].PointType         := MC_MotionPointType.MOTIONPOINTTYPE_REST;
CamParameters.CamTable[1].Points[1].RelIndexNextPoint := 1;
CamParameters.CamTable[1].Points[1].MasterPos         := 0.0;
CamParameters.CamTable[1].Points[1].SlavePos          := 0.0;
CamParameters.CamTable[1].Points[2].PointIndex        := 2;
CamParameters.CamTable[1].Points[2].FunctionType      := MC_MotionFunctionType.MOTIONFUNCTYPE_POLYNOM5;
CamParameters.CamTable[1].Points[2].PointType         := MC_MotionPointType.MOTIONPOINTTYPE_TURN;
CamParameters.CamTable[1].Points[2].RelIndexNextPoint := 1;
CamParameters.CamTable[1].Points[2].MasterPos         := 180.0;
CamParameters.CamTable[1].Points[2].SlavePos          := 100.0;
CamParameters.CamTable[1].Points[3].PointIndex        := 3;
CamParameters.CamTable[1].Points[3].FunctionType      := MC_MotionFunctionType.MOTIONFUNCTYPE_POLYNOM5;
CamParameters.CamTable[1].Points[3].PointType         := MC_MotionPointType.MOTIONPOINTTYPE_REST;
CamParameters.CamTable[1].Points[3].RelIndexNextPoint := 0;
CamParameters.CamTable[1].Points[3].MasterPos         := 360.0;
CamParameters.CamTable[1].Points[3].SlavePos          := 0.0;
CamParameters.CamTable[1].NumberOfPoints              := 3;
Result image

Coupling above table

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
CASE SequenceState OF
    10:
        IF Master.Enable() THEN
            SequenceState := 11;
        END_IF
    11:
        IF Slave.Enable() THEN
            SequenceState := 12;
        END_IF
    12:
        IF Master.Enabled AND Slave.Enabled THEN
            SequenceState := 20;
        END_IF
    20:
        IF Slave.StartSync() THEN
            SequenceState := 21;
        END_IF
    21:
        IF Slave.InSync THEN
            SequenceState := 22;
        END_IF

    22:
        IF Master.MoveVelocity(100, FALSE) THEN
            SequenceState := 23;
        END_IF
END_CASE
Result image

Update Online Change Mode
1
2
3
4
5
CamParameters.ChangeOptions.ActivationMode := MC_CAMACTIVATION_NEXTCYCLE;

IF Slave.ChangeMode() THEN
  SequenceState := 0;
END_IF
Change Current Table Point Data

1
2
3
4
5
CamParameters.CamTable[1].Points[2].SlavePos          := 250.0;

IF Slave.UpdateTable() THEN
  SequenceState := 51;
END_IF
Result image

Change To Different Table
1
2
3
4
CamParameters.TableSelect := 2;
IF Slave.RunningTable = 2 THEN
  SequenceState := 0;
END_IF

Result image

Pre-Couple Sync Behavior

  • StartSync() is called
  • Correct slave position according to current master position is looked up using MC_ReadCamTableSlaveDynamics
  • MC_MoveModulo is performed on Slave to bring into sync with master according to cam
  • MC_CamIn is executed--slave is now coupled

image

Manually Positioning Slave Prior to Coupling

It is possible that you might want to control the pre-couple synchronization move of the slave on your own. Use FindSyncPos() or FindSlavePos() to do this. After looking up the sync position and manually moving slave axis, use StartCouple() instead of StartSync().

FindSyncPos() Result image

FindSlavePos() Use image

Home Routines

FB_HomeRoutine_AbsHoming

1
FUNCTION_BLOCK FINAL FB_HomeRoutine_AbsHoming EXTENDS FB_CyclicFB IMPLEMENTS I_MotionSequence
Use with multi-turn absolute encoder to make current position read as 0.0 using position bias parameter of the NC encoder object. A persistent variable of the type ST_AbsHomeParameters must be created along with the FB declaration. The persistent variable will store the desired value through power cycles.
1
2
3
4
5
6
VAR PERSISTENT
    AbsHomingParms  : ST_AbsHomeParameters;
END_VAR
VAR
    AbsHoming       : FB_HomeRoutine_AbsHoming;
END_VAR
The initialization code of the application should set the home method and the reference to the parameters variable.
1
2
Axis.HomeMethod:=AbsHoming;
AbsHoming.Parameters REF= AbsHomingParms;
In the Maintenence mode, Execute State, the axis should be manually placed in the desired zero position. An HMI command can trigger the AbsHoming.Execute method a single time to update the position bias parameter.
1
2
3
4
IF AbsHomeCmd THEN
    AbsHoming.Execute();
    AbsHomeCmd:=FALSE;
END_IF

Properties

Property Type Access Description
Parameters ST_AbsHomeParameters RW Get/Set parameter structure

FB_HomeRoutine_HardStop

1
FUNCTION_BLOCK FINAL FB_HomeRoutine_HardStop EXTENDS FB_CyclicFB IMPLEMENTS I_MotionSequence

Sets torque limit and moves axis at a set velocity toward specified end of travel. When a mechanical interference is detected via increasing position lag, sets home to interference position.

Properties

Property Type Access Description
HomePosition LREAL RW Get/Set position that should be set once hard stop is detected
Parameters ST_StepBlockLagBasedParameters RW Get/Set parameter structure

FB_HomeRoutine_SetPosition

1
FUNCTION_BLOCK FINAL FB_HomeRoutine_SetPosition EXTENDS FB_CyclicFB IMPLEMENTS I_MotionSequence

Sets current axis position equal to HomePosition property.

Properties

Property Type Access Description
HomePosition LREAL RW Get/Set position that should be set

FB_HomeRoutine_SetZeroHere

1
FUNCTION_BLOCK FINAL FB_HomeRoutine_SetZeroHere EXTENDS FB_CyclicFB IMPLEMENTS I_MotionSequence

Sets current axis position to 0.0

Hardware Utility Function

FB_ResetRoutine_CoEDrive

1
FUNCTION_BLOCK FINAL FB_ResetRoutine_CoEDrive EXTENDS FB_BaseFB IMPLEMENTS I_MotionSequence

Issues a basic MC_Reset command against the assigned axis. Default behavior for FB_BasicAxis, FB_BasicSlaveAxis.

FB_ResetRoutine_SoEDrive

1
FB_ResetRoutine_SoEDrive EXTENDS FB_BaseFB IMPLEMENTS I_MotionSequence

Issues a SoE reset command, followed by MC_Reset. For use with AX5000 drives.