|
21 | 21 |
|
22 | 22 | #include "lifecycle_msgs/msg/state.hpp" |
23 | 23 | #include "nav2_core/controller_exceptions.hpp" |
24 | | -#include "nav_2d_utils/conversions.hpp" |
25 | | -#include "nav_2d_utils/tf_help.hpp" |
26 | 24 | #include "nav2_ros_common/node_utils.hpp" |
27 | 25 | #include "nav2_util/geometry_utils.hpp" |
28 | 26 | #include "nav2_controller/controller_server.hpp" |
@@ -65,6 +63,9 @@ ControllerServer::ControllerServer(const rclcpp::NodeOptions & options) |
65 | 63 | declare_parameter("publish_zero_velocity", rclcpp::ParameterValue(true)); |
66 | 64 | declare_parameter("costmap_update_timeout", 0.30); // 300ms |
67 | 65 |
|
| 66 | + declare_parameter("odom_topic", rclcpp::ParameterValue("odom")); |
| 67 | + declare_parameter("odom_duration", rclcpp::ParameterValue(0.3)); |
| 68 | + |
68 | 69 | // The costmap node is used in the implementation of the controller |
69 | 70 | costmap_ros_ = std::make_shared<nav2_costmap_2d::Costmap2DROS>( |
70 | 71 | "local_costmap", std::string{get_namespace()}, |
@@ -125,8 +126,11 @@ ControllerServer::on_configure(const rclcpp_lifecycle::State & state) |
125 | 126 | get_parameter("min_theta_velocity_threshold", min_theta_velocity_threshold_); |
126 | 127 | RCLCPP_INFO(get_logger(), "Controller frequency set to %.4fHz", controller_frequency_); |
127 | 128 |
|
128 | | - std::string speed_limit_topic; |
| 129 | + std::string speed_limit_topic, odom_topic; |
129 | 130 | get_parameter("speed_limit_topic", speed_limit_topic); |
| 131 | + get_parameter("odom_topic", odom_topic); |
| 132 | + double odom_duration; |
| 133 | + get_parameter("odom_duration", odom_duration); |
130 | 134 | get_parameter("failure_tolerance", failure_tolerance_); |
131 | 135 | get_parameter("use_realtime_priority", use_realtime_priority_); |
132 | 136 | get_parameter("publish_zero_velocity", publish_zero_velocity_); |
@@ -219,7 +223,7 @@ ControllerServer::on_configure(const rclcpp_lifecycle::State & state) |
219 | 223 | get_logger(), |
220 | 224 | "Controller Server has %s controllers available.", controller_ids_concat_.c_str()); |
221 | 225 |
|
222 | | - odom_sub_ = std::make_unique<nav_2d_utils::OdomSubscriber>(node); |
| 226 | + odom_sub_ = std::make_unique<nav2_util::OdomSmoother>(node, odom_duration, odom_topic); |
223 | 227 | vel_publisher_ = std::make_unique<nav2_util::TwistPublisher>(node, "cmd_vel"); |
224 | 228 |
|
225 | 229 | double costmap_update_timeout_dbl; |
@@ -624,15 +628,15 @@ void ControllerServer::computeAndPublishVelocity() |
624 | 628 | throw nav2_core::FailedToMakeProgress("Failed to make progress"); |
625 | 629 | } |
626 | 630 |
|
627 | | - nav_2d_msgs::msg::Twist2D twist = getThresholdedTwist(odom_sub_->getTwist()); |
| 631 | + geometry_msgs::msg::Twist twist = getThresholdedTwist(odom_sub_->getRawTwist()); |
628 | 632 |
|
629 | 633 | geometry_msgs::msg::TwistStamped cmd_vel_2d; |
630 | 634 |
|
631 | 635 | try { |
632 | 636 | cmd_vel_2d = |
633 | 637 | controllers_[current_controller_]->computeVelocityCommands( |
634 | 638 | pose, |
635 | | - nav_2d_utils::twist2Dto3D(twist), |
| 639 | + twist, |
636 | 640 | goal_checkers_[current_goal_checker_].get()); |
637 | 641 | last_valid_cmd_time_ = now(); |
638 | 642 | cmd_vel_2d.header.frame_id = costmap_ros_->getBaseFrameID(); |
@@ -665,10 +669,9 @@ void ControllerServer::computeAndPublishVelocity() |
665 | 669 |
|
666 | 670 | // Find the closest pose to current pose on global path |
667 | 671 | geometry_msgs::msg::PoseStamped robot_pose_in_path_frame; |
668 | | - rclcpp::Duration tolerance(rclcpp::Duration::from_seconds(costmap_ros_->getTransformTolerance())); |
669 | | - if (!nav_2d_utils::transformPose( |
670 | | - costmap_ros_->getTfBuffer(), current_path_.header.frame_id, pose, |
671 | | - robot_pose_in_path_frame, tolerance)) |
| 672 | + if (!nav2_util::transformPoseInTargetFrame( |
| 673 | + pose, robot_pose_in_path_frame, *costmap_ros_->getTfBuffer(), |
| 674 | + current_path_.header.frame_id, costmap_ros_->getTransformTolerance())) |
672 | 675 | { |
673 | 676 | throw nav2_core::ControllerTFError("Failed to transform robot pose to path frame"); |
674 | 677 | } |
@@ -793,14 +796,12 @@ bool ControllerServer::isGoalReached() |
793 | 796 | return false; |
794 | 797 | } |
795 | 798 |
|
796 | | - nav_2d_msgs::msg::Twist2D twist = getThresholdedTwist(odom_sub_->getTwist()); |
797 | | - geometry_msgs::msg::Twist velocity = nav_2d_utils::twist2Dto3D(twist); |
| 799 | + geometry_msgs::msg::Twist velocity = getThresholdedTwist(odom_sub_->getRawTwist()); |
798 | 800 |
|
799 | 801 | geometry_msgs::msg::PoseStamped transformed_end_pose; |
800 | | - rclcpp::Duration tolerance(rclcpp::Duration::from_seconds(costmap_ros_->getTransformTolerance())); |
801 | | - nav_2d_utils::transformPose( |
802 | | - costmap_ros_->getTfBuffer(), costmap_ros_->getGlobalFrameID(), |
803 | | - end_pose_, transformed_end_pose, tolerance); |
| 802 | + nav2_util::transformPoseInTargetFrame( |
| 803 | + end_pose_, transformed_end_pose, *costmap_ros_->getTfBuffer(), |
| 804 | + costmap_ros_->getGlobalFrameID(), costmap_ros_->getTransformTolerance()); |
804 | 805 |
|
805 | 806 | return goal_checkers_[current_goal_checker_]->isGoalReached( |
806 | 807 | pose.pose, transformed_end_pose.pose, |
|
0 commit comments