RWS (Robot Web Services)

abb_robot_client.rws

exception abb_robot_client.rws.ABBException(message, code)

Exception returned from ABB controller

class abb_robot_client.rws.ControllerState(state: str)

Controller state. See RWS.get_controller_state()

state: str

The controller state

class abb_robot_client.rws.EventLogEntry(seqnum: int, msgtype: int, code: int, tstamp: datetime, args: List[Any], title: str, desc: str, conseqs: str, causes: str, actions: str)

Entry within an event log. See RWS.read_event_log()

actions: str

Actions to correct the event

args: List[Any]

Arguments specified when entry created

causes: str

Potential causes of the event

code: int

The error code of the entry

conseqs: str

Consequences of the event

desc: str

Entry description

msgtype: int

Message type of the entry. 1 for info, 2 for warning, 3 for error

seqnum: int

Sequence number of the entry

title: str

Entry title

tstamp: datetime

Entry timestamp in controller clock

class abb_robot_client.rws.EventLogEntryEvent(seqnum: int)

Event returned by subscription when event log entry created

seqnum: int

seqnum of created event log entry

class abb_robot_client.rws.IpcMessage(data: str, userdef: str, msgtype: str, cmd: str, queue_name: str)

IPC queue message. Also used for RMQ. See RMQ.try_create_ipc_queue()

cmd: str

Message command

data: str

Message data encoded as string

msgtype: str

Type of messag

queue_name: str

Queue containing message

userdef: str

User defined message content encoded as string

class abb_robot_client.rws.JointTarget(robax: array, extax: array)

Joint target in degrees or millimeters

extax: array

Extra axes positions. Six entry array

robax: array

Robot axes positions. Six entry array

class abb_robot_client.rws.OperationalMode(mode: str)

Operational mode. See RWS.get_operation_mode()

mode: str

The operational mode

class abb_robot_client.rws.RAPIDExecutionState(ctrlexecstate: Any, cycle: Any)

Execution state of RAPID tasks on controller. See RWS.get_execution_state()

ctrlexecstate: Any

Current controller execution state

cycle: Any

Current controller cycle state

class abb_robot_client.rws.RWS(base_url='http://127.0.0.1:80', username=None, password=None)

Robot Web Services synchronous client. This class uses ABB Robot Web Services HTTP REST interface to interact with robot controller. Subscriptions can be created to provide streaming information. See the ABB documentation for more information: https://developercenter.robotstudio.com/api/rwsApi/

Parameters:
  • base_url (str) – Base URL of the robot. For Robot Studio instances, this should be http://127.0.0.1:80, the default value. For a real robot, 127.0.0.1 should be replaced with the IP address of the robot controller. The WAN port ethernet must be used, not the maintenance port.

  • username (Optional[str]) – The HTTP username for the robot. Defaults to ‘Default User’

  • password (Optional[str]) – The HTTP password for the robot. Defaults to ‘robotics’

activate_task(task)

Activate a RAPID task

Parameters:

task (str) – The name of the task to activate

deactivate_task(task)

Deactivate a RAPID task

Parameters:

task (str) – The name of the task to activate

Return type:

None

delete_file(filename)

Delete a file on the controller

Parameters:

filename (str) – The filename to delete

get_analog_io(signal, network='Local', unit='DRV_1')

Get the value of an analog IO signal.

Parameters:
  • signal (str) – The name of the signal

  • network (str) – The network the signal is on. The default Local will work for most signals.

  • unit (str) – The drive unit of the signal. The default DRV_1 will work for most signals.

Return type:

float

Returns:

The value of the signal

get_controller_state()

Get the controller state. The controller state can have the following values:

init, motoroff, motoron, guardstop, emergencystop, emergencystopreset, sysfail

RAPID can only be executed and the robot can only be moved in the motoron state.

Return type:

str

Returns:

The controller state

get_digital_io(signal, network='Local', unit='DRV_1')

Get the value of a digital IO signal.

Parameters:
  • signal (str) – The name of the signal

  • network (str) – The network the signal is on. The default Local will work for most signals.

  • unit (str) – The drive unit of the signal. The default DRV_1 will work for most signals.

Return type:

int

Returns:

The value of the signal. Typically 1 for ON and 0 for OFF

get_execution_state()

Get the RAPID execution state

Return type:

RAPIDExecutionState

Returns:

The RAPID execution state

get_ipc_queue(queue_name)

Get the IPC queue

Parameters:

queue_name (str) – The name of the queue

Return type:

Any

get_jointtarget(mechunit='ROB_1')

Get the current jointtarget for specified mechunit

Parameters:

mechunit – The mechanical unit to read

Return type:

JointTarget

Returns:

The current jointtarget

get_operation_mode()

Get the controller operational mode. The controller operational mode can have the following values:

INIT, AUTO_CH, MANF_CH, MANR, MANF, AUTO, UNDEF

Typical values returned by the controller are AUTO for auto mode, and MANR for manual reduced-speed mode.

Return type:

str

Returns:

The controller operational mode.

get_ramdisk_path()

Get the path of the RAMDISK variable on the controller

Return type:

str

Returns:

The RAMDISK path

get_rapid_variable(var, task='T_ROB1')

Get value of a RAPID pers variable

Parameters:
  • var (str) – The pers variable name

  • task (str) – The task containing the pers variable

Return type:

str

Returns:

The pers variable encoded as a string

get_rapid_variable_jointtarget(var, task='T_ROB1')

Get a RAPID pers variable and convert to JointTarget

Parameters:
  • var – The pers variable name

  • task (str) – The task containing the pers variable

Return type:

JointTarget

Returns:

The pers variable encoded as a JointTarget

get_rapid_variable_jointtarget_array(var, task='T_ROB1')

Get a RAPID pers variable and convert to JointTarget list

Parameters:
  • var (str) – The pers variable name

  • task (str) – The task containing the pers variable

Return type:

List[JointTarget]

Returns:

The pers variable encoded as a list of JointTarget

get_rapid_variable_num(var, task='T_ROB1')

Get a RAPID pers variable and convert to float

Parameters:
  • var (str) – The pers variable name

  • task (str) – The task containing the pers variable

Return type:

float

Returns:

The pers variable encoded as a float

get_rapid_variable_num_array(var, task='T_ROB1')

Get a RAPID pers variable float array

Parameters:
  • var – The pers variable name

  • task (str) – The task containing the pers variable

Return type:

ndarray

Returns:

The variable value as an array

get_rapid_variables(task='T_ROB1')

Get a list of the persistent variables in a task

Parameters:

task (str) – The RAPID task to query

Return type:

List[str]

Returns:

List of persistent variables in task

get_robtarget(mechunit='ROB_1', tool='tool0', wobj='wobj0', coordinate='Base')

Get the current robtarget (cartesian pose) for the specified mechunit

Parameters:
  • mechunit – The mechanical unit to read

  • tool – The tool to use to compute robtarget

  • wobj – The wobj to use to compute robtarget

  • coordinate – The coordinate system to use to compute robtarget. Can be Base, World, Tool, or Wobj

Return type:

RobTarget

Returns:

The current robtarget

get_speedratio()

Get the current speed ratio

Return type:

float

Returns:

The current speed ratio between 0% - 100%

get_tasks()

Get controller tasks and task state

Return type:

List[TaskState]

Returns:

The tasks and task state

list_files(path)

List files at a path on a controller

Parameters:

path (str) – The path to list

Return type:

List[str]

Returns:

The filenames in the path

poll_rmmp()

Poll rmmp to maintain remote mastering. Call periodically after rmmp enabled using request_rmmp()

read_event_log(elog=0)

Read the controller event log

Parameters:

elog (int) – The event log id to read

Return type:

List[EventLogEntry]

Returns:

The event log entries

read_file(filename)

Read a file off the controller

Parameters:

filename (str) – The filename to read

Return type:

bytes

Returns:

The file bytes

read_ipc_message(queue_name, timeout=0)

Read IPC message. IPC is used to communicate with RMQ in controller tasks. Create IPC using try_create_ipc_queue().

Parameters:
  • queue_name (str) – The name of the queue created using try_create_ipc_queue()

  • timeout (float) – The timeout to receive a message in seconds

Return type:

List[IpcMessage]

Returns:

Messages received from IPC queue

request_rmmp(timeout=5)

Request Remote Mastering. Required to alter pers variables in manual control mode. The teach pendant will prompt to enable remote mastering, and the user must confirm. Once remote mastering is enabled, poll_rmmp() must be executed periodically to maintain rmmp.

Parameters:

timeout (float) – The request timeout in seconds

resetpp()

Reset RAPID program pointer to main in normal tasks

send_ipc_message(target_queue, data, queue_name, cmd=111, userdef=1, msgtype=1)

Send an IPC message to the specified queue

Parameters:
  • target_queue (str) – The target IPC queue. Can also be the name of a task to send to RMQ of controller task.

  • data (str) – The data to send to the controller. Encoding must match the expected type of RMQ

  • queue_name (str) – The queue to send message from. Must be created with try_create_ipc_queue()

  • cmd (int) – The cmd entry in the message

  • userdef (int) – User defined value

  • msgtype (int) – The type of message. Must be 0 or 1

set_analog_io(signal, value, network='Local', unit='DRV_1')

Set the value of an analog IO signal.

Parameters:
  • value (Union[int, float]) – The value of the signal

  • signal (str) – The name of the signal

  • network (str) – The network the signal is on. The default Local will work for most signals.

  • unit (str) – The drive unit of the signal. The default DRV_1 will work for most signals.

set_digital_io(signal, value, network='Local', unit='DRV_1')

Set the value of an digital IO signal.

Parameters:
  • value (Union[bool, int]) – The value of the signal. Bool or bool convertible input

  • signal (str) – The name of the signal

  • network (str) – The network the signal is on. The default Local will work for most signals.

  • unit (str) – The drive unit of the signal. The default DRV_1 will work for most signals.

set_rapid_variable(var, value, task='T_ROB1')

Set value of a RAPID pers variable

Parameters:
  • var (str) – The pers variable name

  • value (str) – The new variable value encoded as a string

  • task (str) – The task containing the pers variable

set_rapid_variable_jointtarget(var, value, task='T_ROB1')

Set a RAPID pers variable from a JointTarget

Parameters:
  • var (str) – The pers variable name

  • value (JointTarget) – The new variable JointTarget value

  • task (str) – The task containing the pers variable

set_rapid_variable_jointtarget_array(var, value, task='T_ROB1')

Set a RAPID pers variable from a JointTarget list

Parameters:
  • var (str) – The pers variable name

  • value (List[JointTarget]) – The new variable JointTarget value

  • task (str) – The task containing the pers variable

set_rapid_variable_num(var, val, task='T_ROB1')

Set a RAPID pers variable from a float

Parameters:
  • var (str) – The pers variable name

  • value – The new variable float value

  • task (str) – The task containing the pers variable

set_rapid_variable_num_array(var, val, task='T_ROB1')

Set a RAPID pers variable from a float list or array

Parameters:
  • var (str) – The pers variable name

  • value – The new variable float array value

  • task (str) – The task containing the pers variable

set_speedratio(speedratio)

Set the current speed ratio

Parameters:

speedratio (float) – The new speed ratio between 0% - 100%

start(cycle='asis', tasks=['T_ROB1'])

Start one or more RAPID tasks

Parameters:
  • cycle (Optional[str]) – The cycle mode of the robot. Can be asis, once, or forever.

  • tasks (Optional[List[str]]) – One or more tasks to start.

stop()

Stop RAPID execution of normal tasks

subscribe(resources, handler)

Create subscription that will receive real-time updates from the controller. handler will be called with the new values. RWS subscriptions are relatively slow, with delays in the hundreds of milliseconds. Use EGM for faster real-time updates.

A list of SubscriptionResourceRequest are used to specify what resources to subscribe. The following are supported:

  • Controller State: SubscriptionResourceRequest(SubscriptionResourceType.ControllerState, rws.SubscriptionResourcePriority.Medium)

  • Operational Mode: SubscriptionResourceRequest(SubscriptionResourceType.OperationalMode, rws.SubscriptionResourcePriority.Medium)

  • Execution State: SubscriptionResourceRequest(SubscriptionResourceType.ExecutionState, rws.SubscriptionResourcePriority.Medium)

  • Variable: SubscriptionResourceRequest(SubscriptionResourceType.PersVar, rws.SubscriptionResourcePriority.High, “variable_name”)

  • IPC Queue: SubscriptionResourceRequest(SubscriptionResourceType.IpcQueue, rws.SubscriptionResourcePriority.Medium, “queue_name”)`

  • Event Log: SubscriptionResourceRequest(SubscriptionResourceType.Elog, rws.SubscriptionResourcePriority.Medium)

  • Signal: SubscriptionResourceRequest(SubscriptionResourceType.Signal, rws.SubscriptionResourcePriority.High, “signal_name”)

The handler parameter will be called on each event from the controller. The passed parameter will have the following type:

The returned RWSSubscription creates a persistent websocket connection to the controller. It must be closed with the close() method when no longer in use.

Parameters:
  • resources (List[SubscriptionResourceRequest]) – Controller resources to subscribe

  • handler (Callable[[Any], None]) – Callable to call on resource events

Return type:

RWSSubscription

Returns:

Active subscription

try_create_ipc_queue(queue_name, queue_size=4440, max_msg_size=444)

Try creating an IPC queue. Returns True if the queue is created, False if queue already exists. Raises exception for all other errors.

Parameters:
  • queue_name (str) – The name of the new IPC queue

  • queue_size (int) – The buffer size of the queue

  • max_msg_size (int) – The maximum message size of the queue

Return type:

bool

Returns:

True if queue created, False if queue already exists

upload_file(filename, contents)

Upload a file to the controller

Parameters:
  • filename (str) – The filename to write

  • contents (bytes) – The file content bytes

class abb_robot_client.rws.RWSSubscription(ws_url, header, handler)

Subscription returned from RWS.subscribe()

close()

Close the subscription

class abb_robot_client.rws.RobTarget(trans: array, rot: array, robconf: array, extax: array)

Robtarget

extax: array

Extra axes positions. Six entry array

robconf: array

4 entry configuration of robot. See confdata datatype in the ABB RAPID manuals for explanation

rot: array

Rotation in quaternion units [w,x,y,z]

trans: array

Translation in millimeters. Three entry array

class abb_robot_client.rws.Signal(name: str, lvalue: str)

Signal state

lvalue: str

Logical value of the signal

name: str

Name of the signal

class abb_robot_client.rws.SubscriptionClosed(code, msg)
code: int

Alias for field number 0

msg: str

Alias for field number 1

exception abb_robot_client.rws.SubscriptionException(message)
class abb_robot_client.rws.SubscriptionResourcePriority(value)

Priority of subscribed resource. Only Signal and PersVar support high priority. See RWS.subscribe()

class abb_robot_client.rws.SubscriptionResourceRequest(resource_type: SubscriptionResourceType, priority: SubscriptionResourcePriority, param: Any | None = None)

Specify resource to subscribe. See RWS.subscribe()

param: Any

Parameter for subscription request

priority: SubscriptionResourcePriority

Subscription priority

resource_type: SubscriptionResourceType

Type of resource to subscribe

class abb_robot_client.rws.SubscriptionResourceType(value)

Enum to select resource to subscribe. See RWS.subscribe()

ControllerState = 1

Subscribe to controller state resource

Elog = 6

Subscribe to Event Log resource

ExecutionState = 3

Subscribe to executio state resource

IpcQueue = 5

Subscribe to IPC queue resource

OperationalMode = 2

Subsribe to operational mode resource

PersVar = 4

Subscribe to RAPID pers variable resource

Signal = 7

Subscribe to signal resource

class abb_robot_client.rws.TaskState(name: str, type_: str, taskstate: str, excstate: str, active: bool, motiontask: bool)

Current state of task running on controller. See RWS.get_tasks()

active: bool

True if the task is currently active

excstate: str

The current execution state

motiontask: bool

True if the task is a motion task

name: str

Name of the controller task

taskstate: str

The curret task state

type_: str

The type of the task

class abb_robot_client.rws.VariableValue(name: str, value: str, task: str | None = None)

RAPID variable value

name: str

The name of the RAPId variable

task: str

The task containing the variable

value: str

The variable value encoded as string