|
@@ -1,8 +1,8 @@
|
|
/****************************************************************
|
|
/****************************************************************
|
|
* Copyright:2016-2021 www.corvin.cn ROS小课堂
|
|
* Copyright:2016-2021 www.corvin.cn ROS小课堂
|
|
- * Description:使用串口来读取IMU模块的数据,并通过ROS话题
|
|
|
|
- * topic将数据发布出来.芯片中默认读取出来的加速度数据
|
|
|
|
- * 单位是g,需要将其转换为ROS中加速度规定的m/s2才能发布.
|
|
|
|
|
|
+ * Description:使用串口来读取IMU模块的数据,并通过ROS话题topic将
|
|
|
|
+ * 数据发布出来.芯片中默认读取出来的加速度数据单位是g,需要将其
|
|
|
|
+ * 转换为ROS中加速度规定的m/s2才能发布.
|
|
* Author: corvin
|
|
* Author: corvin
|
|
* History:
|
|
* History:
|
|
* 20200403: init this file.
|
|
* 20200403: init this file.
|
|
@@ -15,15 +15,18 @@
|
|
* 增加使用service方式可将yaw角度归零.
|
|
* 增加使用service方式可将yaw角度归零.
|
|
* 20210319:增加使用service方式可以修改imu模块串口通信波特率.
|
|
* 20210319:增加使用service方式可以修改imu模块串口通信波特率.
|
|
* 注意修改了波特率后,需要将IMU模块短开使用新波特率连接.
|
|
* 注意修改了波特率后,需要将IMU模块短开使用新波特率连接.
|
|
|
|
+ * 20210321:增加可以设置D0,D1,D2,D3共4个IO引脚输出数字高低电平
|
|
|
|
+ * 的服务,这里的高电平为3.3V.
|
|
****************************************************************/
|
|
****************************************************************/
|
|
#include <ros/ros.h>
|
|
#include <ros/ros.h>
|
|
#include <tf/tf.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>
|
|
#include <std_msgs/Empty.h>
|
|
#include <std_msgs/Empty.h>
|
|
#include "serial_imu_hat_6dof/setYawZero.h"
|
|
#include "serial_imu_hat_6dof/setYawZero.h"
|
|
#include "serial_imu_hat_6dof/setBaudRate.h"
|
|
#include "serial_imu_hat_6dof/setBaudRate.h"
|
|
|
|
+#include "serial_imu_hat_6dof/setPinOutHL.h"
|
|
|
|
|
|
|
|
|
|
/**********************************************************
|
|
/**********************************************************
|
|
@@ -64,6 +67,19 @@ bool setBaudService(serial_imu_hat_6dof::setBaudRate::Request &req,
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/********************************************************************
|
|
|
|
+ * Description:控制IMU板的D0,D1,D2,D3共4个引脚的输出数字高低电平信号,
|
|
|
|
+ * 这里的服务request一次性控制4个引脚的状态,对应引脚0,则输出低电平,
|
|
|
|
+ * 请求为1,则输出高电平.根据反馈状态status,可以得知控制的结果,如果
|
|
|
|
+ * 反馈0,表明控制成功,负值的话控制失败.这里的高电平为3.3V.
|
|
|
|
+ ********************************************************************/
|
|
|
|
+bool pinOutHLService(serial_imu_hat_6dof::setPinOutHL::Request &req,
|
|
|
|
+ serial_imu_hat_6dof::setPinOutHL::Response &res)
|
|
|
|
+{
|
|
|
|
+ res.status = setIMUPinOutHL(req.D0, req.D1, req.D2, req.D3);
|
|
|
|
+ return true;
|
|
|
|
+}
|
|
|
|
+
|
|
int main(int argc, char **argv)
|
|
int main(int argc, char **argv)
|
|
{
|
|
{
|
|
float yaw, pitch, roll;
|
|
float yaw, pitch, roll;
|
|
@@ -77,6 +93,7 @@ int main(int argc, char **argv)
|
|
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;
|
|
|
|
+ std::string pin_outHL_service;
|
|
|
|
|
|
int pub_hz = 0;
|
|
int pub_hz = 0;
|
|
float degree2Rad = 3.1415926/180.0;
|
|
float degree2Rad = 3.1415926/180.0;
|
|
@@ -94,8 +111,9 @@ int main(int argc, char **argv)
|
|
ros::param::get("~pub_temp_topic", temp_topic);
|
|
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("~baud_update_srv", baud_update_service);
|
|
|
|
|
|
+ ros::param::get("~yaw_pub_topic", yaw_pub_topic);
|
|
|
|
+ ros::param::get("~baud_update_srv", baud_update_service);
|
|
|
|
+ ros::param::get("~pin_outHL_srv", pin_outHL_service);
|
|
|
|
|
|
//初始化imu模块串口,根据设备号和波特率进行连接
|
|
//初始化imu模块串口,根据设备号和波特率进行连接
|
|
int ret = initSerialPort(imu_dev.c_str(), baud);
|
|
int ret = initSerialPort(imu_dev.c_str(), baud);
|
|
@@ -107,9 +125,10 @@ int main(int argc, char **argv)
|
|
}
|
|
}
|
|
ROS_INFO("IMU module is working...");
|
|
ROS_INFO("IMU module is working...");
|
|
|
|
|
|
- //定义两个服务,分别是更新波特率和yaw角度归零
|
|
|
|
|
|
+ //定义三个服务,分别是更新波特率,yaw角度归零和控制引脚输出高低电平
|
|
ros::ServiceServer baudSrv = handle.advertiseService(baud_update_service, setBaudService);
|
|
ros::ServiceServer baudSrv = handle.advertiseService(baud_update_service, setBaudService);
|
|
ros::ServiceServer yawSrv = handle.advertiseService(yaw_zero_service, yawZeroService);
|
|
ros::ServiceServer yawSrv = handle.advertiseService(yaw_zero_service, yawZeroService);
|
|
|
|
+ ros::ServiceServer pinSrv = handle.advertiseService(pin_outHL_service, pinOutHLService);
|
|
|
|
|
|
ros::Subscriber yaw_zero_sub = handle.subscribe(yaw_zero_topic, 1, yawZeroCallback);
|
|
ros::Subscriber yaw_zero_sub = handle.subscribe(yaw_zero_topic, 1, yawZeroCallback);
|
|
ros::Publisher imu_pub = handle.advertise<sensor_msgs::Imu>(imu_topic, 1);
|
|
ros::Publisher imu_pub = handle.advertise<sensor_msgs::Imu>(imu_topic, 1);
|