Skip to content

Commit b598a38

Browse files
adding support for in-place rotations in state lattice (#2747)
1 parent f8cd62e commit b598a38

8 files changed

Lines changed: 28 additions & 3 deletions

File tree

nav2_smac_planner/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ planner_server:
121121
change_penalty: 0.0 # For Hybrid nodes: penalty to apply if motion is changing directions, must be >= 0
122122
non_straight_penalty: 1.20 # For Hybrid nodes: penalty to apply if motion is non-straight, must be => 1
123123
cost_penalty: 2.0 # For Hybrid nodes: penalty to apply to higher cost areas when adding into the obstacle map dynamic programming distance expansion heuristic. This drives the robot more towards the center of passages. A value between 1.3 - 3.5 is reasonable.
124+
rotation_penalty: 5.0 # For Lattice node: Penalty to apply only to pure rotate in place commands when using minimum control sets containing rotate in place primitives. This should always be set sufficiently high to weight against this action unless strictly necessary for obstacle avoidance or there may be frequent discontinuities in the plan where it requests the robot to rotate in place to short-cut an otherwise smooth path for marginal path distance savings.
124125
lookup_table_size: 20 # For Hybrid nodes: Size of the dubin/reeds-sheep distance window to cache, in meters.
125126
cache_obstacle_heuristic: True # For Hybrid nodes: Cache the obstacle map dynamic programming distance expansion heuristic between subsiquent replannings of the same goal location. Dramatically speeds up replanning performance (40x) if costmap is largely static.
126127
allow_reverse_expansion: False # For Lattice nodes: Whether to expand state lattice graph in forward primitives or reverse as well, will double the branching factor at each step.

nav2_smac_planner/include/nav2_smac_planner/node_lattice.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ struct LatticeMotionTable
102102
float non_straight_penalty;
103103
float cost_penalty;
104104
float reverse_penalty;
105+
float rotation_penalty;
105106
bool allow_reverse_expansion;
106107
std::vector<std::vector<MotionPrimitive>> motion_primitives;
107108
ompl::base::StateSpacePtr state_space;

nav2_smac_planner/include/nav2_smac_planner/types.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct SearchInfo
3939
float change_penalty;
4040
float reverse_penalty;
4141
float cost_penalty;
42+
float rotation_penalty;
4243
float analytic_expansion_ratio;
4344
float analytic_expansion_max_length;
4445
std::string lattice_filepath;

nav2_smac_planner/src/node_hybrid.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,7 @@ float NodeHybrid::getTraversalCost(const NodePtr & child)
314314

315315
float travel_cost = 0.0;
316316
float travel_cost_raw =
317-
NodeHybrid::travel_distance_cost +
318-
(NodeHybrid::travel_distance_cost * motion_table.cost_penalty * normalized_cost);
317+
NodeHybrid::travel_distance_cost * (1.0 + motion_table.cost_penalty * normalized_cost);
319318

320319
if (child->getMotionPrimitiveIndex() == 0 || child->getMotionPrimitiveIndex() == 3) {
321320
// New motion is a straight motion, no additional costs to be applied

nav2_smac_planner/src/node_lattice.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ void LatticeMotionTable::initMotionModel(
6262
reverse_penalty = search_info.reverse_penalty;
6363
current_lattice_filepath = search_info.lattice_filepath;
6464
allow_reverse_expansion = search_info.allow_reverse_expansion;
65+
rotation_penalty = search_info.rotation_penalty;
6566

6667
// Get the metadata about this minimum control set
6768
lattice_metadata = getLatticeMetadata(current_lattice_filepath);
@@ -283,8 +284,13 @@ float NodeLattice::getTraversalCost(const NodePtr & child)
283284
return prim_length;
284285
}
285286

287+
// Pure rotation in place 1 angular bin in either direction
288+
if (transition_prim->trajectory_length < 1e-4) {
289+
return motion_table.rotation_penalty * (1.0 + motion_table.cost_penalty * normalized_cost);
290+
}
291+
286292
float travel_cost = 0.0;
287-
float travel_cost_raw = prim_length + (prim_length * motion_table.cost_penalty * normalized_cost);
293+
float travel_cost_raw = prim_length * (1.0 + motion_table.cost_penalty * normalized_cost);
288294

289295
if (transition_prim->arc_length < 0.001) {
290296
// New motion is a straight motion, no additional costs to be applied

nav2_smac_planner/src/smac_planner_lattice.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ void SmacPlannerLattice::configure(
9595
nav2_util::declare_parameter_if_not_declared(
9696
node, name + ".cost_penalty", rclcpp::ParameterValue(2.0));
9797
node->get_parameter(name + ".cost_penalty", _search_info.cost_penalty);
98+
nav2_util::declare_parameter_if_not_declared(
99+
node, name + ".rotation_penalty", rclcpp::ParameterValue(5.0));
100+
node->get_parameter(name + ".rotation_penalty", _search_info.rotation_penalty);
98101
nav2_util::declare_parameter_if_not_declared(
99102
node, name + ".analytic_expansion_ratio", rclcpp::ParameterValue(3.5));
100103
node->get_parameter(name + ".analytic_expansion_ratio", _search_info.analytic_expansion_ratio);
@@ -357,6 +360,9 @@ SmacPlannerLattice::dynamicParametersCallback(std::vector<rclcpp::Parameter> par
357360
} else if (name == _name + ".cost_penalty") {
358361
reinit_a_star = true;
359362
_search_info.cost_penalty = static_cast<float>(parameter.as_double());
363+
} else if (name == _name + ".rotation_penalty") {
364+
reinit_a_star = true;
365+
_search_info.rotation_penalty = static_cast<float>(parameter.as_double());
360366
} else if (name == _name + ".analytic_expansion_ratio") {
361367
reinit_a_star = true;
362368
_search_info.analytic_expansion_ratio = static_cast<float>(parameter.as_double());

nav2_smac_planner/src/smoother.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,16 @@ std::vector<PathSegment> Smoother::findDirectionalPathSegments(const nav_msgs::m
241241
segments.push_back(curr_segment);
242242
curr_segment.start = idx;
243243
}
244+
245+
// Checking for the existance of a differential rotation in place.
246+
double cur_theta = tf2::getYaw(path.poses[idx].pose.orientation);
247+
double next_theta = tf2::getYaw(path.poses[idx + 1].pose.orientation);
248+
double dtheta = angles::shortest_angular_distance(cur_theta, next_theta);
249+
if (fabs(ab_x) < 1e-4 && fabs(ab_y) < 1e-4 && fabs(dtheta) > 1e-4) {
250+
curr_segment.end = idx;
251+
segments.push_back(curr_segment);
252+
curr_segment.start = idx;
253+
}
244254
}
245255

246256
curr_segment.end = path.poses.size() - 1;

nav2_smac_planner/test/test_smac_lattice.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ TEST(SmacTest, test_smac_lattice_reconfigure)
123123
rclcpp::Parameter("test.lookup_table_size", 30.0),
124124
rclcpp::Parameter("test.smooth_path", false),
125125
rclcpp::Parameter("test.analytic_expansion_max_length", 42.0),
126+
rclcpp::Parameter("test.rotation_penalty", 42.0),
126127
rclcpp::Parameter("test.allow_reverse_expansion", true)});
127128

128129
try {

0 commit comments

Comments
 (0)