|
@@ -19,6 +19,7 @@
|
|
|
#include <sensor_msgs/Imu.h>
|
|
|
#include <std_msgs/Float32.h>
|
|
|
#include <std_msgs/Empty.h>
|
|
|
+#include "serial_imu_hat_6dof/setYawZero.h"
|
|
|
|
|
|
|
|
|
/*********************************************************
|
|
@@ -30,6 +31,19 @@ void yawZeroCallback(const std_msgs::Empty::ConstPtr& msg)
|
|
|
makeYawZero();
|
|
|
}
|
|
|
|
|
|
+/*****************************************************************
|
|
|
+ * Description:使用service方式来进行yaw角度归零,这里是服务的回调
|
|
|
+ * 函数,当有客户端发送yaw归零的服务时,自动调用该函数,如果正确
|
|
|
+ * 执行了yaw归零,则response反馈为0,如果为其他负数则表明yaw归零
|
|
|
+ * 命令执行失败.
|
|
|
+ *****************************************************************/
|
|
|
+bool yawZeroService(serial_imu_hat_6dof::setYawZero::Request &req,
|
|
|
+ serial_imu_hat_6dof::setYawZero::Response &res)
|
|
|
+{
|
|
|
+ res.status = makeYawZero();
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
int main(int argc, char **argv)
|
|
|
{
|
|
|
float yaw, pitch, roll;
|
|
@@ -39,8 +53,9 @@ int main(int argc, char **argv)
|
|
|
std::string link_name;
|
|
|
std::string imu_topic;
|
|
|
std::string temp_topic;
|
|
|
- std::string yaw_topic;
|
|
|
+ std::string yaw_pub_topic;
|
|
|
std::string yaw_zero_topic;
|
|
|
+ std::string yaw_zero_service;
|
|
|
|
|
|
int pub_hz = 0;
|
|
|
float degree2Rad = 3.1415926/180.0;
|
|
@@ -56,7 +71,8 @@ int main(int argc, char **argv)
|
|
|
ros::param::get("~pub_data_topic", imu_topic);
|
|
|
ros::param::get("~pub_temp_topic", temp_topic);
|
|
|
ros::param::get("~yaw_zero_topic", yaw_zero_topic);
|
|
|
- ros::param::get("~yaw_topic", yaw_topic);
|
|
|
+ ros::param::get("~yaw_zero_service", yaw_zero_service);
|
|
|
+ ros::param::get("~yaw_pub_topic", yaw_pub_topic);
|
|
|
ros::param::get("~pub_hz", pub_hz);
|
|
|
|
|
|
//初始化imu模块串口,根据设备号和波特率进行连接
|
|
@@ -69,9 +85,10 @@ int main(int argc, char **argv)
|
|
|
}
|
|
|
ROS_INFO("IMU module is working... ");
|
|
|
|
|
|
+ ros::ServiceServer service = handle.advertiseService(yaw_zero_service, yawZeroService);
|
|
|
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 yaw_pub = handle.advertise<std_msgs::Float32>(yaw_topic, 1);
|
|
|
+ ros::Publisher yaw_pub = handle.advertise<std_msgs::Float32>(yaw_pub_topic, 1);
|
|
|
ros::Rate loop_rate(pub_hz);
|
|
|
|
|
|
sensor_msgs::Imu imu_msg;
|