Work in progress: this documentation is still being written and reviewed. Check details against the source code.

Blocking Bluesky action device

Submit orchestrator tasks through a blocking Bluesky/Ophyd device.

bluesky_ros.mtc_ophyd_device · Source

Clients and integrations · Guide · Symbol index

How it is used

Use MTCExecutionDevice.set() from a Bluesky plan to submit a task file or JSON string. Initialize ROS before constructing the device. The call processes ROS callbacks until completion and then returns its Ophyd status, so wait=False in the RunEngine does not make this wrapper asynchronous.

ActionStatus connects failed Ophyd status handling to cancellation. The wrapper currently labels canceled/aborted ROS statuses incorrectly; both still produce failed Ophyd statuses.

Start here

Callable

Purpose

MTCExecutionDevice.set

Submit a task and process ROS callbacks until its Ophyd status is done, then return the status. The call blocks; it ignores the result of its ten-second server-discovery wait.

MTCExecutionDevice.construct_goal_message

Populate full_json from a file only when the input is a string ending exactly in .json; otherwise assign the input directly as JSON text.

MTCExecutionDevice.cancel_goal

Request cancellation of the retained goal and spin until its cancel future finishes or five seconds elapse.

MTCExecutionDevice

A ROS node implementing the Bluesky movable interface by blocking until an MTCExecution goal finishes.

Inherits from: Node, Movable.

MTCExecutionDevice.set()

Submit a task and process ROS callbacks until its Ophyd status is done, then return the status. The call blocks; it ignores the result of its ten-second server-discovery wait.

Method · Source

set(self, json_path_or_string)

Parameter

Meaning

json_path_or_string

Task-file path ending in .json or JSON text accepted by construct_goal_message.

Returns: The ActionStatus after completion/failure; this call blocks and has no execution timeout of its own.

Errors: Input/send/callback errors are not caught here; unavailable server can leave a goal/status pending. Repeated calls overwrite shared current status/goal fields.

Side effects: Reads optional file, submits robot execution and processes ROS callbacks synchronously.

MTCExecutionDevice.construct_goal_message()

Populate full_json from a file only when the input is a string ending exactly in .json; otherwise assign the input directly as JSON text.

Method · Source

construct_goal_message(self, json_path_or_string)

Parameter

Meaning

json_path_or_string

String file path with .json suffix or raw JSON string. Path objects are not recognized as paths; no JSON syntax/schema check occurs.

Returns: MTCExecution.Goal with full_json populated.

Errors: File errors and ROS message type-assignment errors propagate.

Side effects: May read a task file; does not submit it.

Referenced in source (1)

MTCExecutionDevice.cancel_goal()

Request cancellation of the retained goal and spin until its cancel future finishes or five seconds elapse.

Method · Source

cancel_goal(self)

Returns: None; no action if _goal_handle is None.

Errors: Future/spin errors propagate; cancellation acceptance/return code is not inspected, and handle may already be complete.

Side effects: Sends an action cancel request and processes ROS callbacks.

MTCExecutionDevice.__init__()

Initialize a ROS node with Bluesky name/parent attributes, resolve the MTCExecution action type and create a beambot_execution client.

Lifecycle · Source

__init__(self, name='mtc_executor', **kwargs)

Parameter

Meaning

name

ROS node name and Bluesky device name.

kwargs

Additional Node constructor keyword arguments, not Ophyd device arguments.

Returns: None; active goal/status/futures start None.

Errors: ROS/type-resolution/client setup errors propagate; does not call rclpy.init().

Side effects: Creates ROS node/client.

Internal callbacks and helpers

MTCExecutionDevice._feedback_callback()

Log the current step/action, one-decimal progress percentage and status message from MTC feedback.

Callback · Source

_feedback_callback(self, feedback_msg)

Parameter

Meaning

feedback_msg

MTCExecution feedback wrapper with feedback.current_step/current_action/progress_percentage/status_message.

Returns: None.

Errors: Malformed feedback/logging errors propagate.

Side effects: Writes an INFO ROS log.

Referenced in source (1)

MTCExecutionDevice._goal_response_callback()

Extract the goal handle; mark the current status failed when rejected, or retain the accepted handle and attach the final-result callback.

Callback · Source

_goal_response_callback(self, future)

Parameter

Meaning

future

Completed send_goal_async future returning the goal handle.

Returns: None.

Errors: Future/None-handle errors propagate; rejection uses Exception(“Goal rejected”) on the status.

Side effects: Mutates goal/status/future state and registers the result callback; failure may trigger cancellation through ActionStatus.

Referenced in source (1)

MTCExecutionDevice._result_callback()

Finish the current status for raw action status 4. For 5 use result.error_message as the exception; for 6 use Canceled; all others use Unknown status.

Callback · Source

_result_callback(self, future)

Parameter

Meaning

future

Completed get_result_async future containing status and MTCExecution result.

Returns: None; status becomes finished or exceptional.

Errors: Future/message errors propagate. Source labels 5 as aborted and 6 as canceled; standard ROS uses 5 canceled and 6 aborted, so error labeling is reversed.

Side effects: Updates Ophyd status/logs and may trigger the cancellation failure hook; retained goal handle is not cleared.

Referenced in source (1)

ActionStatus

Track an execution result for Ophyd and ask the associated device to cancel when the status fails.

Inherits from: DeviceStatus.

ActionStatus.__init__()

Initialize an Ophyd DeviceStatus tied to the ROS action device.

Lifecycle · Source

__init__(self, device, **kwargs)

Parameter

Meaning

device

Device whose cancel_goal() is called by the failure hook.

kwargs

Keyword arguments forwarded to DeviceStatus, such as timeout/settle-time options supported by installed Ophyd.

Errors: Base DeviceStatus validation/construction errors propagate.

Side effects: Creates status bookkeeping; no ROS goal is sent.

Referenced in source (1)

ActionStatus._handle_failure()

Request cancellation through the attached device when Ophyd marks the status failed.

Extension hook · Source

_handle_failure(self)

Returns: None; cancel_goal return value is discarded.

Errors: Cancellation errors propagate; no local catch.

Side effects: May send ROS action cancellation and block spinning for up to five seconds.