API

class aspyrobot.RobotServer(robot, logger=None, update_addr='tcp://*:2000', request_addr='tcp://*:2001')

The RobotServer monitors the state of the robot and processes operation requests from RobotClients. The robot state is broadcast to clients via a Zero-MQ publish/subscribe channel. Operation requests are received via a seperate request/reply channel.

Parameters:
  • robot (Robot) – An instance of the aspyrobot.Robot class.
  • logger – A logging.Logger object.
  • update_addr – An address to create a Zero-MQ socket to broadcast robot state updates to clients.
  • request_addr – An address to create a Zero-MQ socket to receive operation requests from clients.
clear(handle, level)

Clear robot state.

Parameters:level (str) – ‘status’ or ‘all’
operation_update(handle, message='', stage='update', error=None)

Add an operation update to the queue to be sent clients.

Parameters:
  • handle (int) – Operation handle.
  • message (str) – Message to be sent to clients.
  • stage (str) – ‘start’, ‘update’ or ‘end’
  • error (str) – Error message.
refresh()

Query operation to fetch the latest values of the robot state.

This method should be overridden if the server maintains additional state information that needs to be sent to the clients.

setup(*args, **kwds)

Set up the server.

Starts threads and registers for EPICS callbacks.

shutdown()

Request the server shuts down.

Causes the publisher and request threads to exit gracefully.

values_update(update)

Add an robot attribute value update to the queue to be sent clients.

Parameters:update (dict) – robot attributes and their values. For example: {‘safety_gate’: 1, ‘motors_on’: 0}
class aspyrobot.RobotClient(update_addr='tcp://localhost:2000', request_addr='tcp://localhost:2001')

RobotClients are used to remotely monitor the robot and initiate operations.

Parameters:
  • update_addr – Address of the RobotServer update socket.
  • request_addr – Address of the RobotServer operation request socket.
status

int – Robot status flag

current_task

str – Current operation the robot is performing.

task_message

str – Messages about current foreground task

task_progress

str – Current task progress

model

str – Model of the robot

at_home

int – Whether the robot is in the home position

motors_on

int – Whether the robot motors are on

motors_on_command

int – Value of motors on instruction

toolset

codes.Toolset – Current toolset the robot is in

foreground_done

int – Whether the foreground is available

safety_gate

int – Is the safety gate open

closest_point

int – Closest labelled point to the robot’s coordinates

clear(level, callback=None)

Clear the robot state.

Parameters:
  • level (str) – ‘status’ or ‘all’
  • callback – Callback function to receive operation updates
run_operation(operation, callback=None, **parameters)

Run an operation on the RobotServer.

Parameters:
  • operation (str) – Name of the RobotServer method to run.
  • **parameters – keyword arguments to be passed to the operation method.
  • callback – Callback function to receive updates about the operation. Should handle arguments: handle, stage, message, error
Raises:

ValueError – Invalid operation name or parameters.

run_query(query_name, **parameters)

Fetch data from the RobotServer.

Executes a query method on the robot server and returns the data.

Parameters:
  • query_name (str) – Name of the RobotServer method to run.
  • **parameters – keyword arguments to be passed to the query method.
Raises:

RobotError – Error happened on the server.

class aspyrobot.Robot(prefix)

The Robot class creates EPICS connections to the robot IOC. It is intended to be supplied to RobotServer and not used directly.

Parameters:prefix (str) – Prefix of the robot IOC PVs. Eg 'SR03ID01:'.
run_background_task(name, args='')

Execute a background task on the robot.

Background tasks won’t trigger the foreground_done so there is no way to tell when they start or finish.

Parameters:
  • name (str) – Robot controller task to run
  • args (str) – Argument string to supply to the controller
run_task(name, args='')

Execute a foreground task on the robot.

Checks to see that the robot controller foreground thread is free and then executes a task. Blocks until the task is complete.

Parameters:
  • name (str) – Robot controller task to run
  • args (str) – Argument string to supply to the controller
  • timeout (float) – Seconds to wait for the task to being
snapshot()

Capture the robot state to a dictionary.

Stores the value of each attribute PV to a dictionary. For string and char type PVs the string representation is stored.

Returns: dict