|
@@ -17,9 +17,10 @@
|
|
* 注意修改了波特率后,需要将IMU模块短开使用新波特率连接.
|
|
* 注意修改了波特率后,需要将IMU模块短开使用新波特率连接.
|
|
* 20210321:增加可以设置D0,D1,D2,D3共4个IO引脚输出数字高低电平
|
|
* 20210321:增加可以设置D0,D1,D2,D3共4个IO引脚输出数字高低电平
|
|
* 的服务,这里的高电平为3.3V.增加通过服务方式获取yaw数据.
|
|
* 的服务,这里的高电平为3.3V.增加通过服务方式获取yaw数据.
|
|
|
|
+ * 20211003:增加发布pitch和roll数据的话题.
|
|
*****************************************************************/
|
|
*****************************************************************/
|
|
-#include<ros/ros.h>
|
|
|
|
-#include<tf/tf.h>
|
|
|
|
|
|
+#include <ros/ros.h>
|
|
|
|
+#include <tf/tf.h>
|
|
#include <imu_data.h>
|
|
#include <imu_data.h>
|
|
#include <sensor_msgs/Imu.h>
|
|
#include <sensor_msgs/Imu.h>
|
|
#include <std_msgs/Float32.h>
|
|
#include <std_msgs/Float32.h>
|
|
@@ -99,10 +100,11 @@ int main(int argc, char **argv)
|
|
std::string imu_dev;
|
|
std::string imu_dev;
|
|
int baud = 0;
|
|
int baud = 0;
|
|
|
|
|
|
- std::string temp_topic;
|
|
|
|
std::string imu_link_name;
|
|
std::string imu_link_name;
|
|
std::string imu_topic_name;
|
|
std::string imu_topic_name;
|
|
std::string yaw_pub_topic;
|
|
std::string yaw_pub_topic;
|
|
|
|
+ std::string pitch_pub_topic;
|
|
|
|
+ std::string roll_pub_topic;
|
|
std::string yaw_zero_topic;
|
|
std::string yaw_zero_topic;
|
|
std::string yaw_zero_service;
|
|
std::string yaw_zero_service;
|
|
std::string baud_update_service;
|
|
std::string baud_update_service;
|
|
@@ -122,15 +124,16 @@ int main(int argc, char **argv)
|
|
ros::param::get("~imu_link_name", imu_link_name);
|
|
ros::param::get("~imu_link_name", imu_link_name);
|
|
ros::param::get("~pub_topic_hz", pub_topic_hz);
|
|
ros::param::get("~pub_topic_hz", pub_topic_hz);
|
|
ros::param::get("~pub_data_topic", imu_topic_name);
|
|
ros::param::get("~pub_data_topic", imu_topic_name);
|
|
- ros::param::get("~pub_temp_topic", temp_topic);
|
|
|
|
ros::param::get("~yaw_zero_topic", yaw_zero_topic);
|
|
ros::param::get("~yaw_zero_topic", yaw_zero_topic);
|
|
ros::param::get("~yaw_zero_service", yaw_zero_service);
|
|
ros::param::get("~yaw_zero_service", yaw_zero_service);
|
|
ros::param::get("~yaw_pub_topic", yaw_pub_topic);
|
|
ros::param::get("~yaw_pub_topic", yaw_pub_topic);
|
|
|
|
+ ros::param::get("~pitch_pub_topic", pitch_pub_topic);
|
|
|
|
+ ros::param::get("~roll_pub_topic", roll_pub_topic);
|
|
ros::param::get("~baud_update_srv", baud_update_service);
|
|
ros::param::get("~baud_update_srv", baud_update_service);
|
|
ros::param::get("~pin_outHL_srv", pin_outHL_service);
|
|
ros::param::get("~pin_outHL_srv", pin_outHL_service);
|
|
ros::param::get("~yaw_data_srv", yaw_data_service);
|
|
ros::param::get("~yaw_data_srv", yaw_data_service);
|
|
|
|
|
|
- //初始化imu模块串口,根据设备号和波特率进行连接
|
|
|
|
|
|
+ //初始化imu模块串口,根据设备号和波特率建立连接
|
|
int ret = initSerialPort(imu_dev.c_str(), baud);
|
|
int ret = initSerialPort(imu_dev.c_str(), baud);
|
|
if(ret < 0) //通过串口连接IMU模块失败
|
|
if(ret < 0) //通过串口连接IMU模块失败
|
|
{
|
|
{
|
|
@@ -147,13 +150,17 @@ int main(int argc, char **argv)
|
|
ros::ServiceServer getYawSrv = handle.advertiseService(yaw_data_service, getYawDataService);
|
|
ros::ServiceServer getYawSrv = handle.advertiseService(yaw_data_service, getYawDataService);
|
|
|
|
|
|
ros::Subscriber yawZeroSub = handle.subscribe(yaw_zero_topic, 1, yawZeroCallback);
|
|
ros::Subscriber yawZeroSub = handle.subscribe(yaw_zero_topic, 1, yawZeroCallback);
|
|
- ros::Publisher imu_pub = handle.advertise<sensor_msgs::Imu>(imu_topic_name, 1);
|
|
|
|
- ros::Publisher yaw_pub = handle.advertise<std_msgs::Float32>(yaw_pub_topic, 1);
|
|
|
|
|
|
+ ros::Publisher imu_pub = handle.advertise<sensor_msgs::Imu>(imu_topic_name, 2);
|
|
|
|
+ ros::Publisher yaw_pub = handle.advertise<std_msgs::Float32>(yaw_pub_topic, 2);
|
|
|
|
+ ros::Publisher pitch_pub = handle.advertise<std_msgs::Float32>(pitch_pub_topic, 2);
|
|
|
|
+ ros::Publisher roll_pub = handle.advertise<std_msgs::Float32>(roll_pub_topic, 2);
|
|
ros::Rate loop_rate(pub_topic_hz);
|
|
ros::Rate loop_rate(pub_topic_hz);
|
|
|
|
|
|
sensor_msgs::Imu imu_msg;
|
|
sensor_msgs::Imu imu_msg;
|
|
imu_msg.header.frame_id = imu_link_name;
|
|
imu_msg.header.frame_id = imu_link_name;
|
|
std_msgs::Float32 yaw_msg;
|
|
std_msgs::Float32 yaw_msg;
|
|
|
|
+ std_msgs::Float32 pitch_msg;
|
|
|
|
+ std_msgs::Float32 roll_msg;
|
|
while(ros::ok())
|
|
while(ros::ok())
|
|
{
|
|
{
|
|
if(getImuData() < 0)
|
|
if(getImuData() < 0)
|
|
@@ -167,9 +174,12 @@ int main(int argc, char **argv)
|
|
yaw -= 6.2831852;
|
|
yaw -= 6.2831852;
|
|
|
|
|
|
g_yawData = yaw; //获取yaw值,可以通过服务来得到该值
|
|
g_yawData = yaw; //获取yaw值,可以通过服务来得到该值
|
|
- //publish yaw data to topic
|
|
|
|
- yaw_msg.data = yaw;
|
|
|
|
- yaw_pub.publish(yaw_msg);
|
|
|
|
|
|
+ yaw_msg.data = yaw;
|
|
|
|
+ pitch_msg.data = pitch;
|
|
|
|
+ roll_msg.data = roll;
|
|
|
|
+ yaw_pub.publish(yaw_msg); //将yaw值通过话题发布出去
|
|
|
|
+ pitch_pub.publish(pitch_msg); //将pitch值通过话题发布出去
|
|
|
|
+ roll_pub.publish(roll_msg); //将roll值通过话题发布出去
|
|
|
|
|
|
//ROS_INFO("yaw:%f pitch:%f roll:%f",yaw, pitch, roll);
|
|
//ROS_INFO("yaw:%f pitch:%f roll:%f",yaw, pitch, roll);
|
|
imu_msg.orientation.x = getQuat(1);
|
|
imu_msg.orientation.x = getQuat(1);
|