occupancy_map.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, The Regents of the University of California (Regents).
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following
14  * disclaimer in the documentation and/or other materials provided
15  * with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  * Please contact the author(s) of this library if you have any questions.
34  * Authors: David Fridovich-Keil ( dfk@eecs.berkeley.edu )
35  */
36 
38 //
39 // Base class for all occupancy maps, which are types of environment models
40 // in which each point in space is assigned a probability of being occupied.
41 // The base IsValid check is then a threshold test on the corresponding
42 // occupancy probability.
43 //
44 // Like Environment, this class is templated on the sensor message type (M)
45 // and the sensor parameters type (P) which may be used to simulate sensor
46 // measurements.
47 //
49 
50 #ifndef FASTRACK_ENVIRONMENT_OCCUPANCY_MAP_H
51 #define FASTRACK_ENVIRONMENT_OCCUPANCY_MAP_H
52 
53 #include <fastrack/bound/box.h>
54 #include <fastrack/bound/sphere.h>
56 #include <fastrack/utils/types.h>
57 
58 #include <ros/ros.h>
59 #include <std_msgs/Empty.h>
60 #include <visualization_msgs/Marker.h>
61 
62 namespace fastrack {
63 namespace environment {
64 
65 using bound::Box;
66 using bound::Sphere;
67 using bound::Cylinder;
68 
69 template <typename M, typename P>
70 class OccupancyMap : public Environment<M, P> {
71  public:
72  virtual ~OccupancyMap() {}
73 
74  // Collision check is a threshold test on occupancy probability integrated
75  // over the bound.
76  bool IsValid(const Vector3d& position, const TrackingBound& bound,
77  double time = std::numeric_limits<double>::quiet_NaN()) const {
78  return this->initialized_ &&
79  OccupancyProbability(position, bound, time) < free_space_threshold_;
80  }
81 
82  // Derived classes must provide an OccupancyProbability function for both
83  // single points and tracking error bounds centered on a point.
84  virtual double OccupancyProbability(
85  const Vector3d& position,
86  double time = std::numeric_limits<double>::quiet_NaN()) const = 0;
87  virtual double OccupancyProbability(
88  const Vector3d& position, const TrackingBound& bound,
89  double time = std::numeric_limits<double>::quiet_NaN()) const = 0;
90 
91  // Generate a sensor measurement.
92  virtual M SimulateSensor(const P& params) const = 0;
93 
94  // Derived classes must have some sort of visualization through RViz.
95  virtual void Visualize() const = 0;
96 
97  protected:
98  explicit OccupancyMap() : Environment<M, P>() {}
99 
100  // Load parameters. This may be overridden by derived classes if needed
101  // (they should still call this one via OccupancyMap::LoadParameters).
102  virtual bool LoadParameters(const ros::NodeHandle& n);
103 
104  // Update this environment with the information contained in the given
105  // sensor measurement.
106  // NOTE! This function needs to publish on `updated_topic_`.
107  virtual void SensorCallback(const typename M::ConstPtr& msg) = 0;
108 
109  // Occupancy probability threshold below which a point/region is considered
110  // to be free space.
112 }; //\class OccupancyMap
113 
114 // ----------------------------- IMPLEMENTATION ----------------------------- //
115 
116 // Load parameters. This may be overridden by derived classes if needed
117 // (they should still call this one via OccupancyMap::LoadParameters).
118 template <typename M, typename P>
119 bool OccupancyMap<M, P>::LoadParameters(const ros::NodeHandle& n) {
120  if (!Environment<M, P>::LoadParameters(n)) return false;
121 
122  ros::NodeHandle nl(n);
123 
124  // Free space threshold.
125  if (!nl.getParam("free_space_threshold", this->free_space_threshold_)) {
126  ROS_WARN("%s: Free space threshold was not provided.", this->name_.c_str());
127  this->free_space_threshold_ = 0.1;
128  }
129 
130  return true;
131 }
132 
133 } // namespace environment
134 } // namespace fastrack
135 
136 #endif
virtual void Visualize() const =0
virtual void SensorCallback(const typename M::ConstPtr &msg)=0
virtual double OccupancyProbability(const Vector3d &position, double time=std::numeric_limits< double >::quiet_NaN()) const =0
Definition: box.h:53
bool IsValid(const Vector3d &position, const TrackingBound &bound, double time=std::numeric_limits< double >::quiet_NaN()) const
Definition: occupancy_map.h:76
virtual M SimulateSensor(const P &params) const =0
virtual bool LoadParameters(const ros::NodeHandle &n)


fastrack
Author(s): David Fridovich-Keil
autogenerated on Mon Aug 3 2020 21:28:37