1+ #include < sensor_msgs/msg/imu.hpp>
12#include < vortex/utils/math.hpp>
23#include " geometry_msgs/msg/pose_stamped.hpp"
34#include " geometry_msgs/msg/pose_with_covariance_stamped.hpp"
@@ -19,6 +20,7 @@ class MessagePublisherNode : public rclcpp::Node {
1920 this ->declare_parameter <std::string>(" topics.pose_stamped" );
2021 this ->declare_parameter <std::string>(
2122 " topics.pose_with_covariance_stamped" );
23+ this ->declare_parameter <std::string>(" topics.imu" );
2224 this ->declare_parameter <std::string>(" topics.output" );
2325
2426 auto input_type = this ->get_parameter (" input_type" ).as_string ();
@@ -86,6 +88,14 @@ class MessagePublisherNode : public rclcpp::Node {
8688 this ->get_logger (),
8789 " Euler publisher [pose_with_covariance_stamped]: %s -> %s" ,
8890 topic.c_str (), output_topic.c_str ());
91+ } else if (input_type == " imu" ) {
92+ auto topic = this ->get_parameter (" topics.imu" ).as_string ();
93+ sub_ = this ->create_subscription <sensor_msgs::msg::Imu>(
94+ topic, qos_profile,
95+ std::bind (&MessagePublisherNode::imu_callback, this ,
96+ std::placeholders::_1));
97+ RCLCPP_INFO (this ->get_logger (), " Euler publisher [imu]: %s -> %s" ,
98+ topic.c_str (), output_topic.c_str ());
8999
90100 } else {
91101 RCLCPP_FATAL (
@@ -149,13 +159,20 @@ class MessagePublisherNode : public rclcpp::Node {
149159 publish_rpy (msg->header , euler);
150160 }
151161
162+ void imu_callback (const sensor_msgs::msg::Imu::SharedPtr msg) {
163+ const auto & q = msg->orientation ;
164+ auto euler = convert_quat (q.w , q.x , q.y , q.z );
165+ publish_rpy (msg->header , euler);
166+ }
167+
152168 using SubVariant = std::variant<
153169 rclcpp::Subscription<nav_msgs::msg::Odometry>::SharedPtr,
154170 rclcpp::Subscription<vortex_msgs::msg::Waypoint>::SharedPtr,
155171 rclcpp::Subscription<vortex_msgs::msg::ReferenceFilterQuat>::SharedPtr,
156172 rclcpp::Subscription<geometry_msgs::msg::PoseStamped>::SharedPtr,
157173 rclcpp::Subscription<
158- geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr>;
174+ geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr,
175+ rclcpp::Subscription<sensor_msgs::msg::Imu>::SharedPtr>;
159176
160177 SubVariant sub_;
161178 rclcpp::Publisher<vortex_msgs::msg::RPY >::SharedPtr rpy_pub_;
0 commit comments