Python library function documentation

This document contains the documentation of the functions available in the library files included in the Realtime example python code.

 

1 Library Files

The library files which can be referenced to when creating new python scripts for the task manager contain valuable functions that allow the user to communicate with the controller and send commands through the RTR Controller.

1.1 PythonCommander

The Python Commander contains a class that talks with the Realtime Controller over socket communication.

The class is initialized by passing the IP address of the Realtime Controller and a port number as arguments

self.cmdr = PythonCommander(self.ip_addr, 9999)

The functions available in the PythonCommander class are summarized in the table below.

Function Name

Description

Function Name

Description

Reconnect

Deletes all the sockets, creates new ones and reconnects. If an addr and port is specified (both must be), then it'll use the new pair, otherwise it'll use the latest one in cache.

Setup

Caches the group name and project name

GetMode

Sends the GetMode command which queries the Realtime Controller's state

Returns:

  • unsigned int: return code, 0 means success

  • str: string representation of the current Realtime Controller state

BeginOperation

Sends the BeginOperation command which attempts CONFIG -> RUN transition.

Returns:

  • unsigned int: return code, 0 means success

EndOperation

Sends the EndOperation command which attempts RUN -> CONFIG transition.

Returns:

  • unsigned int: return code, 0 means success

ClearFaults

Sends the ClearFaults command which attempts FAULT -> CONFIG transition.

Returns:

  • unsigned int: return code, 0 means success

InitGroup

Sends the InitGroup command with initial workspace. Must call Setup(...) first, or specify both the group_name and project_name args

Parameters:

  • workspace (string): Initial workspace

  • group_name (string) - name of the deconfliction group to terminate

  • project_name (string): name of the robot project this should affect

Returns:

  • unsigned int: return code, 0 means success

TerminateGroup

Sends the TerminateGroup command which unloads a deconfliction group. Must call Setup(...) first, or specify the group_name parameter

Parameters:

  • group_name (string) - name of the deconfliction group to terminate

Returns:

  • unsigned int: return code, 0 means success

WaitForMove

Waits for MoveResult to be received

Parameters:

  • seq_num (uint): sequence number to who's delayed response to wait for

  • timeout (double): timeout in seconds, after which to give up

Returns:

  • uint (or None): return code, 0 means success, None if seq_num isn't found in dict of self._reserved_sockets or timeout

SetInterruptBehavior

Sets the planning parameters. Must call Setup(...) first.

Parameters:

  • replan_attempts (int): Number of times Realtime Controller will attempt to replan if blocked

  • timeout (float): how long to attempt to find a plan

  • project_name (string): name of the robot project this should affect

Returns:

  • unsigned int: return code, 0 means success

MoveToHub

Sends a Move to Hub command. Must call Setup(...) first.

Parameters:

  • workspace (string): workspace to make the move in

  • hub (string): name of hub to move to

  • speed (float): relative speed of motion (between 0 and 1)

  • project_name (string): name of the robot project this should affect

Returns:

  • (uint, uint): (return code - 0 means succes, sequence number - used for WaitForMove)

MoveToPose

Sends a Move to Pose command. Must call Setup(...) first.
Moves robot to specified cartesian coordinate if it's within tolerance to roadmap
Parameters:

  • workspace (string): workspace to make the move in

  • x,y,z,rz,ry,rz (float): desired cartesian coordinate of arm tool

  • tol_x, tol_y, tol_z, tol_rx, tol_ry, tol_rz (float): desired tolerance

  • complete_move (bool): whether or not to go to exact point or closest point on roadmap

  • complete_move_type (int): what kind of interpolation to use for last mile

  • speed (float): relative speed of motion (between 0 and 1)

  • project_name (string): name of the robot project this should affect

Returns:

  • (uint, uint): (return code - 0 means succes, sequence number - used for WaitForMove)

BlindMove

Sends a Blind Move command. Must call Setup(...) first.
Moves robot off roadmap to exact point with static collision checking only

Parameters:

  • workspace (string): workspace to make the move in

  • x,y,z,rz,ry,rz (float): desired cartesian coordinate of arm tool

  • move_type (int): interpolation type of the motion

  • speed (float): relative speed of motion (between 0 and 1)

  • ignore_all_collisions (bool): disables all collision checking when asserted True

  • project_name (string): name of the robot project this should affect

Returns:

  • (uint, uint): (return code - 0 means succes, sequence number - used for WaitForMove)

OffroadToHub

Sends an Offroad to Hub command. Must call Setup(...) first. Moves robot from off roadmap to specified hub with static collision checking only.

Parameters:

  • workspace (string): workspace to make the move in

  • hub (string): name of hub to move to

  • opt (string): Trades between quality of planning ('low', 'medium' or 'high') and time

  • timeout (float): how long to try and find a plan for fallback_to_nominal: true if Offroad is allowed to plan with non-dilated meshes

  • project_name (string): name of the robot project this should affect

Returns:

  • (uint, uint): (return code - 0 means succes, sequence number - used for WaitForMove)

AcquireControl

Sends an Acquire Control command. Must call Setup(...) first. Command to indicate the user is done with an operation that required RTR to release external control of the robot, and the RTR controller should resume control, with the state of the robot in the workspace indicated.

Parameters:

  • workspace (string): workspace of the robot when acquiring control

  • project_name (string): name of the robot project this should affect

Returns:

  • unsigned inst: return code 0 means success

ReleaseControl

Sends a Release Control command. Must call Setup(...) first. Command to indicate the user would like to take temporary control of the robot to get/set IOs, or execute a portion of their robot program that is not suitable for RTR control at this point.

Parameters:

  • workspace (string): workspace of the robot for while control has been release

  • project_name (string): name of the robot project this should affect

Returns:

  • unsigned inst: return code 0 means success

CancelMove

Sends a Cancel Move command. Must call Setup(...) first. This command tells the RTR Motion Planning Server to abort planning and motion for the specified robot, and informs the Motion Planning Server what state the robot is in after the cancellation.

Parameters:

  • workspace (string): desired workspace of the robot following cancellation

  • project_name (string): name of the robot project this should affect

Returns:

  • unsigned inst: return code 0 means success

ChangeWorkspace

Sends a Change Workspace command. Must call Setup(...) first.
Command to change the active workspace from the current one to the one specified

Parameters:

  • workspace (string): desired workspace

  • project_name (string): name of the robot project this should affect

Returns:

  • unsigned inst: return code 0 means success

1.2 CommonOperations

The Common Operations library contains functions that make use of a combination of Python Commander sequence commands for common operations such as start and finish sequence, putting the robots back on the roadmap and attempting fault recovery.

The functions available in the CommonOperations are summarized in the table below.

Function Name

Description

Function Name

Description

startup_sequence

This function calls InitGroup for each project in a group. If all InitGroup calls succeed, the Controller is placed in run mode

Parameters:

  • cmdr (object): Instance of the PythonCommander

  • project_info (nested dict): Nested dict returned by PythonCommanderHelper's get_project_info() method

  • group (string): Group being controlled

Returns:

  • startup_responses: A dictionary with response codes from all InitGroup calls and the BeginOperationMode call. Of the form {'InitGroupResponses':[int],'BeginOperationResponse':int}

shutdown

This function takes the controller out of Operation mode and into Config mode.
Optionally, the group can be unloaded from the control panel

Parameters:

  • cmdr (object): Instance of the PythonCommander

  • group (string): Group being controlled

  • unload (string): If true, the group will be unloaded from the Control Panel

put_on_roadmap

This function attempts to put all robots back on the roadmap.
NOTE: In a multi robot scenario one robot may be blocked by the other. If the blocked robot is moved first, the offroad_to_hub call may fail.

Parameters:

  • cmdr (object): Instance of the PythonCommander

  • project_info (nested dict): Nested dict returned by PythonCommanderHelper's get_project_info() method

  • group (string): Group being controlled

  • hub (string): Hub to move the robots to. Default is 'home'

Returns:

  • move_res (list): a list of the move result value from each offroad to hub call. 0 means success

attempt_fault_recovery

This function clears faults on the controller and puts all robots back on the roadmap. It is assumed that all projects in the group have a hub named 'home' or that all projects have a hub with the same name.

Parameters:

  • cmdr (object): Instance of the PythonCommander

  • project_info (nested dict): Nested dict returned by PythonCommanderHelper's get_project_info() method

  • group (string): Group being controlled

  • hub (string): Hub name to move the all robots to. Default is 'home'

2.3 Python Commander Helper

The Python Commander Helper library communicates with the controler using a REST API.

The functions available in the CommonOperations are summarized in the table below.

Function Name

Description

Function Name

Description

send_get_request

This function sends a get request to the passed URL extension and returns the response in JSON form

Parameters:

  • extension (str): the suffix, after <http://<ip_address>,> of the URL

Returns:

  • resp.json: The REST API's response in JSON form

send_put_request

This function sends a put request to the passed URL extension

Parameters:

  • extension (str): the suffix, after <http://<ip_address>,> of the URL

get_control_panel_state

This function is called with no arguments and returns the current state of the control panel

Returns:

  • state (str): The current state of the control panel

get_group_info

This function is called with no arguments and returns a nested dictionary with all the group names. For each group it also returns if the group is loaded and the projects installed in that group.

Returns:

  • group_info (nested dict): dictionary of the form {'group name': {'loaded': bool, 'projects': [str]}}

get_installed_projects

This function is called with no arguments and returns a list of all projects installed on the Controller

Returns:

  • project_list (list of strings): A list of strings where each string is the name of a project installed on the Controller

put_load_group

This function is passed a group name and attempts to load that group in the Control Panel

Parameters:

  • group_name (str): name of the group to be loaded in the Control Panel

put_unload_group

This function is passed a group name and attempts to unload that group from the Control Panel

Parameters:

  • group_name (str): name of the group to be unloaded from the Control Panel

get_project_info

This function is passed project names and returns relevant information about each project. It is easiest to call get_group_info() first,
and then pass the value of the 'projects' key to get_project_info. Then, you never have to worry about spelling, or passing a project name that isn't in a group.

Parameters:

  • projects (list of strings): A list of strings where each string is a project name in the control panel.

Returns:

  • project_info (nested dict): A nested dictionary containing information about every project passed as an argument. The dictionary structure follows: {'project name': {'workstates': [str], 'hubs': [str]}

put_config_mode

This function puts the controller in config mode

put_teleport_robot

This function teleports a robot to a specified hub. NOTE: the controller must be in config mode to teleport a simulated robot

Parameters:

  • project (str): The name of the project to teleport

  • hub (str): The name of the hub the robot will be teleported to