yaskawa_ros2

Yaskawa robots ROS 2 interface implementations.

This module defines ROS 2-backed robot wrappers used by RobotBlockSet robot interfaces. It provides communication plumbing, controller integration, state feedback handling, and motion-execution helpers for multiple robot platforms.

class robotblockset.ros2.yaskawa_ros2.hc20(name: str = 'hc20', namespace: str = 'yaskawa', tof_topic: str | None = None)[source]

Bases: robot_ros2, hc20_spec, robot

HC20 collaborative robot class using ROS2 and MotoROS2 interface.

This class provides a ROS2-based interface to a Yaskawa HC20 robot using the MotoROS2 driver. It initializes subscriptions to robot status, service clients to control trajectory execution modes, and sets up a joint trajectory controller interface.

Unlike generic robot interfaces, control strategy changes are not allowed. The robot only supports JointPositionTrajectory control via follow_joint_trajectory action.

Attributes:
  • robot_mode (RobotStatus | None) – Last robot-status message received from MotoROS2.

  • last_robot_status_callback_time (float) – Robot time of the last robot-status callback.

  • start_traj_mode_client (Any) – Client for the start_traj_mode service.

  • stop_traj_mode_client (Any) – Client for the stop_traj_mode service.

  • reset_error_client (Any) – Client for the reset_error service.

  • select_tool_client (Any) – Client for the select_motion_tool service.

Initialize the HC20 ROS 2 interface.

Parameters:
  • name (str, optional) – Name of the ROS2 node (default: "hc20").

  • namespace (str, optional) – Namespace for all robot topics and services. Determines ROS namespace prefix. Default is "hc20".

  • tof_topic (str, optional) – Optional topic used to monitor the TOF breach state.

Notes

This wrapper always uses the MotoROS2 follow_joint_trajectory action and therefore does not support controller strategy switching.

__init__(name: str = 'hc20', namespace: str = 'yaskawa', tof_topic: str | None = None) None[source]

Initialize the HC20 ROS 2 interface.

Parameters:
  • name (str, optional) – Name of the ROS2 node (default: "hc20").

  • namespace (str, optional) – Namespace for all robot topics and services. Determines ROS namespace prefix. Default is "hc20".

  • tof_topic (str, optional) – Optional topic used to monitor the TOF breach state.

Notes

This wrapper always uses the MotoROS2 follow_joint_trajectory action and therefore does not support controller strategy switching.

SetStrategy(new_strategy: str) None[source]

Reject attempts to change the control strategy.

Parameters:

new_strategy (str) – Requested control strategy.

Notes

The HC20 wrapper always uses the MotoROS2 trajectory interface and therefore ignores strategy changes.

GoTo_qtraj(q: ndarray, qdot: ndarray, qddot: ndarray, time: ndarray) int[source]

Command the Yaskawa robot to follow a joint trajectory.

It is intended to control the robot to follow a trajectory specified by joint positions (q), velocities (qdot), and accelerations (qddot) over a specified time (time).

Due to controller resource constraints and implementation details of micro-ROS, MotoROS2 imposes an upper limit on the number of JointTrajectoryPoints in a JointTrajectorys submitted as part of control_msgs/FollowJointTrajectory action goals.

This maximum number of points in a single trajectory is currently 200.

Parameters:
  • q (JointPathType) – Desired joint positions for the trajectory (n, nj), where n is the number of trajectory points.

  • qdot (JointPathType) – Desired joint velocities for the trajectory (n, nj), where n is the number of trajectory points.

  • qddot (JointPathType) – Desired joint accelerations for the trajectory (n, nj). Not used in MotoROS2 controller.

  • time (TimesType) – Time points for the trajectory (n,).

Returns:

Controller status code (0 for success).

Return type:

int

Raises:

ValueError – If control is not implemented in controller.

StartTrajectoryMode(timeout_sec: float = 4.0) int | None[source]

Enable MotoROS2 trajectory mode.

This service engages servo drives and activates the trajectory execution mode required by follow_joint_trajectory actions.

Parameters:

timeout_sec (float, optional) – Maximum time (in seconds) to wait for service availability and response. Default is 4.0.

Returns:

Result code returned by StartTrajMode, or None if the service is unavailable, fails, or times out.

Return type:

int | None

Notes

  • If activation fails, use ResetError() first and inspect the robot_status topic to identify the issue.

  • Extended MotoROS2 error codes may be returned (e.g. 111 → “PFL event”).

  • Motion cannot be executed unless this mode is successfully activated.

StopTrajectoryMode(timeout_sec: float = 2.0) bool | None[source]

Disable trajectory mode on the robot.

Attempts to deactivate trajectory execution mode. Servo drives remain enabled if they were active prior to deactivation.

Parameters:

timeout_sec (float, optional) – Maximum time to wait for service availability and response. Default is 2.0.

Returns:

True if the service call succeeded and the mode was deactivated. False if deactivation failed. None if the service is unavailable, fails, or times out.

Return type:

bool or None

Notes

  • This service fails if motion is actively being executed.

  • To stop an active motion, cancel the running FollowJointTrajectory action goal instead.

  • This is typically used after motion is complete.

  • Use MOTOROS2_error_str() to interpret numeric result codes.

SelectToolFromYAML(tool_name: str | None = None, tool_yaml_file: str | Path | None = 'tools.yaml') None[source]

Load tool data from YAML and select the corresponding MotoROS2 tool.

Parameters:
  • tool_name (str, optional) – Tool name to load from the YAML file.

  • tool_yaml_file (str | Path, optional) – Path to the YAML file containing tool definitions.

Notes

After loading RobotBlockSet tool parameters, the selected tool index is propagated to MotoROS2 with SelectMotionTool().

ResetError(timeout_sec: float = 2.0) int | None[source]

Attempt to clear robot error and alarm conditions.

Calls the MotoROS2 reset_error service to clear recoverable errors. Errors requiring physical operator intervention (e.g., e-stop) cannot be reset using this method.

Parameters:

timeout_sec (float, optional) – Maximum time to wait for service availability and response. Default is 2.0.

Returns:

Returns the result_code from motoros2_interfaces.srv.ResetError. A value of 1 typically indicates success (may depend on configuration). Returns None if the service is unavailable, fails, or times out.

Return type:

int or None

Notes

  • Use this method after a failed trajectory mode activation.

  • Always check current status via the robot_status topic after reset.

  • Some errors may persist until manually acknowledged on the teach pendant.

SelectMotionTool(group: int = 0, tool: int = 0, check_motion: bool = True, timeout_sec: float = 2.0) Tuple[int, bool] | None[source]

Select the active motion tool on the MotoROS2 controller.

This method calls the ROS2 service SelectMotionTool to update the tool definition used during robot motion. Tool changes affect safety systems (FSU/PFL), payload characteristics (mass, CoG, inertia), and tool interference models but do not change kinematic execution of joint-space trajectories.

If check_motion is enabled, the method waits until the robot has come to a complete stop (i.e., no queued motion segments) before invoking the service — recommended behavior based on MotoROS2 specifications.

Parameters:
  • group (int, optional) – motion groups. Default is 0.

  • tool (int, optional) – Tool selection index (0–63). Default is 0.

  • check_motion (bool, optional) – If True, waits until the robot is stationary before selecting a tool. This ensures that new trajectories are executed using the selected tool. Default is True.

  • timeout_sec (float, optional) – Timeout for the service request in seconds. Default is 2.0.

Returns:

Returns (result_code, success) where: - result_code : int — Selection result (see SelectionResultCodes; 0 indicates success). - success : boolTrue if the service invocation succeeded on the MotoROS controller, False otherwise. - Returns None if the service is unavailable, times out, or fails.

Return type:

tuple of (int, bool) or None

Notes

  • Tool selection is applied after currently queued motion completes.

  • Tool does not affect Cartesian execution of joint-space trajectories.

  • Use TF frames to define tool poses for motion planning.

  • Use MOTOROS2_error_str() to decode result_code.

Raises:

ValueError – If group or tool indices are negative or out of range.

isReady() bool[source]

Check whether the robot is ready for motion.

Returns:

True if the robot is connected and ready for operations, otherwise False.

Return type:

bool

isActive() bool[source]

Check whether motion is currently possible.

Returns:

True if the robot is active.

Return type:

bool

inMotion() bool[source]

Check if the robot is in motion.

Returns:

True if the robot is in motion.

Return type:

bool

Check(silent: bool = False) list[str][source]

Check the current robot status and return active error codes.

Parameters:

silent (bool, optional) – If True, suppress status messages while checking the robot state.

Returns:

List of active MotoROS2 error codes converted to strings.

Return type:

list[str]

Notes

When silent is False, the method also reports a detailed multi-line robot status through Message().

HasError() bool[source]

Check whether the robot reports an error state.

Returns:

True if the robot reports an active error.

Return type:

bool

RobotModeStr() str[source]

Convert the current robot-mode code to text.

Returns:

Human-readable description of the robot mode.

Return type:

str

static MOTOROS2_error_str(code: int) str[source]

Convert a MotoROS2 status code to a human-readable description.

Parameters:

code (int) – The error code value.

Returns:

Human-readable description of the status code.

Return type:

str

static MotionResultStr(result: int) str[source]

Convert an extended MotoROS2 trajectory result code to text.

Extended format: -ECCCCC E (first digit) = standard ROS FollowJointTrajectory result code CCCCC (next digits) = MOTOROS2 extended status code

Parameters:

result (int) – The FollowJointTrajectory message result code value.

Returns:

A human-readable result code string.

Return type:

str

Classes

hc20([name, namespace, tof_topic])

HC20 collaborative robot class using ROS2 and MotoROS2 interface.