Getting started with the Python Examples

This guide provides a basic walk-through regarding the files inside the python folder in the RealtimeExamples repository and guides the user on how to use the python script as a task manager to control the robots in the Getting Started Example Project

 

1 Repository

Code examples and documentation can be found on our public GitHub repository RealtimeExamples.

1.1 Python Task Manager Directory

The python scripts and libraries are stored in the python folder under the root directory of RealtimeExamples.

RealtimeExamples ├── python │ ├── lib │ │ ├── PythonCommander.py │ │ ├── PythonCommanderHelper.py │ │ └── CommonOperations.py │ ├── Example.py │ ├── Example_CommonOperations.py │ └── Example_GettingStartedExampleProjectr.py ├── C# └── PLC

2 Example Scripts

This section describes how to use the example python scripts located in the root directory of the RealtimeExamples python folder. The examples serve as a Task Manager so the following instructions are written in the assumption that the project is loaded in the Control Panel before the python scripts are called. The example python scripts can be run by moving to the python folder and running the python scripts in a terminal.

python3 <python script file>

For example, to run the example ‘Example.py’:

python3 Example.py

2.1 Example.py

Example.py attempts to connect to the Realtime Controller assuming that the controller is connected via localhost thus using the IP address 127.0.0.1 and port number 9999 as arguments. This example with work with any deconfliction group and projects.

The script then calls GetMode five times and returns the response of the Realtime Controller if the connection was successful.

The expected response would be something like this:

2.2 Example_CommonOperations.py

Example_CommonOperations.py makes use of the three library files and provides an example of how to initialize robots in the project using a python script. The project file needed for this example is located in the root directory of the python folder. The user has to manually add the deconfliction group in the control panel.

2.2.1 How to Use the Example

  1. Load the CommonOperationsExample.zip project into the Control Panel

2. Create a deconfliction group and name it CommonOperationsExample

3. Add the project to the deconfliction group, load the group and verify the voxel region

4. Open a terminal and run the Example_CommonOperations.py.

Note: Checking the box on the voxel display of CommonOperationsExample will allow for better visualization because the robot voxels will be displayed once InitGroup has been successfully executed.

2.2.2 Example Content and Expected Behavior

This example accepts an IP address as an argument and uses 127.0.0.1 as default IP address.

The example checks if the Robot Controller is in fault mode then proceeds with checking if the group has been named correctly using functions from Python Commander Helper.

It gets the necessary project information and project names and proceeds with the startup sequence and putting the robots into the roadmap.

Finally, it executes an attempt at fault recovery after checking with the user if the user wants to test fault recovery or not.

2.3 Example_GettingStarted.py

Example_GettingStarted.py makes use of the GettingStartedExampleProject and simulates a pick and place task using two robots. The project files needed for this example is located in the root directory of the python folder. The user has to manually add the deconfliction group in the control panel.

2.3.1 How to Use the Example

  1. Follow the procedures on how to setup the GettingStartedExampleProject in the Control Panel here until step three.

2. We will then be using the python script as a Task Manager instead of using the rtr_quick_commander.

python3 Example_GettingStarted.py

Note: As shown in the video below, there are still instances where the startup sequence may fail (either InitGroup, BeginOperationMode or put_on_roadmap fails). In this case, just run the script again until the startup sequence is successfully completed and the robots proceed to the pick and place task.

2.3.2 Example Content and Expected Behavior

The example features a pick and place operation using two robots with the work area limited to the area where the pick positions for both robots are really close to each other. The task flow is as follows:

  1. The startup sequence is executed. The deconfliction group is initialized, the controller is set to operation mode and the robots are moved to the ‘staging’ position.

  2. Threads and task parameters are initialized.

  3. The following sequence is executed in a loop until the robots have finished performing pick and place in eight positions listed in the hub_list.

  4. The function AcquireTargets is called to acquire pick positions. It is implemented in such a way that randomized x and y positions with fixed z positions will be returned as pick positions.

  5. pick_and_place_part is called for each of the robots. Pick and place part involves the following sequence:

    1. the robot moves to the closest roadmap position to the pick position using MoveToPose

    2. the robot moves to the pick position via a BlindMove

    3. the robot moves to the unfinished place position

  6. When pick_and_place_part is executed successfully, the hub_idxs is advanced so that the next part will be placed to the next place position until pick and place to all eight place positions are completed for each robot.

Note: By setting the retreat_idx variable to the robot with less priority to complete the pick and place sequence, the other robot will retract to the ‘staging’ position if motion is not possible because its path is blocked by the other robot.