#include "rclcpp/rclcpp.hpp" #include "sensor_msgs/msg/imu.hpp" class IMUSubscriber : public rclcpp::Node { public: IMUSubscriber() : Node("imu_sub") { subscription_ = this->create_subscription( "/imu", 10, std::bind(&IMUSubscriber::imu_callback, this, std::placeholders::_1) ); } private: void imu_callback(const sensor_msgs::msg::Imu::SharedPtr msg) { RCLCPP_INFO(this->get_logger(), "Angular velocity around z: %.3f rad/s", msg->angular_velocity.z); } rclcpp::Subscription::SharedPtr subscription_; }; int main(int argc, char *argv[]) { rclcpp::init(argc, argv); rclcpp::spin(std::make_shared()); rclcpp::shutdown(); return 0; }