33 lines
802 B
C++
33 lines
802 B
C++
#include "rclcpp/rclcpp.hpp"
|
|
#include "sensor_msgs/msg/imu.hpp"
|
|
|
|
class IMUSubscriber : public rclcpp::Node
|
|
{
|
|
public:
|
|
IMUSubscriber() : Node("imu_sub")
|
|
{
|
|
subscription_ = this->create_subscription<sensor_msgs::msg::Imu>(
|
|
"/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<sensor_msgs::msg::Imu>::SharedPtr subscription_;
|
|
};
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
rclcpp::init(argc, argv);
|
|
rclcpp::spin(std::make_shared<IMUSubscriber>());
|
|
rclcpp::shutdown();
|
|
return 0;
|
|
}
|
|
|