#include "rclcpp/rclcpp.hpp"
#include "sensor_msgs/msg/imu.hpp"

using std::placeholders::_1;

class ImuSub : public rclcpp::Node
{
public:
  ImuSub()
  : Node("imu_sub")
  {
    subscription_ = this->create_subscription<sensor_msgs::msg::Imu>(
      "/imu",
      10,
      std::bind(&ImuSub::topic_callback, this, _1));
  }

private:
  void topic_callback(const sensor_msgs::msg::Imu::SharedPtr msg)
  {
    double wz = msg->angular_velocity.z;
    RCLCPP_INFO(this->get_logger(), "IMU angular velocity z = %.3f rad/s", wz);
  }

  rclcpp::Subscription<sensor_msgs::msg::Imu>::SharedPtr subscription_;
};

int main(int argc, char * argv[])
{
  rclcpp::init(argc, argv);
  rclcpp::spin(std::make_shared<ImuSub>());
  rclcpp::shutdown();
  return 0;
}
