sensor_map.hpp
Go to the documentation of this file.
1 
6 #ifndef mitre_fast_layered_map_sensor_map
7 #define mitre_fast_layered_map_sensor_map
8 #pragma once
9 
10 // STD
11 #include <string>
12 
13 // ROS
14 #include <filters/filter_chain.h>
15 #include <ros/ros.h>
16 #include <nav_msgs/Odometry.h>
17 #include <sensor_msgs/PointCloud2.h>
20 #include <tf2_ros/buffer.h> // Transform point clouds
22 
23 // Grid map
27 #include <grid_map_msgs/GridMap.h>
28 
29 // Pcl
30 #include <pcl-1.7/pcl/point_cloud.h>
31 #include <pcl-1.7/pcl/point_types.h>
33 
34 namespace mitre_fast_layered_map
35 {
36 
38  {
39  // SUBSCRIBED TOPICS
40  std::string nonGroundPointSubTopic;
41  std::string groundPointSubTopic;
42  std::string odomSubTopic;
43  std::string markerSubTopic;
44  std::string staticMapSubTopic;
45  std::string occupancyOutputTopic;
46  std::string gridmapOutputTopic;
47 
48  // MAP CHARACTERISTICS
49  std::string mapName;
50  std::string mapFrameId;
52  double resolution;
53  std::string historyLayerPrefix;
55 
56 
57  // VEHICLE CHARACTERISTICS
58  // @TODO: Could this be pulled from the robot model automatically?
59  // Used to remove lidar points that may be hitting the vehicle
60  std::string vehicleFrameId;
61  double footPrintLen;
62  double footPrintWidth;
63 
64  // FILTERS
65  std::string obstacleFilterNs;
66  std::string mapOperationsFilterNs;
69  double maxPointHeight;
70 
71  // SAVING OBSTACLES
74  };
75 
76  inline bool operator==(const MapConfiguration &conf1, const MapConfiguration &conf2)
77  {
78  return (conf1.nonGroundPointSubTopic == conf2.nonGroundPointSubTopic &&
80  conf1.odomSubTopic == conf2.odomSubTopic &&
81  conf1.markerSubTopic == conf2.markerSubTopic &&
82  conf1.staticMapSubTopic == conf2.staticMapSubTopic &&
84  conf1.mapName == conf2.mapName &&
85  conf1.mapFrameId == conf2.mapFrameId &&
86  conf1.len(0) == conf2.len(0) &&
87  conf1.resolution == conf2.resolution &&
88  conf1.historyLayerPrefix == conf2.historyLayerPrefix &&
89  conf1.numHistoryLayers == conf2.numHistoryLayers &&
90  conf1.vehicleFrameId == conf2.vehicleFrameId &&
92  conf1.footPrintLen == conf2.footPrintLen &&
93  conf1.footPrintWidth == conf2.footPrintWidth &&
94  conf1.obstacleFilterNs == conf2.obstacleFilterNs &&
97  conf1.maxPointHeight == conf2.maxPointHeight &&
100  }
101 
102  typedef pcl::PointCloud<pcl::PointXYZ> PointCloud;
103  class SensorMap
104  {
105  public:
106  SensorMap();
107 
117 
118  ~SensorMap();
119 
120  int init();
121  int once();
122 
123  void odomCb(const nav_msgs::Odometry::ConstPtr);
124  int moveMap(double, double);
125 
126  void groundPointCb(const sensor_msgs::PointCloud2 &);
127  int updateGroundPts(const PointCloud &);
128 
129  void nonGroundPointCb(const sensor_msgs::PointCloud2 &);
130  int updateNongroundPts(const PointCloud &);
131  bool pointHeightFilter(const pcl::PointXYZ, double _vehicleHeight = 0);
132  bool pointBoundingBoxFilter(const pcl::PointXYZ);
133 
134  int integrateStaticMap();
135  void markerCb(const visualization_msgs::Marker &);
136 
137  void staticMapCb(const nav_msgs::OccupancyGrid &);
138 
139  int getOccupancyGrid(nav_msgs::OccupancyGrid &);
140  int publishMap();
141 
142  int tfTransformCloud(const sensor_msgs::PointCloud2 &, sensor_msgs::PointCloud2 &, std::string);
143 
144  friend class TestMap;
145 
146  private:
147  int runFilter();
148 
151  bool initialized_{false}; // Stateful variable for determining if map has been initialized
152 
154 
163 
168  uint64_t readingsReceived_{0};
170  bool cornersCalculated_{false};
171  std::vector<geometry_msgs::Pose> corners_;
172  bool recStaticMap_{false};
176  };
177 
178  // Class with helper functions for testing that the map above works as expected
179  class TestMap
180  {
181 
182  public:
183  TestMap();
184  ~TestMap();
185 
186  bool CheckConfigEqual(SensorMap &, MapConfiguration &);
187  bool CheckMapsEqual(SensorMap &, grid_map::GridMap &);
188  bool CheckGeometry(SensorMap &, grid_map::Length, double resolution);
189  bool CheckFrame(SensorMap &, std::string);
190  bool CheckPosition(SensorMap &, double x, double y);
191  bool CheckNans(SensorMap &);
192  bool TestMapCells(SensorMap &, std::string, Eigen::MatrixXi);
193  bool TestMapCells(SensorMap& , std::string, Eigen::MatrixXf);
194  };
195 } // namespace mitre_fast_layered_map
196 
197 #endif
ros::Subscriber markerSub_
Subscriber for marker topic to add points to map.
Definition: sensor_map.hpp:156
ros::Subscriber groundPointsSub_
Receives point cloud of ground points.
Definition: sensor_map.hpp:159
grid_map::GridMap staticMap_
Storage for static map. For optimization we only want to receive it once.
Definition: sensor_map.hpp:165
std::string obstacleFilterNs
Filter chain for filtering sensor data into obstacles.
Definition: sensor_map.hpp:65
std::string staticMapSubTopic
Sub topic for static maps that should be integrated with our dynamic map.
Definition: sensor_map.hpp:44
double permanentFilterProb
Probability required to declare a cell as a permanent obstacle.
Definition: sensor_map.hpp:73
ros::Publisher gridMapPub_
Publisher for the whole grid map using grid map msgs.
Definition: sensor_map.hpp:162
std::string nonGroundPointSubTopic
Ros topic with nonground (obstacle) points.
Definition: sensor_map.hpp:40
bool enablePermanentObstacles
Whether to try and save permanent obstacles.
Definition: sensor_map.hpp:72
std::string mapFrameId
TF frame that the map should use.
Definition: sensor_map.hpp:50
std::string gridmapOutputTopic
Topic to output the full grid map on.
Definition: sensor_map.hpp:46
grid_map::Length len
Size of the map, assumed to be square.
Definition: sensor_map.hpp:51
ros::Time odomLastUpdate_
Keeps track of last time we updated position of map.
Definition: sensor_map.hpp:173
TFSIMD_FORCE_INLINE const tfScalar & y() const
bool enablePointHeightFilter
Whether to filter points by height.
Definition: sensor_map.hpp:67
std::string odomSubTopic
Ros topic holding odometry information.
Definition: sensor_map.hpp:42
grid_map::GridMap gridMap_
Mapping data storage container.
Definition: sensor_map.hpp:164
double footPrintLen
Length of robot.
Definition: sensor_map.hpp:61
double resolution
Cell size of map.
Definition: sensor_map.hpp:52
std::string occupancyOutputTopic
Topic the occupancy map should be output on.
Definition: sensor_map.hpp:45
TFSIMD_FORCE_INLINE const tfScalar & x() const
bool operator==(const MapConfiguration &conf1, const MapConfiguration &conf2)
Definition: sensor_map.hpp:76
bool enableBoundingBoxFilter
Whether to filter lidar points if they are inside the hitbox of the vehicle.
Definition: sensor_map.hpp:68
std::string historyLayerPrefix
Prefix to use for history layers.
Definition: sensor_map.hpp:53
double footPrintWidth
Width of robot.
Definition: sensor_map.hpp:62
int numHistoryLayers
Number of layers to hold for history.
Definition: sensor_map.hpp:54
ros::NodeHandle nh_
Passed in node handle for namespace.
Definition: sensor_map.hpp:155
filters::FilterChain< grid_map::GridMap > mapOperationsFilterChain_
after updating points
Definition: sensor_map.hpp:167
double maxPointHeight
If height filter is enabled, filter points more than this height above vehicle.
Definition: sensor_map.hpp:69
ros::Time groundLastUpdate_
Keeps track of the last time we updated ground points.
Definition: sensor_map.hpp:174
filters::FilterChain< grid_map::GridMap > obstacleFilterChain_
Filters to modify obstacle state of map.
Definition: sensor_map.hpp:166
tf2_ros::TransformListener tfListener_
Used in tfBuffer_.
Definition: sensor_map.hpp:150
ros::Time nongroundLastUpdate_
Keeps track of the last time we updated non ground points.
Definition: sensor_map.hpp:175
std::vector< geometry_msgs::Pose > corners_
Holds corner of vehicle which will create polygon bounding box.
Definition: sensor_map.hpp:171
ros::Subscriber nonGroundPointsSub_
Receives point cloud of nonground points.
Definition: sensor_map.hpp:158
std::string vehicleFrameId
Frame id of the robot.
Definition: sensor_map.hpp:60
std::string groundPointSubTopic
Ros topic with ground points.
Definition: sensor_map.hpp:41
ros::Subscriber odomSub_
Subscribes to odom topic to position map within frame.
Definition: sensor_map.hpp:157
std::string mapOperationsFilterNs
Filter chain for map operations after obstacles have been determined.
Definition: sensor_map.hpp:66
std::string markerSubTopic
Ros topic to recieve obstacles from other sources.
Definition: sensor_map.hpp:43
Eigen::Array2d Length
ros::Subscriber staticMapSub_
Will subscripe to the static map topic. ASSUMPTION: Only one static map.
Definition: sensor_map.hpp:160
tf2_ros::Buffer tfBuffer_
Holds transformations from tf tree.
Definition: sensor_map.hpp:149
ros::Publisher occPub_
Publisher of occupancy grid.
Definition: sensor_map.hpp:161
std::string mapName
Name that will refer to this instance of map.
Definition: sensor_map.hpp:49
pcl::PointCloud< pcl::PointXYZ > PointCloud
Definition: sensor_map.hpp:102


mitre_fast_layered_map
Author(s):
autogenerated on Thu Mar 11 2021 03:06:49