|
10 | 10 | #include <unistd.h> |
11 | 11 | #include <regex> |
12 | 12 |
|
13 | | -#include "boost/bind.hpp" |
| 13 | +#include "boost/bind/bind.hpp" |
14 | 14 | #include "gflags/gflags.h" |
15 | 15 | #include "glog/logging.h" |
16 | 16 | #include "ut_automata/msg/car_status_msg.hpp" |
17 | 17 | #include "ut_automata/msg/vesc_state_stamped.hpp" |
18 | 18 | #include "amrl_msgs/msg/ackermann_curvature_drive_msg.hpp" |
19 | 19 | #include "nav_msgs/msg/odometry.hpp" |
20 | 20 | #include "geometry_msgs/msg/twist_stamped.hpp" |
| 21 | +#include "tf2_ros/transform_broadcaster.h" |
| 22 | +#include "geometry_msgs/msg/transform_stamped.hpp" |
21 | 23 |
|
22 | 24 | #include "config_reader/config_reader.h" |
23 | 25 | #include "shared/math/math_util.h" |
24 | 26 |
|
| 27 | +using namespace boost::placeholders; |
| 28 | + |
25 | 29 | static const bool kDebug = false; |
26 | 30 | static const float kCommandRate = 20; |
27 | 31 | static const float kCommandInterval = 1.0 / kCommandRate; |
@@ -159,6 +163,7 @@ VescDriver::VescDriver(rclcpp::Node::SharedPtr nh, |
159 | 163 | odom_pub_ = nh_->create_publisher<nav_msgs::msg::Odometry>("odom", rclcpp::QoS(10)); |
160 | 164 | drive_pub_ = nh_->create_publisher<geometry_msgs::msg::TwistStamped>("vesc_drive", rclcpp::QoS(10)); |
161 | 165 | car_status_pub_ = nh_->create_publisher<ut_automata::msg::CarStatusMsg>("car_status", rclcpp::QoS(10)); |
| 166 | + tf_broadcaster_ = std::make_unique<tf2_ros::TransformBroadcaster>(nh_); |
162 | 167 |
|
163 | 168 | ackermann_curvature_sub_ = nh_->create_subscription<amrl_msgs::msg::AckermannCurvatureDriveMsg>( |
164 | 169 | "/ackermann_curvature_drive", rclcpp::QoS(10), |
@@ -470,7 +475,25 @@ void VescDriver::updateOdometry(float rpm, float steering_angle) { |
470 | 475 | position_y = position_y + del_y; |
471 | 476 | orientation = math_util::AngleMod(orientation + del_theta); |
472 | 477 |
|
| 478 | + // Create and publish tf2 transform |
| 479 | + geometry_msgs::msg::TransformStamped transform; |
| 480 | + transform.header.stamp = current_frame_time; |
| 481 | + transform.header.frame_id = "odom"; |
| 482 | + transform.child_frame_id = "base_link"; |
| 483 | + |
| 484 | + transform.transform.translation.x = position_x; |
| 485 | + transform.transform.translation.y = position_y; |
| 486 | + transform.transform.translation.z = 0.0; |
| 487 | + |
| 488 | + transform.transform.rotation.w = cos(0.5 * orientation); |
| 489 | + transform.transform.rotation.x = 0.0; |
| 490 | + transform.transform.rotation.y = 0.0; |
| 491 | + transform.transform.rotation.z = sin(0.5 * orientation); |
| 492 | + |
| 493 | + tf_broadcaster_->sendTransform(transform); |
| 494 | + |
473 | 495 | // Create an odometry message |
| 496 | + odom_msg_.header.stamp = current_frame_time; |
474 | 497 | odom_msg_.twist.twist.linear.x = lin_vel; |
475 | 498 | odom_msg_.twist.twist.angular.z = rot_vel; |
476 | 499 | odom_msg_.pose.pose.position.x = position_x; |
|
0 commit comments