ur_cb2.receive package

Submodules

ur_cb2.receive.cb2_receive module

A module to receive data from UR CB2 robots.

class ur_cb2.receive.cb2_receive.URReceiver(open_socket, verbose=False)[source]

Bases: object

A class to receive and process data from a UR Robot

The receiving and processing can be run in a separate thread by calling start(). The stop() command must be called before exiting to halt the additional thread. Alternatively, receive(), decode(), and print_parsed_data() can be called in sequence in order to receive, decode, and print data. One should not call receive(), decode(), or any of the print methods, if a separate thread is being used. You should never write to any of the data fields externally, however you can read from them. Python’s atomic read/write architecture should prevent you from getting any half baked results from basic types, for all lists and tuples, you must lock using lock (recommend that you use with lock: paradigm.

clean_data

Double array of length 101 for all of the data returned by the robot

raw_data

String of complete raw data packet

__socket

The socket for communications

clean_packets

The Integer number of packets which have been received cleanly

stub_packets

The Integer number of packets which have been received as stubs

received

The total Integer number of complete data sets which have been received

waiting_data

String to hold incomplete data sets

new_data

Boolean whether new data is available for processing

time

Double of time elapsed since the controller was started

target_joint_positions

6 member Double list of target joint positions

target_joint_velocities

6 member Double list of target joint velocities

target_joint_accelerations

6 member Double list of target joint accelerations

target_joint_currents

6 member Double list of target joint currents

target_joint_moments

6 member Double list of target joint moments as torques

actual_joint_positions

6 member Double list of actual joint positions

actual_joint_velocities

6 member Double list of actual joint velocities

actual_joint_currents

6 member Double list of actual joint currents

tool_accelerometer

3 member Double list of ool x,y and z accelerometer values (software version 1.7)

force_tcp

6 member Double list of generalised forces in the TCP

position

6 member Double list of cartesian coordinates of the tool: (x,y,z,rx,ry,rz), where rx, ry and rz is a rotation vector representation of the tool orientation

tool_speed

6 member Double list of speed of the tool given in cartesian coordinates

digital_inputs

Current state of the digital inputs. NOTE: these are bits encoded as int64_t, e.g. a value of 5 corresponds to bit 0 and bit 2 set high

joint_temperature

6 member Double list of temperature of each joint in degrees celsius

controller_period

Double of controller real time thread execution time

robot_control_mode

Double of robot control mode (see PolyScopeProgramServer on the “How to” page

joint_control_modes

6 member Double list of joint control modes (see PolyScopeProgramServer on the “How to” page) (only from software version 1.8 and on)

run

Boolean on whether to run or not

__receiving_thread

Thread object for running the receiving and parsing loops

verbose

Boolean defining whether or not to print data

lock

A threading lock which is used to protect data from race conditions

_is_stopped

A boolean specifying whether the robot is stopped

__init__(open_socket, verbose=False)[source]

Construct a UR Robot connection given connection parameters

Parameters:
  • open_socket (socket.socket) – The socket to use for communications.
  • verbose (bool) – Whether to print received data in main loop
at_goal(goal, cartesian, error=0.005)[source]

Check whether the robot is at a goal point.

Check whether the differences between the joint or cartesian coordinates are all below some error. This can be used to determine if a move has been completed. It can also be used to create blends by beginning the next move prior to the current one reaching its goal. Note, this will lock the data set and block execution in a number of other functions.

Parameters:
  • goal (6 member tuple or list of floats) – The goal to check against
  • cartesian (bool) – Whether the goal is in cartesian coordinates or not (in which case joint coordinates)
  • error (float) – The error range in which to consider an object at its goal, in meters for cartesian space and radians for axis space.
Returns: Boolean, whether the current position is within the error
range of the goal.
decode()[source]

Decode the data stored in the class’s rawData field.

Only process the data if there is new data available. Unset the self.newData flag upon completion. Note, this will lock the data set and block execution in a number of other functions

double_format_string = '{:+011.7f}'
format = <Struct object>

Format spec for complete data packet

formatLength = <Struct object>

The format spec for the packet length field

is_stopped(error=0.005)[source]

Check whether the robot is stopped.

Check whether the joint velocities are all below some error. Note, this will lock the data set and block execution in a number of other functions

Parameters:error (float) – The error range to define “stopped”

Returns: Boolean, whether the robot is stopped.

loop()[source]

The main loop which receives, decodes, and optionally prints data

name_width = 30

The width to be given to name items when printing out

output_data_item(name, values)[source]

Output item with name and values.

Formatting is specified by self.name_width and self.precision.

Parameters:
  • name (str) – The name of the value
  • values (float, int, tuple of float, list of float) – The list of values
precision = 7

The precision for printing data

print_data()[source]

Print the processed data stored in self.clean_data

Note, this will lock the data set and block execution in a number of other functions

print_parsed_data()[source]

Print the parsed data

Note, this will lock the data set and block execution in a number of other functions

print_raw_data()[source]

Print the raw data which is stored in self.raw_data.

Note, this will lock the data set and block execution in a number of other functions

receive()[source]

Receive data from the UR Robot.

If an entire data set is not received, then store the data in a temporary location (self.waitingData). Once a complete packet is received, place the complete packet into self.rawData and set the newData flag. Note, this will lock the data set and block execution in a number of other functions once a full data set is built.

start()[source]

Spawn a new thread for receiving and run it

stop()[source]

Stops execution of the auxiliary receiving thread

verbose_print(string_input, emphasis='', count=5)[source]

Print input if verbose is set

Parameters:
  • string_input (str) – The input string to be printed.
  • emphasis (str) – Emphasis character to be placed around input.
  • count (int) – Number of emphasis characters to use.

ur_cb2.receive.cb2_receive_example module

A basic script to demonstrate usage of the cb2_receive module.

There are a few lines which are commented out. Uncomment these lines to see a demonstration of the parallel nature of the cb2_receive module.

ur_cb2.receive.cb2_receive_example.main()[source]

ur_cb2.receive.cb2_store_points module

A basic script to store points from a cb2 robot

Basic Usage: Run the script, with commandline args. Press c to capture a point. Press s to save and exit.

ur_cb2.receive.cb2_store_points.main()[source]

Module contents