Skip to content

Commit e690ef0

Browse files
authored
Add support for dynamically changing keepout zone (#5429)
* Add support for dynamically changing keepout zone Signed-off-by: mini-1235 <[email protected]> * Linting Signed-off-by: mini-1235 <[email protected]> * Revert binary and speed changes Signed-off-by: mini-1235 <[email protected]> --------- Signed-off-by: mini-1235 <[email protected]>
1 parent 773a8aa commit e690ef0

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

nav2_costmap_2d/include/nav2_costmap_2d/costmap_filters/costmap_filter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class CostmapFilter : public Layer
9999
*/
100100
void updateBounds(
101101
double robot_x, double robot_y, double robot_yaw,
102-
double * min_x, double * min_y, double * max_x, double * max_y) final;
102+
double * min_x, double * min_y, double * max_x, double * max_y) override;
103103

104104
/**
105105
* @brief Update the costs in the master costmap in the window

nav2_costmap_2d/include/nav2_costmap_2d/costmap_filters/keepout_filter.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ class KeepoutFilter : public CostmapFilter
6868
void initializeFilter(
6969
const std::string & filter_info_topic);
7070

71+
/**
72+
* @brief Update the bounds of the master costmap by this layer's update dimensions
73+
* @param robot_x X pose of robot
74+
* @param robot_y Y pose of robot
75+
* @param robot_yaw Robot orientation
76+
* @param min_x X min map coord of the window to update
77+
* @param min_y Y min map coord of the window to update
78+
* @param max_x X max map coord of the window to update
79+
* @param max_y Y max map coord of the window to update
80+
*/
81+
void updateBounds(
82+
double robot_x, double robot_y, double robot_yaw,
83+
double * min_x, double * min_y, double * max_x, double * max_y) override;
84+
7185
/**
7286
* @brief Process the keepout layer at the current pose / bounds / grid
7387
*/
@@ -108,6 +122,12 @@ class KeepoutFilter : public CostmapFilter
108122
bool last_pose_lethal_{false}; // If true, last pose was lethal
109123
unsigned int lethal_state_update_min_x_{999999u}, lethal_state_update_min_y_{999999u};
110124
unsigned int lethal_state_update_max_x_{0u}, lethal_state_update_max_y_{0u};
125+
126+
unsigned int x_{0};
127+
unsigned int y_{0};
128+
unsigned int width_{0};
129+
unsigned int height_{0};
130+
bool has_updated_data_{false};
111131
};
112132

113133
} // namespace nav2_costmap_2d

nav2_costmap_2d/plugins/costmap_filters/keepout_filter.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,37 @@ void KeepoutFilter::maskCallback(
155155

156156
// Store filter_mask_
157157
filter_mask_ = msg;
158+
has_updated_data_ = true;
159+
x_ = y_ = 0;
160+
width_ = msg->info.width;
161+
height_ = msg->info.height;
162+
}
163+
164+
void KeepoutFilter::updateBounds(
165+
double robot_x, double robot_y, double robot_yaw,
166+
double * min_x, double * min_y, double * max_x, double * max_y)
167+
{
168+
if (!enabled_) {
169+
return;
170+
}
171+
172+
CostmapFilter::updateBounds(robot_x, robot_y, robot_yaw, min_x, min_y, max_x, max_y);
173+
174+
if(!has_updated_data_) {
175+
return;
176+
}
177+
178+
double wx, wy;
179+
180+
layered_costmap_->getCostmap()->mapToWorld(x_, y_, wx, wy);
181+
*min_x = std::min(wx, *min_x);
182+
*min_y = std::min(wy, *min_y);
183+
184+
layered_costmap_->getCostmap()->mapToWorld(x_ + width_, y_ + height_, wx, wy);
185+
*max_x = std::max(wx, *max_x);
186+
*max_y = std::max(wy, *max_y);
187+
188+
has_updated_data_ = false;
158189
}
159190

160191
void KeepoutFilter::process(

0 commit comments

Comments
 (0)