Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
keepout_filter.hpp
1 /*********************************************************************
2  *
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2020 Samsung Research Russia
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of the <ORGANIZATION> nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  * Author: Alexey Merzlyakov
36  *********************************************************************/
37 
38 #ifndef NAV2_COSTMAP_2D__COSTMAP_FILTERS__KEEPOUT_FILTER_HPP_
39 #define NAV2_COSTMAP_2D__COSTMAP_FILTERS__KEEPOUT_FILTER_HPP_
40 
41 #include <string>
42 #include <memory>
43 
44 #include "nav2_costmap_2d/costmap_filters/costmap_filter.hpp"
45 
46 #include "nav2_msgs/msg/costmap_filter_info.hpp"
47 
48 namespace nav2_costmap_2d
49 {
50 
57 {
58 public:
62  KeepoutFilter();
63 
67  void initializeFilter(
68  const std::string & filter_info_topic) override;
69 
80  void updateBounds(
81  double robot_x, double robot_y, double robot_yaw,
82  double * min_x, double * min_y, double * max_x, double * max_y) override;
83 
87  void process(
88  nav2_costmap_2d::Costmap2D & master_grid,
89  int min_i, int min_j, int max_i, int max_j,
90  const geometry_msgs::msg::Pose & pose) override;
91 
95  void resetFilter() override;
96 
100  bool isActive();
101 
102 protected:
106  void filterInfoCallback(const nav2_msgs::msg::CostmapFilterInfo::ConstSharedPtr & msg);
110  void maskCallback(const nav_msgs::msg::OccupancyGrid::ConstSharedPtr & msg);
111 
112  nav2::Subscription<nav2_msgs::msg::CostmapFilterInfo>::SharedPtr filter_info_sub_;
113  nav2::Subscription<nav_msgs::msg::OccupancyGrid>::SharedPtr mask_sub_;
114 
115  nav_msgs::msg::OccupancyGrid::ConstSharedPtr filter_mask_;
116 
117  std::string global_frame_; // Frame of current layer (master_grid)
118 
119  bool override_lethal_cost_{false}; // If true, lethal cost will be overridden
120  unsigned char lethal_override_cost_{252}; // Value to override lethal cost with
121  bool last_pose_lethal_{false}; // If true, last pose was lethal
122  bool is_pose_lethal_{false};
123  double lethal_state_update_min_x_, lethal_state_update_min_y_;
124  double lethal_state_update_max_x_, lethal_state_update_max_y_;
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};
131 };
132 
133 } // namespace nav2_costmap_2d
134 
135 #endif // NAV2_COSTMAP_2D__COSTMAP_FILTERS__KEEPOUT_FILTER_HPP_
A 2D costmap provides a mapping between points in the world and their associated "costs".
Definition: costmap_2d.hpp:69
: CostmapFilter basic class. It is inherited from Layer in order to avoid hidden problems when the sh...
Reads in a keepout mask and marks keepout regions in the map to prevent planning or control in restri...
void initializeFilter(const std::string &filter_info_topic) override
Initialize the filter and subscribe to the info topic.
void resetFilter() override
Reset the costmap filter / topic / info.
void process(nav2_costmap_2d::Costmap2D &master_grid, int min_i, int min_j, int max_i, int max_j, const geometry_msgs::msg::Pose &pose) override
Process the keepout layer at the current pose / bounds / grid.
void filterInfoCallback(const nav2_msgs::msg::CostmapFilterInfo::ConstSharedPtr &msg)
Callback for the filter information.
bool isActive()
If this filter is active.
void updateBounds(double robot_x, double robot_y, double robot_yaw, double *min_x, double *min_y, double *max_x, double *max_y) override
Update the bounds of the master costmap by this layer's update dimensions.
void maskCallback(const nav_msgs::msg::OccupancyGrid::ConstSharedPtr &msg)
Callback for the filter mask.