写一段gazebo订阅ROS中imu话题并打印出来的C++代码
时间: 2023-03-19 07:20:58 浏览: 139
C++ 打印代码 示 例
5星 · 资源好评率100%
#include <ros/ros.h>
#include <sensor_msgs/Imu.h>void imu_callback(const sensor_msgs::Imu::ConstPtr& msg)
{
ROS_INFO("IMU Data: [Linear Acceleration: x:%f, y:%f, z:%f] [Angular Velocity: x:%f, y:%f, z:%f]",
msg->linear_acceleration.x, msg->linear_acceleration.y, msg->linear_acceleration.z,
msg->angular_velocity.x, msg->angular_velocity.y, msg->angular_velocity.z);
}int main(int argc, char** argv)
{
ros::init(argc, argv, "imu_listener");
ros::NodeHandle nh; ros::Subscriber imu_sub = nh.subscribe("/imu_data", 1000, &imu_callback); ros::spin(); return 0;
}我们可以使用以下C++代码来订阅ROS中imu话题并打印出来:
#include <ros/ros.h>
#include <sensor_msgs/Imu.h>void imu_callback(const sensor_msgs::Imu::ConstPtr& msg)
{
ROS_INFO("IMU Data: [Linear Acceleration: x:%f, y:%f, z:%f] [Angular Velocity: x:%f, y:%f, z:%f]",
msg->linear_acceleration.x, msg->linear_acceleration.y, msg->linear_acceleration.z,
msg->angular_velocity.x, msg->angular_velocity.y, msg->angular_velocity.z);
}int main(int argc, char** argv)
{
ros::init(argc, argv, "imu_listener");
ros::NodeHandle nh; ros::Subscriber imu_sub = nh.subscribe("/imu_data", 1000, &imu_callback); ros::spin(); return 0;
}
阅读全文