在ROS中,用C++写一段订阅IMU topic并打印的代码
时间: 2023-03-07 07:16:22 浏览: 120
ROS中文教程v5完整版
#include <ros/ros.h>
#include <sensor_msgs/Imu.h>int main(int argc, char **argv)
{
ros::init(argc, argv, "imu_subscriber");
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe("imu", 1000, &imuCallback);
ros::spin();
return 0;
}void imuCallback(const sensor_msgs::Imu::ConstPtr& msg)
{
ROS_INFO("收到IMU信息:orientation_x = %f, orientation_y = %f, orientation_z = %f, orientation_w = %f",
msg->orientation.x, msg->orientation.y,
msg->orientation.z, msg->orientation.w);
}
阅读全文