Skip to content

Commit 1d026e9

Browse files
bektaskemalKemal BektasSteveMacenski
authored andcommitted
feat(nav2_rotation_shim_controller): add use_path_orientations (#5034)
* feat(nav2_rotation_shim_controller): add use_path_orientations Signed-off-by: Kemal Bektas <[email protected]> * Update nav2_rotation_shim_controller/src/nav2_rotation_shim_controller.cpp Signed-off-by: Steve Macenski <[email protected]> --------- Signed-off-by: Kemal Bektas <[email protected]> Signed-off-by: Steve Macenski <[email protected]> Co-authored-by: Kemal Bektas <[email protected]> Co-authored-by: Steve Macenski <[email protected]>
1 parent 2dde228 commit 1d026e9

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

nav2_rotation_shim_controller/README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ See its [Configuration Guide Page](https://docs.nav2.org/configuration/packages/
3131

3232
| Parameter | Description |
3333
|-----|----|
34-
| `angular_dist_threshold` | Maximum angular distance, in radians, away from the path heading to trigger rotation until within. |
35-
| `forward_sampling_distance` | Forward distance, in meters, along path to select a sampling point to use to approximate path heading |
36-
| `rotate_to_heading_angular_vel` | Angular rotational velocity, in rad/s, to rotate to the path heading |
37-
| `primary_controller` | Internal controller plugin to use for actual control behavior after rotating to heading |
38-
| `max_angular_accel` | Maximum angular acceleration for rotation to heading |
39-
| `simulate_ahead_time` | Time in seconds to forward simulate a rotation command to check for collisions. If a collision is found, forwards control back to the primary controller plugin. |
40-
| `rotate_to_goal_heading` | If true, the rotationShimController will take back control of the robot when in XY tolerance of the goal and start rotating to the goal heading |
34+
| `angular_dist_threshold` | Maximum angular distance, in radians, away from the path heading to trigger rotation until within. |
35+
| `forward_sampling_distance` | Forward distance, in meters, along path to select a sampling point to use to approximate path heading |
36+
| `rotate_to_heading_angular_vel` | Angular rotational velocity, in rad/s, to rotate to the path heading |
37+
| `primary_controller` | Internal controller plugin to use for actual control behavior after rotating to heading |
38+
| `max_angular_accel` | Maximum angular acceleration for rotation to heading |
39+
| `simulate_ahead_time` | Time in seconds to forward simulate a rotation command to check for collisions. If a collision is found, forwards control back to the primary controller plugin. |
40+
| `rotate_to_goal_heading` | If true, the rotationShimController will take back control of the robot when in XY tolerance of the goal and start rotating to the goal heading |
41+
| `use_path_orientations` | If true, the controller will use the orientations of the path points to compute the heading of the path instead of computing the heading from the path points. If true, the controller will use the orientations of the path points to compute the heading of the path instead of computing the heading from the path points. Use for for feasible planners like the Smac Planner which generate feasible paths with orientations for forward and reverse motion. |
4142

4243
Example fully-described XML with default parameter values:
4344

@@ -70,6 +71,7 @@ controller_server:
7071
max_angular_accel: 3.2
7172
simulate_ahead_time: 1.0
7273
rotate_to_goal_heading: false
74+
use_path_orientations: false
7375
7476
# DWB parameters
7577
...

nav2_rotation_shim_controller/include/nav2_rotation_shim_controller/nav2_rotation_shim_controller.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ class RotationShimController : public nav2_core::Controller
190190
double control_duration_, simulate_ahead_time_;
191191
bool rotate_to_goal_heading_, in_rotation_, rotate_to_heading_once_;
192192
bool closed_loop_;
193+
bool use_path_orientations_;
193194
double last_angular_vel_ = std::numeric_limits<double>::max();
194195

195196
// Dynamic parameters handler

nav2_rotation_shim_controller/src/nav2_rotation_shim_controller.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ void RotationShimController::configure(
7070
node, plugin_name_ + ".rotate_to_heading_once", rclcpp::ParameterValue(false));
7171
nav2_util::declare_parameter_if_not_declared(
7272
node, plugin_name_ + ".closed_loop", rclcpp::ParameterValue(true));
73+
nav2_util::declare_parameter_if_not_declared(
74+
node, plugin_name_ + ".use_path_orientations", rclcpp::ParameterValue(false));
7375

7476
node->get_parameter(plugin_name_ + ".angular_dist_threshold", angular_dist_threshold_);
7577
node->get_parameter(plugin_name_ + ".angular_disengage_threshold", angular_disengage_threshold_);
@@ -87,6 +89,7 @@ void RotationShimController::configure(
8789
node->get_parameter(plugin_name_ + ".rotate_to_goal_heading", rotate_to_goal_heading_);
8890
node->get_parameter(plugin_name_ + ".rotate_to_heading_once", rotate_to_heading_once_);
8991
node->get_parameter(plugin_name_ + ".closed_loop", closed_loop_);
92+
node->get_parameter(plugin_name_ + ".use_path_orientations", use_path_orientations_);
9093

9194
try {
9295
primary_controller_ = lp_loader_.createUniqueInstance(primary_controller);
@@ -202,10 +205,17 @@ geometry_msgs::msg::TwistStamped RotationShimController::computeVelocityCommands
202205

203206
std::lock_guard<std::mutex> lock_reinit(mutex_);
204207
try {
205-
geometry_msgs::msg::Pose sampled_pt_base = transformPoseToBaseFrame(getSampledPathPt());
206-
207-
double angular_distance_to_heading =
208-
std::atan2(sampled_pt_base.position.y, sampled_pt_base.position.x);
208+
auto sampled_pt = getSampledPathPt();
209+
double angular_distance_to_heading;
210+
if (use_path_orientations_) {
211+
angular_distance_to_heading = angles::shortest_angular_distance(
212+
tf2::getYaw(pose.pose.orientation),
213+
tf2::getYaw(sampled_pt.pose.orientation));
214+
} else {
215+
geometry_msgs::msg::Pose sampled_pt_base = transformPoseToBaseFrame(sampled_pt);
216+
angular_distance_to_heading = std::atan2(sampled_pt_base.position.y,
217+
sampled_pt_base.position.x);
218+
}
209219

210220
double angular_thresh =
211221
in_rotation_ ? angular_disengage_threshold_ : angular_dist_threshold_;
@@ -418,6 +428,8 @@ RotationShimController::dynamicParametersCallback(std::vector<rclcpp::Parameter>
418428
rotate_to_heading_once_ = parameter.as_bool();
419429
} else if (name == plugin_name_ + ".closed_loop") {
420430
closed_loop_ = parameter.as_bool();
431+
} else if (name == plugin_name_ + ".use_path_orientations") {
432+
use_path_orientations_ = parameter.as_bool();
421433
}
422434
}
423435
}

nav2_rotation_shim_controller/test/test_shim_controller.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,8 @@ TEST(RotationShimControllerTest, testDynamicParameter)
626626
rclcpp::Parameter("test.primary_controller", std::string("HI")),
627627
rclcpp::Parameter("test.rotate_to_goal_heading", true),
628628
rclcpp::Parameter("test.rotate_to_heading_once", true),
629-
rclcpp::Parameter("test.closed_loop", false)});
629+
rclcpp::Parameter("test.closed_loop", false),
630+
rclcpp::Parameter("test.use_path_orientations", true)});
630631

631632
rclcpp::spin_until_future_complete(
632633
node->get_node_base_interface(),
@@ -640,4 +641,5 @@ TEST(RotationShimControllerTest, testDynamicParameter)
640641
EXPECT_EQ(node->get_parameter("test.rotate_to_goal_heading").as_bool(), true);
641642
EXPECT_EQ(node->get_parameter("test.rotate_to_heading_once").as_bool(), true);
642643
EXPECT_EQ(node->get_parameter("test.closed_loop").as_bool(), false);
644+
EXPECT_EQ(node->get_parameter("test.use_path_orientations").as_bool(), true);
643645
}

0 commit comments

Comments
 (0)