ros入门(10)IMU航向锁定

本文介绍了如何在ROS(RobotOperatingSystem)环境中,通过解析IMU传感器数据,计算并实时调整姿态(包括滚转、俯仰和朝向),实现一个简单的控制节点,以便在`imu_node`中驱动`cmd_vel`话题进行导航。
摘要由CSDN通过智能技术生成

#include <ros/ros.h>

#include <sensor_msgs/Imu.h>

#include <tf/tf.h>

#include<geometry_msgs/Twist.h>

ros::Publisher vel_pub;

void IMUCallback(sensor_msgs::Imu msg)

{

if (msg.orientation_covariance[0] < 0 )

{

return;

}

tf::Quaternion quaternion(

msg.orientation.x,

msg.orientation.y,

msg.orientation.z,

msg.orientation.w

);

double roll, pitch,yaw;

tf::Matrix3x3(quaternion).getRPY(roll,pitch,yaw);

roll = roll*180/M_PI;

pitch= pitch*180/M_PI;

yaw = yaw*180/M_PI;

ROS_INFO("滚转= %.0f 俯仰= %.0f 朝向= %.0f",roll,pitch,yaw);

double target_yaw =90;

double diff_angle =target_yaw -yaw;

geometry_msgs::Twist vel_cmd;

vel_cmd.angular.z=diff_angle*0.01;

vel_pub.publish(vel_cmd);

}

int main(int argc, char *argv[])

{

setlocale(LC_ALL,"");

ros::init(argc,argv,"imu_node");

ros::NodeHandle n;

ros::Subscriber imu_sub =n.subscribe("/imu/data",10,IMUCallback);

vel_pub =n.advertise<geometry_msgs::Twist>("/cmd_vel",10);

ros::spin();

return 0;

}

roslaunch wpr_simulation wpb_simple.launch

rosrun imu_pkg imu_node

加了横向速度vel_cmd.linear.x=0.1;

roslaunch wpr_simulation wpb_simple.launch

rosrun imu_pkg imu_node

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值