Using the Codesys SoftPLC as Task Manager

This guide shows the step-by-step process on how to use the example Codesys project and make it communicate with the Realtime controller to control the robots in the Getting Started Guide example project.

 

1 Prerequisites

Install Codesys on a Windows System

  1. Install Codesys V3.5 SP14 x64 or newer on a Windows System

    1. Download the Codesys installer from https://store.codesys.com/codesys.html.

A Codesys account is necessary to proceed with download, so when a user is not logged in, pressing Download will prompt a dialog box leading the user to the “Login or Create an Account” page

Once logged in as a user, the user would have the option to download the 32-bit or 64-bit installer.

2 Setup and Execution

2.1 Realtime Controller

  1. Create a group and load the projects in the Control Panel

The Getting Started Example Project is loaded for this example with the group named as ‘Test’. You can download the project files for the Control Panel below.

 

 

2.2 Codesys

The Codesys library files and example Codesys projects are available in the Examples github repository. The files are located inside the PLC/RealtimeCodesysControl/ folder. The folder structure of the repository is as follows.

RealtimeExamples ├── PLC/RealtimeCodesysControl │ ├── ExampleProject │ ├── LibraryCode │ ├── MELCOPickExample ├── C# └── python

Open Codesys (Codesys v3.5 SP16 is used in this guide)

  1. Install the RTR Controller Library.compiled-library file into codesys

    1. From the menu bar: Tools -> Library Respository -> Install

b. Choose the RTR Controller Library.compiled-library file.

This file is located in the LibraryCode folder.

The library should show up in the installed libraries list when the library is successfully installed

  1. Launch the Example Project (ExampleProject.project)

This file is located in the ExampleProject folder.

The project should be loaded as shown in the image below

 

  1.  

Configure the necessary parameters in RunRobotA and RunRobotB

  • Configure the following parameters for RunRobotA and RunRobotB in the program and the logic diagram

Program

ParameterName

Value

Program

ParameterName

Value

RunRobotA / RunRobotB

ProjectName

RTR_Example_Project_Left_Bot / RTR_Example_Project_Right_Bot

RunRobotA & RunRobotB

RTC_IP

Realtime Controller IP address

(e.g. 192.168.0.10)

RunRobotA & RunRobotB

GroupName

Deconfliction group name

(e.g. ‘Test’)

RunRobotA & RunRobotB

HubOrder

['staging', ‘place_1_1’, ‘place_1_2’, ‘place_1_3’, ‘place_1_4’, ‘place_2_1’, ‘place_2_1’]

RunRobotA & RunRobotB

Work_State_Name (Logic Diagram)

‘no_part'

Check the IP address of the workstation or system running the Realtime Controller appliance using ifconfig in a terminal.

 

  1. Make sure that all the libraries are installed into the system by double clicking on the Library Manager

Unavailable libraries will have a warning mark in their icon and show a message that the library is unavailable when the mouse is hovered over it as shown in the image below

  1. Make sure that RunRobotA and RunRobotB are added to the main task.

The ExampleProject has RunRobotB_1 called in the MainTask. This step can be skipped if the ExampleProject you’re working on already has RunRobotA and RunRobotB under MainTask.

The following video shows how to remove the RunRobotB_1 call and how to add RunRobotA and RunRobotB call to the MainTask.

a. Double-click on MainTask (IEC-Tasks) on the Devices pane.

b. Click on RunRobotB_1 and click on Remove Call.

c. Click Add Call and choose RunRobotA or RunRobotB under Applications > Two Robots Moving To Hubs. Do this for both RunRobotA and RunRobotB.

  1. Start the Codesys Control Win v3x64 soft PLC

a. Click on the Show hidden icons button in the task bar

b. Right click on the Codesys Control Systray icon (the icon of a gray box with 64 in black) and select StartPLC. The 64 on the icon will turn red once the PLC is started.

  1. Scan Network and select the soft PLC

a. Double click on the Device icon in the Devices panel

 

b. Click on Scan Network and select the device

  1. Download project to the soft PLC then run the program

The project can be built by clicking on the Build icon on the toolbar or by pressing F11. Make sure that there are no errors by checking the log message in the status bar.

When logging in for the first time with the active application, you will be prompted whether the application “Sim.<device name>.<application name>” should be created and loaded. Click Yes to confirm.

Pressing the Login button allows you to connect the application to the target system (PLC to simulated device) and allows you to go to online mode which allows you to run the application using the play icon.

10. Toggle InitEnable then EnableOpMode in both RunRobotA and RunRobotB

11. Toggle Run bit in both RunRobotA and RunRobotB. This allows the robot to move by cycling to the hubs in the HubList. Toggling the Run bit off will stop the PLC from sending commands. Toggling the Reset bit at the bottom of the logic diagram would reset the application and move the robots to the ‘home’ hub.

3 How To

3.1 Add a new Ladder Logic Diagram Program POU

This section shows a step-by-step procedure on how to add a new ladder logic diagram program POU

  1. Right click on the Devices pane on the right side of the screen and select Add Object → POU

  2. In the Add POU dialog box, select Program as the POU Type

  3. Make sure that the Implementation Language that is selected is Ladder Logic Diagram (LD)

  4. Edit the name of the POU and click Add.

3.2 Add RTR library blocks in the ladder diagram

The example uses a Program POU with Ladder Logic Diagram (LD) as implementation language. A Program POU with Ladder Logic Diagram consists of the upper and lower pane. The upper pane is where the variables can be defined and can be set to be either in textular or tabular view. The lower pane is where the ladder diagram can be constructed and RTR library blocks can be added.

The user can add the RTR library blocks in the ladder diagram by doing the following:

  1. Right click on the Logic Diagram side of the program and select Empty box with EN/EN0

  2. Click on the block title

  3. Click on the button with ellipsis (…) beside the block title and select the RTR library block you want to add (We will be using TCP_Connect in this example) and click OK. The parameters of the empty box will be updated once you click somewhere outside the box.

  4. Click on each of the input and output parameters and enter the necessary information (variables are defined on the upper pane of the program)

The video attached shows how TCP_Connect is added in the ladder diagram.

4 Devices supported by Codesys

To use actual PLCs, downloaded the PLC program to the actual PLC instead of downloading it to the Codesys SoftPLC as shown in this guide.

The list of PLCs supported by Codesys can be accessed here. Schneider Electric, Beckhoff, WAGO, and Festo among others use Codesys as their standard programming interface.

5 Codesys Realtime Controller Function Blocks

5.1 PLC Program Variables

5.1.1 ConfigurationStrings

Variable Name

Type

Description

Variable Name

Type

Description

Project Name

STRING

Project Name for each robot

RTC_IP

STRING

IP address of the Realtime Controller

GroupName

STRING

Group Name for Init Group

HubOrder

ARRAY[0..n] OF STRING

Array of Hubs

5.1.2 HMI Buttons

Variable Name

Type

Description

Variable Name

Type

Description

Configure

BOOL

Enter Configuration Mode

RUN

BOOL

Moves from config to run mode and runs the robots

xRESET

BOOL

Resets everything and moves robots back to home

Priority

BOOL

If TRUE, robot will not go to staging but will wait in place. If FALSE, robot will go to staging.

5.1.3 Realtime Controller Library Block Enable Bits

Variable Name

Type

Description

Variable Name

Type

Description

Connect

BOOL

Connect to robot

InitEnable

BOOL

send INIT command to RTR controller

EnableOpMode

BOOL

Bit to trigger the BeginOperationMode Command

OffroadToHome

BOOL

Bit to enable the offroadmap move back to home

5.1.4 Realtime Controller Library Blocks

Variable Name

Realtime Controller Library Block

Variable Name

Realtime Controller Library Block

TCP_Connect

TCP_Connect

hc_A

RTR.CAA.HANDLE

InitGroup

InitGroup

MoveToHub

MoveToHub

MoveToStage

MoveToHub

MoveToHome

MoveToHub

BeginOperationMode

BeginOperationMode

OffroadToHub

OffroadToHub

5.2 Realtime Controller Library Block Specifications

The following diagrams show the different Realtime Controller library blocks used in the PLC example program with their corresponding input and output parameters.

5.2.1 TCP_Connect

Input Parameters

Parameter Name

Description

Parameter Name

Description

xConnect

Connects on rising edge; connection remains open while true

xReset

Reset connection

strConfigIPAddress

IP address of appliance as a string (e.g. 192.168.0.4)

uiConfigPort

Port to connect to on the appliance (e.g. 9999)

Output Parameters

Parameter Name

Description

Parameter Name

Description

hConnection

Required socket info for all appliance blocks

strDiagnose

Status of the block

xReady

TRUE when connected

5.2.2 InitGroup

Input Parameters

Parameter Name

Description

Parameter Name

Description

Enable

Message sent on rising edge | Disable to reset block

Deconfliction_Group

String value for deconfliction group

Project_Name

String value for project name

Work_State_Name

String value for roadmap workstate

hConnection

Required socket info for all appliance blocks

Output Parameters

Parameter Name

Description

Parameter Name

Description

Done

True when valid response is received

Output

String output of the response

Result

Output of the error code from the RTR controller

Status

Current status of this block

Error

True when a non-zero value is returned from the appliance

5.2.3 BeginOperationMode

Input Parameters

Parameter Name

Description

Parameter Name

Description

Enable

Message sent on rising edge | Disable to reset block

hConnection

Required socket info for all appliance blocks

Output Parameters

Parameter Name

Description

Parameter Name

Description

Done

True when valid response is received

Output

String output of the response

Result

Output of the error code from the RTR controller

Status

Current status of this block

Error

True when a non-zero value is returned from the appliance

5.2.4 MoveToHub

Input Parameters

Parameter Name

Description

Parameter Name

Description

Enable

Message sent on rising edge | Disable to reset block

Project_Name

String value for project name

Work_State_Name

String value for roadmap workstate

HubName

String value for hub name

Speed

String value for robot speed (1 = full speed, 0.1 = 10% speed)

hConnection

Required socket info for all appliance blocks

Output Parameters

Parameter Name

Description

Parameter Name

Description

Done

True when valid response is received

Output

String output of the response

Result

Output of the error code from the RTR controller

Status

Current status of this block

Error

True when a non-zero value is returned from the appliance

5.2.5 OffroadToHub

Input Parameters

Parameter Name

Description

Parameter Name

Description

Enable

Message sent on rising edge | Disable to reset block

Project_Name

String value for project name

Work_State_Name

String value for roadmap workstate

HubName

String value for hub name

Path_Quality

String value for the desired quality of the executed path (“low”, “medium”, “high”)

Timeout

String value for the amount of time given to plan the path to the hub, in seconds.

hConnection

Required socket info for all appliance blocks

Output Parameters

Parameter Name

Description

Parameter Name

Description

Done

True when valid response is received

Output

String output of the response

Result

Output of the error code from the RTR controller

Status

Current status of this block

Error

True when a non-zero value is returned from the appliance