Skip to content

Commit 93e01cf

Browse files
committed
Merge branch 'kilted' of github.com:ros-navigation/navigation2 into kilted
2 parents a2a173f + ba9b087 commit 93e01cf

File tree

11 files changed

+250
-59
lines changed

11 files changed

+250
-59
lines changed

nav2_bringup/launch/tb3_loopback_simulation_launch.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ def generate_launch_description() -> LaunchDescription:
144144
'use_composition': use_composition,
145145
'use_respawn': use_respawn,
146146
'use_localization': 'False', # Don't use SLAM, AMCL
147+
'use_keepout_zones': 'False',
148+
'use_speed_zones': 'False',
147149
}.items(),
148150
)
149151

nav2_bringup/launch/tb3_simulation_launch.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ def generate_launch_description() -> LaunchDescription:
195195
'autostart': autostart,
196196
'use_composition': use_composition,
197197
'use_respawn': use_respawn,
198+
'use_keepout_zones': 'False',
199+
'use_speed_zones': 'False',
198200
}.items(),
199201
)
200202
# The SDF file for the world is a xacro file because we wanted to

nav2_bringup/params/nav2_params.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ local_costmap:
229229
plugin: "nav2_costmap_2d::KeepoutFilter"
230230
enabled: KEEPOUT_ZONE_ENABLED
231231
filter_info_topic: "keepout_costmap_filter_info"
232+
override_lethal_cost: True
233+
lethal_override_cost: 200
232234
inflation_layer:
233235
plugin: "nav2_costmap_2d::InflationLayer"
234236
cost_scaling_factor: 3.0
@@ -281,6 +283,8 @@ global_costmap:
281283
plugin: "nav2_costmap_2d::KeepoutFilter"
282284
enabled: KEEPOUT_ZONE_ENABLED
283285
filter_info_topic: "keepout_costmap_filter_info"
286+
override_lethal_cost: True
287+
lethal_override_cost: 200
284288
speed_filter:
285289
plugin: "nav2_costmap_2d::SpeedFilter"
286290
enabled: SPEED_ZONE_ENABLED

nav2_costmap_2d/include/nav2_costmap_2d/costmap_filters/keepout_filter.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ class KeepoutFilter : public CostmapFilter
102102
nav_msgs::msg::OccupancyGrid::SharedPtr filter_mask_;
103103

104104
std::string global_frame_; // Frame of current layer (master_grid)
105+
106+
bool override_lethal_cost_{false}; // If true, lethal cost will be overridden
107+
unsigned char lethal_override_cost_{252}; // Value to override lethal cost with
108+
bool last_pose_lethal_{false}; // If true, last pose was lethal
109+
unsigned int lethal_state_update_min_x_{999999u}, lethal_state_update_min_y_{999999u};
110+
unsigned int lethal_state_update_max_x_{0u}, lethal_state_update_max_y_{0u};
105111
};
106112

107113
} // namespace nav2_costmap_2d

nav2_costmap_2d/plugins/costmap_filters/keepout_filter.cpp

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ void KeepoutFilter::initializeFilter(
7474
std::bind(&KeepoutFilter::filterInfoCallback, this, std::placeholders::_1));
7575

7676
global_frame_ = layered_costmap_->getGlobalFrameID();
77+
78+
declareParameter("override_lethal_cost", rclcpp::ParameterValue(false));
79+
node->get_parameter(name_ + "." + "override_lethal_cost", override_lethal_cost_);
80+
declareParameter("lethal_override_cost", rclcpp::ParameterValue(MAX_NON_OBSTACLE));
81+
node->get_parameter(name_ + "." + "lethal_override_cost", lethal_override_cost_);
82+
83+
// clamp lethal_override_cost_ in case if higher than MAX_NON_OBSTACLE is given
84+
lethal_override_cost_ = \
85+
std::clamp<unsigned int>(lethal_override_cost_, FREE_SPACE, MAX_NON_OBSTACLE);
7786
}
7887

7988
void KeepoutFilter::filterInfoCallback(
@@ -149,7 +158,7 @@ void KeepoutFilter::maskCallback(
149158
void KeepoutFilter::process(
150159
nav2_costmap_2d::Costmap2D & master_grid,
151160
int min_i, int min_j, int max_i, int max_j,
152-
const geometry_msgs::msg::Pose2D & /*pose*/)
161+
const geometry_msgs::msg::Pose2D & pose)
153162
{
154163
std::lock_guard<CostmapFilter::mutex_t> guard(*getMutex());
155164

@@ -244,10 +253,47 @@ void KeepoutFilter::process(
244253
}
245254

246255
// unsigned<-signed conversions.
247-
unsigned const int mg_min_x_u = static_cast<unsigned int>(mg_min_x);
248-
unsigned const int mg_min_y_u = static_cast<unsigned int>(mg_min_y);
249-
unsigned const int mg_max_x_u = static_cast<unsigned int>(mg_max_x);
250-
unsigned const int mg_max_y_u = static_cast<unsigned int>(mg_max_y);
256+
unsigned int mg_min_x_u = static_cast<unsigned int>(mg_min_x);
257+
unsigned int mg_min_y_u = static_cast<unsigned int>(mg_min_y);
258+
unsigned int mg_max_x_u = static_cast<unsigned int>(mg_max_x);
259+
unsigned int mg_max_y_u = static_cast<unsigned int>(mg_max_y);
260+
261+
// Let's find the pose's cost if we are allowed to override the lethal cost
262+
bool is_pose_lethal = false;
263+
if (override_lethal_cost_) {
264+
geometry_msgs::msg::Pose2D mask_pose;
265+
if (transformPose(global_frame_, pose, filter_mask_->header.frame_id, mask_pose)) {
266+
unsigned int mask_robot_i, mask_robot_j;
267+
if (worldToMask(filter_mask_, mask_pose.x, mask_pose.y, mask_robot_i, mask_robot_j)) {
268+
auto data = getMaskCost(filter_mask_, mask_robot_i, mask_robot_j);
269+
is_pose_lethal = (data == INSCRIBED_INFLATED_OBSTACLE || data == LETHAL_OBSTACLE);
270+
if (is_pose_lethal) {
271+
RCLCPP_WARN_THROTTLE(
272+
logger_, *(clock_), 2000,
273+
"KeepoutFilter: Pose is in keepout zone, reducing cost override to navigate out.");
274+
}
275+
}
276+
}
277+
278+
// If in lethal space or just exited lethal space,
279+
// we need to update all possible spaces touched during this state
280+
if (is_pose_lethal || (last_pose_lethal_ && !is_pose_lethal)) {
281+
lethal_state_update_min_x_ = std::min(mg_min_x_u, lethal_state_update_min_x_);
282+
mg_min_x_u = lethal_state_update_min_x_;
283+
lethal_state_update_min_y_ = std::min(mg_min_y_u, lethal_state_update_min_y_);
284+
mg_min_y_u = lethal_state_update_min_y_;
285+
lethal_state_update_max_x_ = std::max(mg_max_x_u, lethal_state_update_max_x_);
286+
mg_max_x_u = lethal_state_update_max_x_;
287+
lethal_state_update_max_y_ = std::max(mg_max_y_u, lethal_state_update_max_y_);
288+
mg_max_y_u = lethal_state_update_max_y_;
289+
} else {
290+
// If out of lethal space, reset managed lethal state sizes
291+
lethal_state_update_min_x_ = master_grid.getSizeInCellsX();
292+
lethal_state_update_min_y_ = master_grid.getSizeInCellsY();
293+
lethal_state_update_max_x_ = 0u;
294+
lethal_state_update_max_y_ = 0u;
295+
}
296+
}
251297

252298
unsigned int i, j; // master_grid iterators
253299
unsigned int index; // corresponding index of master_grid
@@ -284,12 +330,19 @@ void KeepoutFilter::process(
284330
if (data == NO_INFORMATION) {
285331
continue;
286332
}
333+
287334
if (data > old_data || old_data == NO_INFORMATION) {
288-
master_array[index] = data;
335+
if (override_lethal_cost_ && is_pose_lethal) {
336+
master_array[index] = lethal_override_cost_;
337+
} else {
338+
master_array[index] = data;
339+
}
289340
}
290341
}
291342
}
292343
}
344+
345+
last_pose_lethal_ = is_pose_lethal;
293346
}
294347

295348
void KeepoutFilter::resetFilter()

nav2_loopback_sim/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<exec_depend>nav_msgs</exec_depend>
1313
<exec_depend>tf_transformations</exec_depend>
1414
<exec_depend>tf2_ros</exec_depend>
15+
<exec_depend>python3-transforms3d</exec_depend>
1516

1617
<test_depend>ament_copyright</test_depend>
1718
<test_depend>ament_flake8</test_depend>

nav2_smac_planner/include/nav2_smac_planner/analytic_expansion.hpp

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
#ifndef NAV2_SMAC_PLANNER__ANALYTIC_EXPANSION_HPP_
1616
#define NAV2_SMAC_PLANNER__ANALYTIC_EXPANSION_HPP_
1717

18+
#include <ompl/base/ScopedState.h>
19+
#include <ompl/base/spaces/DubinsStateSpace.h>
20+
#include <ompl/base/spaces/ReedsSheppStateSpace.h>
21+
1822
#include <functional>
1923
#include <list>
2024
#include <memory>
@@ -61,7 +65,33 @@ class AnalyticExpansion
6165
Coordinates proposed_coords;
6266
};
6367

64-
typedef std::vector<AnalyticExpansionNode> AnalyticExpansionNodes;
68+
/**
69+
* @struct AnalyticExpansionNodes
70+
* @brief Analytic expansion nodes and associated metadata
71+
*
72+
* This structure holds a collection of analytic expansion nodes and the number of direction
73+
* changes encountered during the expansion.
74+
*/
75+
struct AnalyticExpansionNodes
76+
{
77+
AnalyticExpansionNodes() = default;
78+
79+
void add(
80+
NodePtr & node,
81+
Coordinates & initial_coords,
82+
Coordinates & proposed_coords)
83+
{
84+
nodes.emplace_back(node, initial_coords, proposed_coords);
85+
}
86+
87+
void setDirectionChanges(int changes)
88+
{
89+
direction_changes = changes;
90+
}
91+
92+
std::vector<AnalyticExpansionNode> nodes;
93+
int direction_changes{0};
94+
};
6595

6696
/**
6797
* @brief Constructor for analytic expansion object
@@ -112,14 +142,15 @@ class AnalyticExpansion
112142

113143
/**
114144
* @brief Refined analytic path from the current node to the goal
115-
* @param current_node The node to start the analytic path from
145+
* @param node The node to start the analytic path from. Node head may
146+
* change as a result of refinement
116147
* @param goal_node The goal node to plan to
117148
* @param getter The function object that gets valid nodes from the graph
118149
* @param analytic_nodes The set of analytic nodes to refine
119150
* @return The score of the refined path
120151
*/
121152
float refineAnalyticPath(
122-
const NodePtr & current_node,
153+
NodePtr & node,
123154
const NodePtr & goal_node,
124155
const NodeGetter & getter,
125156
AnalyticExpansionNodes & analytic_nodes);
@@ -135,6 +166,13 @@ class AnalyticExpansion
135166
const NodePtr & node, const NodePtr & goal,
136167
const AnalyticExpansionNodes & expanded_nodes);
137168

169+
/**
170+
* @brief Counts the number of direction changes in a Reeds-Shepp path
171+
* @param path The Reeds-Shepp path to count direction changes in
172+
* @return The number of direction changes in the path
173+
*/
174+
int countDirectionChanges(const ompl::base::ReedsSheppStateSpace::ReedsSheppPath & path);
175+
138176
/**
139177
* @brief Takes an expanded nodes to clean up, if necessary, of any state
140178
* information that may be polluting it from a prior search iteration

0 commit comments

Comments
 (0)