Skip to content

Commit 95830f1

Browse files
authored
simplify twist conversion (#44)
1 parent 1d860b3 commit 95830f1

1 file changed

Lines changed: 31 additions & 11 deletions

File tree

vortex_utils_ros/include/vortex/utils/ros/ros_conversions.hpp

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,27 @@ inline vortex::utils::types::Pose ros_pose_to_pose(
126126
return p;
127127
}
128128

129+
/**
130+
* @brief Converts a ROS geometry_msgs::msg::Pose to an internal Pose type.
131+
* @param pose ROS pose message
132+
* @return vortex::utils::types::PoseEuler Internal pose representation
133+
*/
134+
inline vortex::utils::types::PoseEuler ros_pose_to_pose_euler(
135+
const geometry_msgs::msg::Pose& pose) {
136+
vortex::utils::types::PoseEuler p;
137+
p.x = pose.position.x;
138+
p.y = pose.position.y;
139+
p.z = pose.position.z;
140+
141+
Eigen::Quaterniond q(pose.orientation.w, pose.orientation.x,
142+
pose.orientation.y, pose.orientation.z);
143+
Eigen::Vector3d euler = vortex::utils::math::quat_to_euler(q);
144+
p.roll = euler(0);
145+
p.pitch = euler(1);
146+
p.yaw = euler(2);
147+
return p;
148+
}
149+
129150
/**
130151
* @brief Converts a ROS geometry_msgs::msg::Pose to an internal Pose vector
131152
* type.
@@ -203,21 +224,20 @@ inline std::vector<vortex::utils::types::Pose> ros_to_pose_vec(
203224
}
204225

205226
/**
206-
* @brief Converts a ROS geometry_msgs::msg::TwistWithCovarianceStamped to an
227+
* @brief Converts a ROS geometry_msgs::msg::Twist to an
207228
* internal Twist type.
208-
* @param twist_msg geometry_msgs::msg::TwistWithCovarianceStamped
229+
* @param twist_msg geometry_msgs::msg::Twist
209230
* @return vortex::utils::types::Twist Internal twist representation
210231
*/
211-
inline vortex::utils::types::Twist ros_twist_cov_msg_to_twist(
212-
const geometry_msgs::msg::TwistWithCovarianceStamped& twist_msg) {
213-
const auto& t = twist_msg.twist.twist;
232+
inline vortex::utils::types::Twist ros_twist_to_twist(
233+
const geometry_msgs::msg::Twist& twist_msg) {
214234
return vortex::utils::types::Twist{
215-
.u = t.linear.x,
216-
.v = t.linear.y,
217-
.w = t.linear.z,
218-
.p = t.angular.x,
219-
.q = t.angular.y,
220-
.r = t.angular.z,
235+
.u = twist_msg.linear.x,
236+
.v = twist_msg.linear.y,
237+
.w = twist_msg.linear.z,
238+
.p = twist_msg.angular.x,
239+
.q = twist_msg.angular.y,
240+
.r = twist_msg.angular.z,
221241
};
222242
}
223243

0 commit comments

Comments
 (0)