Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panda client for moveit #174

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions moma_utils/src/moma_utils/ros/conversions.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
import numpy as np
import scipy
import geometry_msgs.msg
import rospy
import std_msgs.msg

from moma_utils.spatial import Rotation, Transform
from moma_utils.transform import Rotation, Transform


def from_point_msg(msg):
def from_point_msg(msg: geometry_msgs.msg.Point) -> np.array:
return np.r_[msg.x, msg.y, msg.z]


def from_quat_msg(msg):
def from_quat_msg(msg: geometry_msgs.msg.Quaternion) -> Rotation:
return Rotation.from_quat([msg.x, msg.y, msg.z, msg.w])


def from_pose_msg(msg):
def from_pose_msg(msg: geometry_msgs.msg.Pose) -> Transform:
position = from_point_msg(msg.position)
orientation = from_quat_msg(msg.orientation)
return Transform(orientation, position)


def from_transform_msg(msg):
def from_transform_msg(msg: geometry_msgs.msg.Transform) -> Transform:
translation = from_vector3_msg(msg.translation)
rotation = from_quat_msg(msg.rotation)
return Transform(rotation, translation)


def from_vector3_msg(msg):
def from_vector3_msg(msg: geometry_msgs.msg.Vector3) -> np.array:
return np.r_[msg.x, msg.y, msg.z]


def to_color_msg(color):
def to_color_msg(color: list) -> std_msgs.msg.ColorRGBA:
msg = std_msgs.msg.ColorRGBA()
msg.r = color[0]
msg.g = color[1]
Expand All @@ -39,29 +40,29 @@ def to_color_msg(color):
return msg


def to_point_msg(point):
def to_point_msg(point: np.array) -> geometry_msgs.msg.Point:
msg = geometry_msgs.msg.Point()
msg.x = point[0]
msg.y = point[1]
msg.z = point[2]
return msg


def to_pose_msg(transform):
def to_pose_msg(transform: Transform) -> geometry_msgs.msg.Pose:
msg = geometry_msgs.msg.Pose()
msg.position = to_point_msg(transform.translation)
msg.orientation = to_quat_msg(transform.rotation)
return msg


def to_pose_stamped_msg(transform, frame_id):
def to_pose_stamped_msg(transform : Transform, frame_id: str) -> geometry_msgs.msg.PoseStamped:
msg = geometry_msgs.msg.PoseStamped()
msg.header.frame_id = frame_id
msg.pose = to_pose_msg(transform)
return msg


def to_quat_msg(orientation):
def to_quat_msg(orientation: scipy.spatial.transform.Rotation) -> geometry_msgs.msg.Quaternion:
quat = orientation.as_quat()
msg = geometry_msgs.msg.Quaternion()
msg.x = quat[0]
Expand All @@ -71,22 +72,22 @@ def to_quat_msg(orientation):
return msg


def to_transform_msg(transform):
def to_transform_msg(transform: Transform) -> geometry_msgs.msg.Transform:
msg = geometry_msgs.msg.Transform()
msg.translation = to_vector3_msg(transform.translation)
msg.rotation = to_quat_msg(transform.rotation)
return msg


def to_vector3_msg(vector3):
def to_vector3_msg(vector3: list) -> geometry_msgs.msg.Vector3:
msg = geometry_msgs.msg.Vector3()
msg.x = vector3[0]
msg.y = vector3[1]
msg.z = vector3[2]
return msg


def waypoint_to_pose_msg(waypoint):
def waypoint_to_pose_msg(waypoint: list) -> geometry_msgs.msg.PoseStamped:
"""Converts 2D waypoint to a PoseStamped message.

Arguments:
Expand Down
Loading
Loading