6 #include "yaml-cpp/yaml.h"
8 #include "geometry_msgs/Vector3.h"
9 #include "nav_msgs/Odometry.h"
10 #include "sensor_msgs/Imu.h"
11 #include "sensor_msgs/JointState.h"
12 #include "std_srvs/Trigger.h"
14 #include "leo_msgs/Imu.h"
15 #include "leo_msgs/WheelOdom.h"
16 #include "leo_msgs/WheelOdomMecanum.h"
17 #include "leo_msgs/WheelStates.h"
19 #include "leo_msgs/SetImuCalibration.h"
21 constexpr
double PI = 3.141592653;
55 "wheel_FL_joint",
"wheel_RL_joint",
"wheel_FR_joint",
"wheel_RR_joint"};
59 0.0001, 0.0001, 0.0, 0.0, 0.0, 0.001};
62 0.000001, 0.000001, 0.00001};
75 pnh.
getParam(
"wheel_odom_twist_covariance_diagonal",
77 pnh.
getParam(
"wheel_odom_mecanum_twist_covariance_diagonal",
79 pnh.
getParam(
"imu_angular_velocity_covariance_diagonal",
81 pnh.
getParam(
"imu_linear_acceleration_covariance_diagonal",
91 sensor_msgs::JointState joint_states;
92 joint_states.header.stamp = msg->stamp;
94 joint_states.position =
95 std::vector<double>(msg->position.begin(), msg->position.end());
96 joint_states.velocity =
97 std::vector<double>(msg->velocity.begin(), msg->velocity.end());
99 std::vector<double>(msg->torque.begin(), msg->torque.end());
105 nav_msgs::Odometry wheel_odom;
108 wheel_odom.header.stamp = msg->stamp;
109 wheel_odom.twist.twist.linear.x = msg->velocity_lin;
110 wheel_odom.twist.twist.angular.z = msg->velocity_ang;
111 wheel_odom.pose.pose.position.x = msg->pose_x;
112 wheel_odom.pose.pose.position.y = msg->pose_y;
113 wheel_odom.pose.pose.orientation.z = std::sin(msg->pose_yaw * 0.5F);
114 wheel_odom.pose.pose.orientation.w = std::cos(msg->pose_yaw * 0.5F);
118 for (
int i = 0; i < 6; i++)
119 wheel_odom.twist.covariance[i * 7] =
126 sensor_msgs::Imu imu;
128 imu.header.stamp = msg->stamp;
132 imu.linear_acceleration.x = msg->accel_x;
133 imu.linear_acceleration.y = msg->accel_y;
134 imu.linear_acceleration.z = msg->accel_z;
138 for (
int i = 0; i < 3; i++) {
139 imu.angular_velocity_covariance[i * 4] =
141 imu.linear_acceleration_covariance[i * 4] =
149 nav_msgs::Odometry wheel_odom;
152 wheel_odom.header.stamp = msg->stamp;
153 wheel_odom.twist.twist.linear.x = msg->velocity_lin_x;
154 wheel_odom.twist.twist.linear.y = msg->velocity_lin_y;
155 wheel_odom.twist.twist.angular.z = msg->velocity_ang;
156 wheel_odom.pose.pose.position.x = msg->pose_x;
157 wheel_odom.pose.pose.position.y = msg->pose_y;
158 wheel_odom.pose.pose.orientation.z = std::sin(msg->pose_yaw * 0.5F);
159 wheel_odom.pose.pose.orientation.w = std::cos(msg->pose_yaw * 0.5F);
164 for (
int i = 0; i < 6; i++)
165 wheel_odom.twist.covariance[i * 7] =
172 nav_msgs::Odometry merged_odom;
200 std::vector<double>* merged_covariance;
207 for (
int i = 0; i < 5; i++)
208 merged_odom.twist.covariance[i * 7] = (*merged_covariance)[i];
209 merged_odom.twist.covariance[35] =
220 if (node[
"gyro_bias_x"])
223 if (node[
"gyro_bias_y"])
226 if (node[
"gyro_bias_z"])
229 }
catch (YAML::BadFile& e) {
230 std::cerr <<
"Calibration file doesn't exist.\n";
231 std::cerr <<
"Creating calibration file with default gyrometer bias.\n";
243 std::string ros_home;
245 if (ros_home_env = std::getenv(
"ROS_HOME")) {
246 ros_home = ros_home_env;
247 }
else if (ros_home_env = std::getenv(
"HOME")) {
248 ros_home = ros_home_env;
252 return ros_home +
"/imu_calibration.yaml";
256 leo_msgs::SetImuCalibrationResponse& res) {
257 ROS_INFO(
"SetImuCalibration request for: [ %f, %f, %f]", req.gyro_bias_x,
258 req.gyro_bias_y, req.gyro_bias_z);
272 std_srvs::TriggerResponse& res) {
285 int main(
int argc,
char** argv) {
286 ros::init(argc, argv,
"firmware_message_converter");
298 const std::string wheel_states_topic =
300 const std::string wheel_odom_topic =
302 const std::string wheel_odom_mecanum_topic =
309 nh.
serviceClient<std_srvs::Trigger>(
"firmware/reset_odometry");
318 "firmware/wheel_states topic no longer has any publishers. "
319 "Shutting down joint_states publisher.");
326 "firmware/wheel_odom topic no longer has any publishers. "
327 "Shutting down wheel_odom_with_covariance and odometry_merged "
339 "firmware/wheel_odom_mecanum topic no longer has any publishers. "
340 "Shutting down wheel_odom_with_covariance and odometry_merged "
351 "firmware/imu topic no longer has any publishers. "
352 "Shutting down imu/data_raw and odometry_merged publishers.");
367 for (
auto& topic : topics) {
370 "Detected firmware/wheel_states topic advertised. "
371 "Advertising joint_states topic.");
373 nh.
advertise<sensor_msgs::JointState>(
"joint_states", 10);
380 "Detected firmware/wheel_odom topic advertised. "
381 "Advertising wheel_odom_with_covariance topic.");
383 nh.
advertise<nav_msgs::Odometry>(
"wheel_odom_with_covariance", 10);
389 topic.name == wheel_odom_mecanum_topic) {
391 "Detected firmware/wheel_odom_mecanum topic advertised. "
392 "Advertising wheel_odom_with_covariance topic.");
394 nh.
advertise<nav_msgs::Odometry>(
"wheel_odom_with_covariance", 10);
401 "Detected firmware/imu topic advertised. "
402 "Advertising imu/data_raw topic.");
410 "Both firmware/imu and (firmware/wheel_odom or "
411 "firmware/wheel_odom_mecanum) topics are advertised. "
412 "Advertising odometry_merged topic.");
414 nh.
advertise<nav_msgs::Odometry>(
"odometry_merged", 10);