Message Handlers

mil_tools.pose_to_numpy(pose: Pose) Tuple[float, float][source]

Turns a Pose message into a tuple of position and orientation.

Warning

This method relies on a method (mil_ros_tools.rosmsg_to_numpy()) which will be deprecated in the future. This method will need to be updated.

Parameters

pose (Pose) – The pose message.

Returns

The tuple of position and orientation.

Return type

Tuple[float, float]

mil_tools.twist_to_numpy(twist: Twist)[source]

Turns a Twist message into a tuple of linear and angular speeds.

Warning

This method relies on a method (mil_ros_tools.rosmsg_to_numpy()) which will be deprecated in the future. This method will need to be updated.

Parameters

twist (Twist) – The twist message.

Returns

The tuple of linear and angular speeds.

Return type

Tuple[List[float], List[float]]

mil_tools.posetwist_to_numpy(posetwist: PoseTwist)[source]

Turns a PoseTwist message into pose position, pose orientation, twist linear, and twist angular.

Warning

This method relies on a method (mil_ros_tools.rosmsg_to_numpy()) which will be deprecated in the future. This method will need to be updated.

Parameters

twist (PoseTwist) – The pose + twist message.

Returns

The tuple of linear and angular speeds.

Return type

Tuple[Tuple[np.ndarray, np.ndarray], Tuple[np.ndarray, np.ndarray]]

mil_tools.odometry_to_numpy(odom: Odometry)[source]

Turns a Odometry message into its pose, twist, pose covariance, and twist covariance.

Warning

This method relies on a method (mil_ros_tools.rosmsg_to_numpy()) which will be deprecated in the future. This method will need to be updated.

Parameters

odom (Odometry) – The odometry message.

Returns

Tuple[Tuple[np.ndarray, np.ndarray], Tuple[np.ndarray, np.ndarray],

np.ndarray, np.ndarray]: The tuple of pose, twist, pose covariance, and twist covariance.

mil_tools.wrench_to_numpy(wrench: Wrench)[source]

Turns a Wrench message into its force and torque, represented as numpy arrays.

Warning

This method relies on a method (mil_ros_tools.rosmsg_to_numpy()) which will be deprecated in the future. This method will need to be updated.

Parameters

wrench (Wrench) – The wrench message.

Returns

The tuple of force and torque.

Return type

Tuple[np.ndarray, np.ndarray]

mil_tools.numpy_to_point(vector: ndarray) Point[source]

Turns a List[float] into a Point message.

Parameters

vector (np.ndarray) – The vector to convert

Returns

The constructed message.

Return type

geometry_msgs.Point

mil_tools.numpy_to_point2d(vector: ndarray) Point2D[source]

Turns a np.ndarray into a Point2D message.

Parameters

vector (np.ndarray) – The vector to convert. Should have two values, the first of which represents x and the other y.

Returns

The constructed message.

Return type

Point2D

mil_tools.numpy_to_quaternion(np_quaternion: ndarray) Quaternion[source]

Turns a List[float] into a Quaternion message.

Parameters

np_quaternion (np.ndarray) – The vector to convert. Should have four values, representing x, y, z, and w.

Returns

The constructed message.

Return type

Quaternion

mil_tools.numpy_to_twist(linear_vel: ndarray, angular_vel: ndarray) Twist[source]

Turns two np.ndarray`s into a :class:`Twist message.

Parameters
  • linear_vel (np.ndarray) – The vector to convert. Values should represent the individual components of x, y, and z.

  • angular_vel (np.ndarray) – The vector to convert. Values should represent the individual components of x, y, and z.

Returns

The constructed message.

Return type

Twist

mil_tools.numpy_to_wrench(forcetorque: ndarray)[source]

Turns a np.ndarray into a Wrench message.

Parameters

forcetorque (np.ndarray) – The vector to convert. Values should represent the individual components of force.x, force.y, force.z, torque.x, torque.y, and torque.z.

Returns

The constructed message.

Return type

Wrench

mil_tools.numpy_matrix_to_quaternion(np_matrix: ndarray)[source]

Given a 3x3 rotation matrix, convert to a quaternion, and return the quaternion as a ROS message.

Parameters

np_matrix (np.ndarray) – The 3x3 rotation matrix.

Returns

The constructed message.

Return type

Quaternion

mil_tools.numpy_pair_to_pose(np_translation: ndarray, np_rotation_matrix: ndarray) Pose[source]

Convert a rotation matrix and point pair to a Pose message.

Parameters
  • np_translation (np.ndarray) – An array of 2 or 3 points representing the object’s position.

  • np_rotation_matrix (np.ndarray) – A 3x3 rotation matrix.

Returns

The Pose message with the position and orientation.

Return type

geometry_msgs.Pose

mil_tools.numpy_quat_pair_to_pose(np_translation: ndarray, np_quaternion: ndarray) Pose[source]

Convert a quaternion array and point array pair to a Pose message.

Parameters
  • np_translation (np.ndarray) – An array of 2 or 3 points representing the object’s position.

  • np_quaternion (np.ndarray) – An array with 4 points, representing x, y, z, and w of a quaternion describing the object.

Returns

The Pose message with the position and orientation.

Return type

geometry_msgs.Pose

mil_tools.numpy_to_points(points: List[ndarray]) List[Point][source]

Convert a list of np.ndarray`s into :class:`Point messages.

Parameters

points (List[np.ndarray]) – The points that will be converted to messages.

Returns

The resulting point messages.

Return type

List[Point]

mil_tools.numpy_to_polygon(polygon: List[ndarray]) Polygon[source]

Convert a list of np.ndarray`s (representing :class:`Point`s) into a :class:`Polygon message.

Parameters

points (List[np.ndarray]) – The points that will be added to the polygon.

Returns

The resulting message.

Return type

Polygon

mil_tools.numpy_to_vector3(vec: ndarray) Vector3[source]

Convert a np.ndarray of float`s with length 3 into a :class:`Vector3 message.

Parameters

vec (np.ndarray) – A numpy array with x, y, and z.

Returns

The Vector3 message.

Return type

Vector3

mil_tools.numpy_to_pose2D(pose: ndarray) Pose2D[source]

Convert a np.ndarray of float`s with length 3 into a :class:`Pose2D message.

Parameters

pose (np.ndarray) – A numpy array with x, y, and theta.

Returns

The Pose2D message.

Return type

Pose2D

mil_tools.numpy_to_colorRGBA(color: ndarray) ColorRGBA[source]

Convert a np.ndarray of float`s with length 4 into a :class:`ColorRGBA message.

Parameters

color (np.ndarray) – A numpy array with r, g, b, and a.

Returns

The ColorRGBA message.

Return type

ColorRGBA

mil_tools.numpy_to_pointcloud2(points: ndarray, stamp: Optional[Time] = None, frame_id: Optional[str] = None) PointCloud2[source]

Create a sensor_msgs.PointCloud2 from an array of points.

Parameters
  • points (np.ndarray) – The array of points.

  • stamp (Optional[genpy.rostime.Time]) – An optional timestamp for the message header.

  • frame_id (Optional[str]) – An optional string describing the frame associated with the point cloud.

Returns

A PointCloud2 message with the provided information.

Return type

PointCloud2

mil_tools.make_header(frame='/body', stamp=None) Header[source]

Creates a message header.

Parameters
  • frame (str) – The name of the frame to attach to the header. Defaults to /body.

  • stamp (Optional[rospy.rostime.Time]) – The timestamp to attach to the header of the message. If None, then the current time is used.

Returns

The constructed header.

Return type

Header

mil_tools.make_wrench_stamped(force: List[float], torque: List[float], frame: str = '/body')[source]

Makes a WrenchStamped message.

Parameters
  • force (List[float]) – An array representing the force components. The list should contain force.x, force.y, force.z.

  • torque (List[float]) – An array representing the torque components. The list should contain torque.x, torque.y, and torque.z.

  • frame (str) – The frame to attach to the header. Defaults to /body.

Returns

The constructed message.

Return type

WrenchStamped

mil_tools.make_pose_stamped(position: List[float], orientation: List[float], frame: str = '/body') WrenchStamped[source]

Makes a PoseStamped message.

Parameters
  • position (List[float]) – An array representing the force components. The list should contain position.x, position.y, position.z.

  • orientation (List[float]) – An array representing the torque components. The list should contain orientation.x, orientation.y, orientation.z, and orientation.w.

  • frame (str) – The frame to attach to the header. Defaults to /body.

Returns

The constructed message.

Return type

WrenchStamped