Skip to main content

Using Depictor to Visualize Axis Groups

For this project, you also need the CODESYS Depictor add-on with a valid license.

The SoftMotion application consists of four rotary drives configured as an axis group. The first three axes move the TCP in the X/Y-plane, and the fourth axis in the Z-plane.

The example demonstrates how you can use Depictor with the Kin_Scara3_Z kinematic configuration. You can also customize the same procedure for other kinematic configurations.

_sm_img_dep.png

Creating the standard project

  1. Create a standard project with the CODESYS SoftMotion Win controller and the ST programming language.

  2. Add a Library Manager in the POUs view.

  3. Open the Library Manager and add the libraries SM3_Depictor and DepictorBase.

Adding and parameterizing the axes

  1. Insert four virtual axes below the object SoftMotion General Axis Pool and name the axes as Drive1...Drive4.

  2. Parameterize the axes Drive1, Drive2, Drive3, and Drive4 as axis type finite with software limit switches from -180 degrees to 180 degrees.

    Configuration editor:

    _sm_img_depictor_drives.png

For more information, see: Virtual Drive

Configuring the axis groups

  1. Add a "KinScara" axis group below the application. To do this, click Project → Add Object → Axis Group.

  2. In the configurator, click Select kinematics. Select the TRAFO.Kin_Scara3_Z kinematics.

  3. Define the parameters as follows:

    • dArmLength1, dArmLength2, dArmLength3: 500

    • dOffsetA1, dOffsetA2, dOffsetA3, dOffsetZ: 0

  4. Order the axes as follows:

    • A1: Drive1

    • A2: Drive2

    • A3: Drive3

    • Z: Drive4

    Note: You can drag the axes directly into the input field.

For more information, see: Kinematics

Creating the controller program

  1. In the PLC_PRG program, declare instances of the MC_Power function block for all drives. Create an istate variable for the statechart.

    VAR
     Power_Drive1, Power_Drive2, Power_Drive3, Power_Drive4 : MC_Power;
     istate: INT;
    END_VAR
  2. Define a statechart in the implementation.

    CASE istate OF
     0:
     1:
     2:
    END_CASE
  3. Activate all drives in state 0.

    0:
     Power_Drive1(Axis:=Drive1, Enable:=TRUE, bRegulatorOn:=TRUE, bDriveStart:=TRUE);
     Power_Drive2(Axis:=Drive2, Enable:=TRUE, bRegulatorOn:=TRUE, bDriveStart:=TRUE);
     Power_Drive3(Axis:=Drive3, Enable:=TRUE, bRegulatorOn:=TRUE, bDriveStart:=TRUE);
     Power_Drive4(Axis:=Drive4, Enable:=TRUE, bRegulatorOn:=TRUE, bDriveStart:=TRUE);
     IF Power_Drive1.Status AND Power_Drive2.Status AND Power_Drive3.Status AND Power_Drive4.Status THEN
      istate:=istate+1;
     END_IF
  4. When the axes are activated, enable the axis group (switch from "deactivated" to "standby").

    VAR
     GroupEnable:MC_GroupEnable;
    END_VAR
    
    1:
     GroupEnable(AxisGroup:=KinScara, Execute:=TRUE);
     IF GroupEnable.Done THEN
      istate:=istate+1;
     END_IF
  5. Declare and initialize a variable to save the set value in machine coordinates. Declare two instances of type SMC_POS_REF to represent the TCP in Cartesian and axis coordinates.

    VAR
     Frame: MC_COORD_REF:=(X:=-120, Y:=-25); // This variable stores the cartesian position & orientation of the TCP
     Pos_Cart: SMC_POS_REF; // This variable represents the position of the TCP in cartesian coordinates coordinates
     Pos_Axis: SMC_POS_REF := (a := axispos);// This variable represents the position of the TCP in Axis coordinates
    END_VAR
    VAR CONSTANT
     axispos: TRAFO.AXISPOS_REF := (a0 := 0, a1 := 100, a2:=60);
    END_VAR
    
    2:
     Pos_Cart.c:= Frame; // To represent the TCP in cartesian coordinates;
  6. Declare an instance of MC_MoveDirectAbsolute to move the SCARA robot to the specified coordinates.

    VAR
     MoveAbs:MC_MoveDirectAbsolute; // Moves the TCP to the defined coordinates
    END_VAR
    
    2:
     MoveAbs(AxisGroup:=KinScara, Execute:=TRUE, Position:=Pos_Axis,CoordSystem:=SMC_COORD_SYSTEM.ACS, BufferMode:=MC_BUFFER_MODE.Aborting,); //move to the defined Axis coordinates
     //MoveAbs(AxisGroup:=KinScara, Execute:=TRUE, Position:=Pos_Cart,CoordSystem:=SMC_COORD_SYSTEM.MCS, BufferMode:=MC_BUFFER_MODE.Aborting,); //move to the defined cartesian coordinates
    
     IF MoveAbs.Done THEN
             MoveAbs(AxisGroup:=KinScara, Execute:=FALSE); // Waits for the next new coordinates
       istate:=2;
            END_IF
  7. Declare a variable of type SMC_GroupReadSetPosition to read the current value of the robot in Cartesian coordinates and axis coordinates.

    VAR
     Car_pos, Axis_pos :SMC_GroupReadSetPosition; //to read the current axis values
    END_VAR
    
    2:
     Car_pos(AxisGroup:=KinScara, CoordSystem:=SM3_Robotics.SMC_COORD_SYSTEM.MCS, Enable:=TRUE); // to read the current position in cartesian coordinates
     Axis_pos(AxisGroup:=KinScara, CoordSystem:=SM3_Robotics.SMC_COORD_SYSTEM.ACS, Enable:=TRUE); // to read the current axis values

The entire PLC_PRG program

Compare your program and add the missing program parts.

Declaration

PROGRAM PLC_PRG
VAR
    Power_Drive1, Power_Drive2, Power_Drive3, Power_Drive4 :MC_Power;
    istate: INT;

    GroupEnable:MC_GroupEnable;

    Frame:MC_COORD_REF:=(X:=-120, Y:=-25); // This variable stores the cartesian position & orientation of the TCP
    Pos_Cart:SMC_POS_REF; // This variable represents the position of the TCP in cartesian coordinates coordinates
    Pos_Axis:SMC_POS_REF := (a := axispos);// This variable represents the position of the TCP in Axis coordinates

    MoveAbs:MC_MoveDirectAbsolute; // Moves the TCP to the defined coordinates (PTP)

    Car_pos,Axis_pos :SMC_GroupReadSetPosition; //to read the current position of the TCP in Cartesian and Axis Coordinates and display it on the visu

    scara_Config:trafo.Kin_Scara3_Z_Config; // To set the configuration of the SCARA_3_Z
    kin_Config:SMC_SetKinConfiguration; // To set the defined configuration of SCARA_3_Z to the axis group used
    nPeriod:DINT:=0; // SCARA_3_Z Period
    Xelbow:BOOL:=TRUE;

END_VAR
VAR CONSTANT
    axispos : TRAFO.AXISPOS_REF := (a0 := 0, a1 := 100, a2:=60);
END_VAR

Implementation

CASE istate OF

0:
 Power_Drive1(Axis:=Drive1, Enable:=TRUE, bRegulatorOn:=TRUE, bDriveStart:=TRUE);
 Power_Drive2(Axis:=Drive2, Enable:=TRUE, bRegulatorOn:=TRUE, bDriveStart:=TRUE);
 Power_Drive3(Axis:=Drive3, Enable:=TRUE, bRegulatorOn:=TRUE, bDriveStart:=TRUE);
 Power_Drive4(Axis:=Drive4, Enable:=TRUE, bRegulatorOn:=TRUE, bDriveStart:=TRUE);

 IF Power_Drive1.Status AND Power_Drive2.Status AND Power_Drive3.Status AND Power_Drive4.Status THEN
  istate:=istate+1;
 END_IF

1:
 GroupEnable(AxisGroup:=KinScara, Execute:=TRUE);

 IF GroupEnable.Done THEN
  istate:=istate+1;
 END_IF

2:
 scara_Config(xElbowRight:=Xelbow, nPeriodA3:=nPeriod);
 kin_Config(AxisGroup:=KinScara,ConfigData:=scara_Config.Config, Execute:=TRUE);
 Pos_Cart.c:=Frame; // To represent the TCP in cartesian coordinates

 Car_pos(AxisGroup:=KinScara, CoordSystem:=SM3_Robotics.SMC_COORD_SYSTEM.MCS, Enable:=TRUE); // read the current position in cartesian coordinates
 Axis_pos(AxisGroup:=KinScara, CoordSystem:=SM3_Robotics.SMC_COORD_SYSTEM.ACS, Enable:=TRUE); // read the current position in Axis coordinates

 MoveAbs(AxisGroup:=KinScara, Execute:=TRUE, Position:=Pos_Axis,CoordSystem:=SMC_COORD_SYSTEM.ACS, BufferMode:=MC_BUFFER_MODE.Aborting,); //move to the defined axis coordinates
 //MoveAbs(AxisGroup:=KinScara, Execute:=TRUE, Position:=Pos_Cart,CoordSystem:=SMC_COORD_SYSTEM.MCS, BufferMode:=MC_BUFFER_MODE.Aborting,); //move to the defined cartesian coordinates

 IF MoveAbs.Done THEN
  MoveAbs(AxisGroup:=KinScara, Execute:=FALSE); // Waits for the next new coordinates
  istate:=2;
 END_IF
END_CASE

Creating a Depictor program

  1. Add a new "Depic" POU of "Program" type below the application. To do this, click Project → Add Object → POU.

  2. Declare a variable of type SM3_Depictor.SMC_R_Scara3_Z_Data. Declare a variable LrSize of type LREAL and initialize the variable with the value of 100.

    VAR
     ScaraTrafo : SM3_Depictor.SMC_R_Scara3_Z_Data;
     LrSize:LREAL:=100;
    END_VAR
  3. Insert a call to the function block in the implementation.

    ScaraTrafo(AxisGroup:=KinScara, trf:=KinScara.trafo);
  4. Add the "Depic" POU to the MainTask.

Configuring Depictor

  1. Add a "Depictor" object below the application. To do this, click Project → Add Object → Depictor.

  2. Double-click the object.

  3. Select the Pose element in the Depictor tree.

  4. Click Depictor → Add element.

    The Box element is added below the pose.

  5. Select the Depictor Ref. option in the properties of the element.

  6. Click the _cds_icon_three_dots.png button.

  7. Select the SMC_R_Depictor_Scara3_Z object from the SM3_Depictor library.

  8. Define the interface variables as follows:

    • fb: Depic.ScaraTrafo

    • lrZ_: Drive1.fSetPosition

    • lrZmin: 10

    • lrZmax: -50

    • lrSize: Depic.LrSize

    • xShowPlane: 0

Creating visualizations

Create a visualization screen in which the Cartesian coordinates and the axis coordinates can be displayed and modified.

_sm_img_depictor_visu.png
  1. Add a "Visualization" object below the application. To do this, click Project → Add Object → Visualization.

  2. Open the visualization in the editor.

  3. Insert a Rectangle visualization element (1).

  4. Change the properties of the element.

    • Texts → Text: %s

    • Text variables → Text variable: PLC_PRG.Car_pos.Position.c.X

    • Input configuration → OnMouseDown → Write Variable

      • Input type: VisuDialogs.Numpad

      • Use another variable: PLC_PRG.Frame.X

  5. Insert the other Box visualization elements.

  6. Change the properties of elements (2) and (3).

    • Texts → Text: %s

    • Text variables → Text variable: PLC_PRG.Car_pos.Position.c.Y or PLC_PRG.Car_pos.Position.c.Z

    • Input configuration → OnMouseDown → Write Variable

      • Input type: VisuDialogs.Numpad

      • Use another variable: PLC_PRG.Frame.Y and PLC_PRG.Frame.Z

  7. Change the properties of elements (4), (5), and (6).

    • Texts → Text: %s

    • Text variables → Text variable: PLC_PRG.Frame.A or PLC_PRG.Frame.B or PLC_PRG.Frame.C

  8. Change the properties of elements (7), (8), (9), and (10).

    • Texts → Text: %s

    • Text variables → Text variable: PLC_PRG.Axis_pos.Position.a.a0 or PLC_PRG.Axis_pos.Position.a.a1 or PLC_PRG.Axis_pos.Position.a.a2 or PLC_PRG.Axis_pos.Position.a.a3

    • Input configuration → OnMouseDown → Write Variable

      • Input type: VisuDialogs.Numpad

      • Use another variable: PLC_PRG.Pos_Axis.a.a0 and PLC_PRG.Pos_Axis.a.a1 and PLC_PRG.Pos_Axis.a.a2 and PLC_PRG.Pos_Axis.a.a3

  9. Label the visualization elements with the Label element.

Starting and testing the program

You can modify the axis values in the visualization of the project. If you comment out the active movement command (MoveAbs..., ...) in the program PLC_PRG and remove the comments of the second movement command, then you can modify the Cartesian coordinates.

  1. Build the project and download it to the PLC.

  2. Open the editor of the Depictor object in your project.

  3. Switch to the visualization and modify the axis values or the Cartesian values. Observe the movement of the SCARA robot in Depictor.