costmap_2d
obstacle_layer.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2008, 2013, Willow Garage, Inc.
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 Willow Garage, Inc. 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: Eitan Marder-Eppstein
36  * David V. Lu!!
37  *********************************************************************/
38 #ifndef COSTMAP_2D_OBSTACLE_LAYER_H_
39 #define COSTMAP_2D_OBSTACLE_LAYER_H_
40 
41 #include <ros/ros.h>
45 
46 #include <nav_msgs/OccupancyGrid.h>
47 
48 #include <sensor_msgs/LaserScan.h>
49 #include <laser_geometry/laser_geometry.h>
50 #include <sensor_msgs/PointCloud.h>
51 #include <sensor_msgs/PointCloud2.h>
52 #include <sensor_msgs/point_cloud_conversion.h>
53 #include <tf2_ros/message_filter.h>
54 #include <message_filters/subscriber.h>
55 #include <dynamic_reconfigure/server.h>
56 #include <costmap_2d/ObstaclePluginConfig.h>
57 #include <costmap_2d/footprint.h>
58 
59 namespace costmap_2d
60 {
61 
62 class ObstacleLayer : public CostmapLayer
63 {
64 public:
66  {
67  costmap_ = NULL; // this is the unsigned char* member of parent class Costmap2D.
68  }
69 
70  virtual ~ObstacleLayer();
71  virtual void onInitialize();
72  virtual void updateBounds(double robot_x, double robot_y, double robot_yaw, double* min_x, double* min_y,
73  double* max_x, double* max_y);
74  virtual void updateCosts(costmap_2d::Costmap2D& master_grid, int min_i, int min_j, int max_i, int max_j);
75 
76  virtual void activate();
77  virtual void deactivate();
78  virtual void reset();
79 
85  void laserScanCallback(const sensor_msgs::LaserScanConstPtr& message,
86  const boost::shared_ptr<costmap_2d::ObservationBuffer>& buffer);
87 
93  void laserScanValidInfCallback(const sensor_msgs::LaserScanConstPtr& message,
94  const boost::shared_ptr<ObservationBuffer>& buffer);
95 
101  void pointCloudCallback(const sensor_msgs::PointCloudConstPtr& message,
102  const boost::shared_ptr<costmap_2d::ObservationBuffer>& buffer);
103 
109  void pointCloud2Callback(const sensor_msgs::PointCloud2ConstPtr& message,
110  const boost::shared_ptr<costmap_2d::ObservationBuffer>& buffer);
111 
112  // for testing purposes
113  void addStaticObservation(costmap_2d::Observation& obs, bool marking, bool clearing);
114  void clearStaticObservations(bool marking, bool clearing);
115 
116 protected:
117 
118  void checkTimeStamps(double* min_x, double* min_y, double* max_x, double* max_y);
119  double free_to_default_time_;
121 
122  virtual void setupDynamicReconfigure(ros::NodeHandle& nh);
123 
129  bool getMarkingObservations(std::vector<costmap_2d::Observation>& marking_observations) const;
130 
136  bool getClearingObservations(std::vector<costmap_2d::Observation>& clearing_observations) const;
137 
146  virtual void raytraceFreespace(const costmap_2d::Observation& clearing_observation, double* min_x, double* min_y,
147  double* max_x, double* max_y);
148 
149  void updateRaytraceBounds(double ox, double oy, double wx, double wy, double range, double* min_x, double* min_y,
150  double* max_x, double* max_y);
151 
154  void updateFootprint(double robot_x, double robot_y, double robot_yaw, double* min_x, double* min_y,
155  double* max_x, double* max_y);
156 
158  double max_obstacle_height_;
159 
160  laser_geometry::LaserProjection projector_;
161 
167 
168  // Used only for testing purposes
170 
171  bool rolling_window_;
172  dynamic_reconfigure::Server<costmap_2d::ObstaclePluginConfig> *dsrv_;
173 
175 
176 private:
177  void reconfigureCB(costmap_2d::ObstaclePluginConfig &config, uint32_t level);
178 };
179 
180 } // namespace costmap_2d
181 
182 #endif // COSTMAP_2D_OBSTACLE_LAYER_H_
costmap_2d::ObstacleLayer::deactivate
virtual void deactivate()
Stop publishers.
Definition: obstacle_layer.cpp:626
costmap_2d::ObstacleLayer::getMarkingObservations
bool getMarkingObservations(std::vector< costmap_2d::Observation > &marking_observations) const
Get the observations used to mark space.
Definition: obstacle_layer.cpp:496
costmap_2d::ObstacleLayer::raytraceFreespace
virtual void raytraceFreespace(const costmap_2d::Observation &clearing_observation, double *min_x, double *min_y, double *max_x, double *max_y)
Clear freespace based on one observation.
Definition: obstacle_layer.cpp:528
costmap_2d::ObstacleLayer::global_frame_
std::string global_frame_
The global frame for the costmap.
Definition: obstacle_layer.h:229
std::string
costmap_layer.h
costmap_2d::ObstacleLayer::updateRaytraceBounds
void updateRaytraceBounds(double ox, double oy, double wx, double wy, double range, double *min_x, double *min_y, double *max_x, double *max_y)
Definition: obstacle_layer.cpp:635
costmap_2d::ObstacleLayer::static_clearing_observations_
std::vector< costmap_2d::Observation > static_clearing_observations_
Definition: obstacle_layer.h:241
costmap_2d::ObstacleLayer::updateCosts
virtual void updateCosts(costmap_2d::Costmap2D &master_grid, int min_i, int min_j, int max_i, int max_j)
Actually update the underlying costmap, only within the bounds calculated during UpdateBounds().
Definition: obstacle_layer.cpp:460
costmap_2d::ObstacleLayer::occupied_to_default_time_
double occupied_to_default_time_
Definition: obstacle_layer.h:192
std::vector< costmap_2d::Observation >
costmap_2d::ObstacleLayer::updateBounds
virtual void updateBounds(double robot_x, double robot_y, double robot_yaw, double *min_x, double *min_y, double *max_x, double *max_y)
This is called by the LayeredCostmap to poll this plugin as to how much of the costmap it needs to up...
Definition: obstacle_layer.cpp:370
layered_costmap.h
costmap_2d::ObstacleLayer::static_marking_observations_
std::vector< costmap_2d::Observation > static_marking_observations_
Definition: obstacle_layer.h:241
costmap_2d::ObstacleLayer::reconfigureCB
void reconfigureCB(costmap_2d::ObstaclePluginConfig &config, uint32_t level)
Definition: obstacle_layer.cpp:234
costmap_2d::ObstacleLayer::observation_notifiers_
std::vector< boost::shared_ptr< tf2_ros::MessageFilterBase > > observation_notifiers_
Used to make sure that transforms are available for each sensor.
Definition: obstacle_layer.h:235
costmap_2d::Costmap2D
A 2D costmap provides a mapping between points in the world and their associated "costs".
Definition: costmap_2d.h:96
costmap_2d::ObstacleLayer::projector_
laser_geometry::LaserProjection projector_
Used to project laser scans into point clouds.
Definition: obstacle_layer.h:232
costmap_2d::ObstacleLayer::setupDynamicReconfigure
virtual void setupDynamicReconfigure(ros::NodeHandle &nh)
Definition: obstacle_layer.cpp:221
costmap_2d::ObstacleLayer::addStaticObservation
void addStaticObservation(costmap_2d::Observation &obs, bool marking, bool clearing)
Definition: obstacle_layer.cpp:480
costmap_2d::ObstacleLayer::onInitialize
virtual void onInitialize()
This is called at the end of initialize(). Override to implement subclass-specific initialization.
Definition: obstacle_layer.cpp:57
costmap_2d::ObstacleLayer::free_to_default_time_
double free_to_default_time_
Definition: obstacle_layer.h:191
costmap_2d::ObstacleLayer::max_obstacle_height_
double max_obstacle_height_
Max Obstacle Height.
Definition: obstacle_layer.h:230
costmap_2d::ObstacleLayer::marking_buffers_
std::vector< boost::shared_ptr< costmap_2d::ObservationBuffer > > marking_buffers_
Used to store observation buffers used for marking obstacles.
Definition: obstacle_layer.h:237
observation_buffer.h
costmap_2d::ObstacleLayer::ObstacleLayer
ObstacleLayer()
Definition: obstacle_layer.h:137
costmap_2d::ObstacleLayer::observation_subscribers_
std::vector< boost::shared_ptr< message_filters::SubscriberBase > > observation_subscribers_
Used for the observation message filters.
Definition: obstacle_layer.h:234
costmap_2d::ObstacleLayer::clearing_buffers_
std::vector< boost::shared_ptr< costmap_2d::ObservationBuffer > > clearing_buffers_
Used to store observation buffers used for clearing obstacles.
Definition: obstacle_layer.h:238
costmap_2d::ObstacleLayer::activate
virtual void activate()
Restart publishers if they've been stopped.
Definition: obstacle_layer.cpp:611
costmap_2d::ObstacleLayer::combination_method_
int combination_method_
Definition: obstacle_layer.h:246
costmap_2d::ObstacleLayer::transformed_footprint_
std::vector< geometry_msgs::Point > transformed_footprint_
Definition: obstacle_layer.h:224
costmap_2d::ObstacleLayer::checkTimeStamps
void checkTimeStamps(double *min_x, double *min_y, double *max_x, double *max_y)
Definition: obstacle_layer.cpp:342
costmap_2d::ObstacleLayer::~ObstacleLayer
virtual ~ObstacleLayer()
Definition: obstacle_layer.cpp:229
costmap_2d::ObstacleLayer::updateFootprint
void updateFootprint(double robot_x, double robot_y, double robot_yaw, double *min_x, double *min_y, double *max_x, double *max_y)
Definition: obstacle_layer.cpp:448
footprint.h
costmap_2d::Observation
Stores an observation in terms of a point cloud and the origin of the source.
Definition: observation.h:46
costmap_2d::ObstacleLayer::laserScanValidInfCallback
void laserScanValidInfCallback(const sensor_msgs::LaserScanConstPtr &message, const boost::shared_ptr< ObservationBuffer > &buffer)
A callback to handle buffering LaserScan messages which need filtering to turn Inf values into range_...
Definition: obstacle_layer.cpp:274
costmap_2d::ObstacleLayer::reset
virtual void reset()
Definition: obstacle_layer.cpp:645
costmap_2d::ObstacleLayer::pointCloud2Callback
void pointCloud2Callback(const sensor_msgs::PointCloud2ConstPtr &message, const boost::shared_ptr< costmap_2d::ObservationBuffer > &buffer)
A callback to handle buffering PointCloud2 messages.
Definition: obstacle_layer.cpp:333
costmap_2d::ObstacleLayer::dsrv_
dynamic_reconfigure::Server< costmap_2d::ObstaclePluginConfig > * dsrv_
Definition: obstacle_layer.h:244
costmap_2d::Costmap2D::costmap_
unsigned char * costmap_
Definition: costmap_2d.h:470
costmap_2d::ObstacleLayer::pointCloudCallback
void pointCloudCallback(const sensor_msgs::PointCloudConstPtr &message, const boost::shared_ptr< costmap_2d::ObservationBuffer > &buffer)
A callback to handle buffering PointCloud messages.
Definition: obstacle_layer.cpp:316
costmap_2d::ObstacleLayer::clearStaticObservations
void clearStaticObservations(bool marking, bool clearing)
Definition: obstacle_layer.cpp:488
costmap_2d::ObstacleLayer::footprint_clearing_enabled_
bool footprint_clearing_enabled_
Definition: obstacle_layer.h:225
costmap_2d
Definition: array_parser.h:37
costmap_2d::ObstacleLayer::laserScanCallback
void laserScanCallback(const sensor_msgs::LaserScanConstPtr &message, const boost::shared_ptr< costmap_2d::ObservationBuffer > &buffer)
A callback to handle buffering LaserScan messages.
Definition: obstacle_layer.cpp:244
costmap_2d::ObstacleLayer::observation_buffers_
std::vector< boost::shared_ptr< costmap_2d::ObservationBuffer > > observation_buffers_
Used to store observations from various sensors.
Definition: obstacle_layer.h:236
costmap_2d::ObstacleLayer::rolling_window_
bool rolling_window_
Definition: obstacle_layer.h:243
costmap_2d::ObstacleLayer::getClearingObservations
bool getClearingObservations(std::vector< costmap_2d::Observation > &clearing_observations) const
Get the observations used to clear space.
Definition: obstacle_layer.cpp:512