ROS and GUI bridge
Translate ROS messages, action results, and service responses into Qt signals.
mtc_gui.ros2_bridge · Source
Operator GUI · Guide · Symbol index
How it is used
The GUI startup creates ROS2Bridge and calls init_ros2(); the main window connects its signals to the panels. A ROS2Spinner services the node in a QThread. Separate daemon workers wait for action and service responses so those waits do not block the GUI. The application entry point calls shutdown() during cleanup.
execute_task() submits a complete task JSON document to beambot_execution and can cause robot motion; dry_run=True requests a plan-only preview. stop_execution() sets a flag and returns immediately. The worker skips submission if it sees that flag before sending, or waits for acceptance and requests cancellation once. After submission, it continues waiting for the server’s terminal result, even if cancellation fails.
Start here
Callable |
Purpose |
|---|---|
Initialize rclpy and the mtc_gui_client node, register subscriptions and clients, then start a Qt spin thread. |
|
Submit a task JSON document to the orchestrator on a background worker. |
|
Request a stop while leaving the worker to wait for the final task result. |
|
Request the /capture_2d Trigger service through the shared background helper. |
|
Stop the spinner, wait up to three seconds for its QThread, destroy the node, and shut down rclpy. |
ROS2Bridge
Own the GUI’s ROS node, subscriptions, clients, and worker coordination. Its signals carry data back to GUI-thread widgets; action and service methods communicate with the running EROBS system.
Inherits from: QObject.
ROS2Bridge.init_ros2()
Initialize rclpy and the mtc_gui_client node, register subscriptions and clients, then start a Qt spin thread.
Lifecycle · Source
init_ros2(self)
Returns: True on complete setup; False when ROS is unavailable or setup raises.
Errors: Catches Exception and emits “ROS2 init failed: …”. Partial setup is not rolled back.
Side effects: Subscribes to /color/image_color, /joint_states, /beambot/current_gripper, /beambot/execution_state, and /beambot/preview_trajectory; the last three use reliable transient-local QoS. Creates beambot_execution action and capture/pause/resume clients, optional Zivid marker client, starts QThread, and emits a log message.
ROS2Bridge.execute_task()
Submit a task JSON document to the orchestrator on a background worker.
Entry point · Source
execute_task(self, config_json: str, dry_run: bool=False)
Parameter |
Meaning |
|---|---|
|
Serialized task script passed verbatim to Goal.full_json; this method does not parse or validate JSON. |
|
Value assigned to Goal.dry_run; True requests orchestrator planning/preview without execution. |
Returns: None; results arrive as action_result_received(status, error_message, completed_steps, total_steps).
Errors: Thread-start errors propagate; worker handles client/server/goal/result failures. There is no guard against concurrent invocations.
Side effects: Resets the shared stop flag and starts a worker that can dispatch robot motion unless dry_run is True.
ROS2Bridge.stop_execution()
Request a stop while leaving the worker to wait for the final task result.
Method · Source
stop_execution(self)
Returns: None.
Errors: No validation of whether an action is active.
Side effects: Sets _stop_execution and logs “Stopping… waiting for task completion”. Does not synchronously cancel a goal or emit a completion result; the worker handles the flag before submission or after acceptance.
ROS2Bridge.trigger_capture()
Request the /capture_2d Trigger service through the shared background helper.
Method · Source
trigger_capture(self)
Returns: None.
Errors: Unavailable clients and service failures are logged by _call_trigger_service.
Side effects: Starts capture service work when a client exists; image arrival remains a separate subscription event.
ROS2Bridge.shutdown()
Stop the spinner, wait up to three seconds for its QThread, destroy the node, and shut down rclpy.
Lifecycle · Source
shutdown(self)
Returns: None.
Errors: Exceptions in rclpy.shutdown are suppressed, including the missing-rclpy case; earlier stop/thread/node errors propagate.
Side effects: Requests thread termination, destroys the ROS node and context. Stored node/client references are not reset.
ROS2Bridge.__init__()
Create a disconnected ROS bridge and prepare optional image conversion.
Lifecycle · Source
__init__(self, parent=None)
Parameter |
Meaning |
|---|---|
|
Optional QObject parent. |
Errors: CvBridge/Qt construction errors propagate.
Side effects: Creates CvBridge only when ROS imports succeeded; no node, subscriptions, or threads are started.
Referenced in source (1)
main— mtc_gui.main
ROS2Bridge.available
Report whether optional ROS imports succeeded and a node has been assigned.
Method · Source
@property
available(self)
Access this as an instance property, without parentheses.
Returns: Boolean; it does not check whether the node/context/server is still live.
Referenced in source (1)
ROS2Bridge.test_server._test— mtc_gui.ros2_bridge
ROS2Bridge.pause_task()
Request beambot/pause using the shared Trigger-service helper.
Method · Source
pause_task(self)
Returns: None.
Errors: Unavailable clients and service failures are logged by the helper.
Side effects: Starts a background pause request; no local execution-state value is changed.
ROS2Bridge.resume_task()
Request beambot/resume using the shared Trigger-service helper.
Method · Source
resume_task(self)
Returns: None.
Errors: Unavailable clients and service failures are logged by the helper.
Side effects: Starts a background resume request; no local execution-state value is changed.
ROS2Bridge.trigger_marker_detection()
Start a background Zivid marker request if the optional marker client exists.
Method · Source
trigger_marker_detection(self)
Returns: None.
Errors: Missing client logs “Marker detection: service not available”; thread-start errors propagate.
Side effects: Starts the nested detection worker; does not update detections immediately.
ROS2Bridge.test_server()
Launch a daemon connectivity check for beambot_execution.
Method · Source
test_server(self)
Returns: None.
Errors: Thread-start errors propagate; the nested check has no exception handler.
Side effects: Starts the nested server-check worker and reports through logs only.
Internal callbacks and helpers
ROS2Bridge._on_image()
Convert a ROS Image to BGR8 pixels and forward it to the GUI.
Callback · Source
_on_image(self, msg)
Parameter |
Meaning |
|---|---|
|
sensor_msgs/Image camera message. |
Returns: None.
Errors: Catches conversion/emission exceptions and prints “Image callback error: …”.
Side effects: Emits image_received with a numpy BGR image.
Referenced in source (1)
ROS2Bridge.init_ros2— mtc_gui.ros2_bridge
ROS2Bridge._on_joint_state()
Select the configured arm joints from a JointState and convert radians to degrees rounded to two decimals.
Callback · Source
_on_joint_state(self, msg)
Parameter |
Meaning |
|---|---|
|
sensor_msgs/JointState with name and position sequences; extra joints are ignored. |
Returns: None.
Errors: Silently emits nothing if any configured arm joint is missing. Other errors are printed as joint-state callback errors.
Side effects: Emits joint_state_received with angles in arm_joint_names() order when all joints exist.
Referenced in source (1)
ROS2Bridge.init_ros2— mtc_gui.ros2_bridge
ROS2Bridge._on_gripper()
Forward the current-gripper topic string to Qt.
Callback · Source
_on_gripper(self, msg)
Parameter |
Meaning |
|---|---|
|
std_msgs/String whose data is the gripper name. |
Returns: None.
Errors: Attribute/signal errors propagate.
Side effects: Emits gripper_changed(msg.data).
Referenced in source (1)
ROS2Bridge.init_ros2— mtc_gui.ros2_bridge
ROS2Bridge._on_execution_state()
Cache and forward the orchestrator’s execution-state string.
Callback · Source
_on_execution_state(self, msg)
Parameter |
Meaning |
|---|---|
|
std_msgs/String state message; contents are not validated. |
Returns: None.
Errors: Attribute/signal errors propagate.
Side effects: Sets execution_state and emits execution_state_changed(msg.data).
Referenced in source (1)
ROS2Bridge.init_ros2— mtc_gui.ros2_bridge
ROS2Bridge._on_preview_trajectory()
Combine preview segments into timed waypoints, preserving each waypoint’s joint names.
Callback · Source
_on_preview_trajectory(self, msg)
Parameter |
Meaning |
|---|---|
|
moveit_msgs/DisplayTrajectory; each joint trajectory supplies joint_names, positions, and time_from_start seconds/nanoseconds. |
Returns: None.
Errors: Skips segments without names or points. Catches other failures and prints a preview callback error.
Side effects: Emits preview_trajectory_received([], waypoints) when nonempty, where each waypoint is (joint_names, positions, cumulative_seconds); logs point count/duration. Segment offsets advance by that segment’s maximum point time.
Referenced in source (1)
ROS2Bridge.init_ros2— mtc_gui.ros2_bridge
ROS2Bridge.execute_task._run()
Submit the goal, handle stop requests, and forward the server’s terminal result.
Internal helper · Source
_run()
Returns: None.
Errors: Missing client/server or a rejected goal emits status 0 and zero counts. A stop handled before submission emits STATUS_CANCELED with zero counts and sends no goal. Server discovery waits up to 10 seconds; acceptance and result polling have no overall timeout. Cancellation-call exceptions are logged while result waiting continues; cancellation responses are not inspected. Other exceptions emit a log and status 0.
Side effects: Sends MTCExecution(full_json, dry_run), retains an accepted goal handle until result or failure, and requests cancellation at most once when stopped. A Stop request during acceptance remains pending until a handle arrives. For submitted goals, forwards the actual server status, error and completed/total counts; completion may still be successful. Clears _current_goal_handle in finally.
Referenced in source (1)
ROS2Bridge.execute_task— mtc_gui.ros2_bridge
ROS2Bridge._on_action_feedback()
Unpack MTCExecution feedback into the five-value Qt signal.
Callback · Source
_on_action_feedback(self, feedback_msg)
Parameter |
Meaning |
|---|---|
|
Action feedback wrapper whose feedback exposes progress_percentage, current_step, current_action, current_gripper, and status_message. |
Returns: None.
Errors: Malformed feedback/signal errors propagate.
Side effects: Emits action_feedback_received(progress, step, action, gripper, message).
Referenced in source (1)
ROS2Bridge.execute_task._run— mtc_gui.ros2_bridge
ROS2Bridge._call_trigger_service()
Start a daemon worker for a named std_srvs/Trigger client, or log that the client is unavailable.
Internal helper · Source
_call_trigger_service(self, client, name)
Parameter |
Meaning |
|---|---|
|
rclpy Trigger service client, or a false value when unavailable. |
|
Human-readable operation label inserted into every log message. |
Returns: None.
Errors: Missing client logs and returns; thread-start errors propagate.
Side effects: Starts the nested service worker; exposes outcomes only through log signals.
Referenced in source (3)
ROS2Bridge.pause_task— mtc_gui.ros2_bridgeROS2Bridge.resume_task— mtc_gui.ros2_bridgeROS2Bridge.trigger_capture— mtc_gui.ros2_bridge
ROS2Bridge._call_trigger_service._call()
Wait for a Trigger service and report its response or timeout through the log signal.
Internal helper · Source
_call()
Returns: None.
Errors: Waits at most two seconds for service readiness and five seconds for a response; timeout does not cancel the request. All Exception failures become log messages.
Side effects: Sends Trigger.Request(), polls at 0.01 seconds, and emits labeled service response/error logs.
Referenced in source (1)
ROS2Bridge._call_trigger_service— mtc_gui.ros2_bridge
ROS2Bridge.trigger_marker_detection._detect()
Capture and detect ArUco IDs 0–49 using the aruco4x4_50 dictionary.
Internal helper · Source
_detect()
Returns: None.
Errors: Waits two seconds for the service and ten seconds for a result; logs readiness, timeout, unsuccessful-response, and Exception failures. Timeout does not cancel the request.
Side effects: Calls CaptureAndDetectMarkers asynchronously; on success emits detection_received(response.detection_result.detected_markers).
Referenced in source (1)
ROS2Bridge.trigger_marker_detection— mtc_gui.ros2_bridge
ROS2Bridge.test_server._test()
Check bridge availability and wait up to three seconds for the action server.
Internal helper · Source
_test()
Returns: None.
Errors: Unavailable bridge logs and returns; action-client exceptions propagate from the worker.
Side effects: Emits ROS-unavailable, testing, running, or server-unavailable log messages; sends no goal.
Referenced in source (1)
ROS2Bridge.test_server— mtc_gui.ros2_bridge
ROS2Spinner
Service ROS callbacks inside the QThread owned by ROS2Bridge. The bridge starts run() through the thread’s started signal and requests loop termination with stop().
Inherits from: QObject.
ROS2Spinner.__init__()
Store the ROS node and initialize the spin-worker running flag.
Lifecycle · Source
__init__(self, node)
Parameter |
Meaning |
|---|---|
|
rclpy node to spin from the worker’s QThread. |
Errors: QObject construction errors propagate.
Side effects: Sets node and _running=True.
Referenced in source (1)
ROS2Bridge.init_ros2— mtc_gui.ros2_bridge
ROS2Spinner.stop()
Request that the next spin-loop condition end the worker.
Lifecycle · Source
stop(self)
Returns: None.
Side effects: Sets _running=False; does not join the thread.
Internal callbacks and helpers
ROS2Spinner.run()
Spin the node in 0.1-second increments until stopped or the ROS context shuts down.
Callback · Source
run(self)
Returns: None.
Errors: Prints a spin exception and exits the loop; does not re-raise it.
Side effects: Services ROS callbacks on the calling worker thread.