Skip to main content

Controlling the Movement of Single Axes

See the PLCopenSingle.project sample project in the installation directory of CODESYS under ..\CODESYS SoftMotion\Examples.

This example shows how to control a drive by means of PLCopen standardized function blocks.

  1. Insert a virtual drive named Drive in the device tree below SoftMotion General Axis Pool.

  2. Create a MOTION_PRG program in ST.

    PROGRAM MOTION_PRG
    VAR
            iStatus: INT;
            Power: MC_Power;
            MoveAbsolute: MC_MoveAbsolute;
            p:REAL:=100;
    END_VAR
    
    CASE iStatus OF
    
    // initialization of the axis
    0:
            Power(Enable:=TRUE, bRegulatorOn:=TRUE, bDriveStart:=TRUE, Axis:=Drive);
            IF Power.Status THEN
                    iStatus := iStatus + 1;
            END_IF
    
    // Move the axis to position p by use of the MC_MoveAbsolute function block
    1:
            MoveAbsolute(Execute:=TRUE, Position:= p, Velocity:=100, Acceleration:=100, Deceleration:=100, Axis:=Drive);
            IF MoveAbsolute.Done THEN
                    MoveAbsolute(Execute:=FALSE, Axis:=Drive);
                    iStatus := iStatus + 1;
            END_IF
    
    // Move the axis back to position 0 by use of the MC_MoveAbsolute function block:
    2:
            MoveAbsolute(Execute:=TRUE, Position:= 0, Velocity:=100, Acceleration:=100, Deceleration:=100, Axis:=Drive);
            IF MoveAbsolute.Done THEN
                    MoveAbsolute(Execute:=FALSE, Axis:=Drive);
                    iStatus := 1;
            END_IF
  3. Add the call of the MOTION_PRG program to the task MainTask.

    Device tree:

    _sm_img_example_single_axis_2.png
  4. Download the project to the controller and start it.

  5. Open the Drive virtual axis in the editor.

    In the Online part of the General tab, you see the axis motion.

    _sm_img_example_single_axis_1.png