sensor_map_node.cpp
Go to the documentation of this file.
1 
6 // ROS
7 #include <ros/ros.h>
8 
9 // Us
10 #include "sensor_map.hpp"
11 
13 {
14 
15  // Constants for now. Use <remap> in launch file
16  // to point to correct topics
17  _mapConfig.occupancyOutputTopic = "costmap";
18  _mapConfig.gridmapOutputTopic = "gridmap";
19 
20 
21  // Required Parameters
22  if (!_nh.getParam("odom_sub_topic", _mapConfig.odomSubTopic))
23  {
24  ROS_ERROR("No odometry sub topic set.");
25  return -1;
26  }
27 
28  if (!_nh.getParam("ground_points_sub_topic", _mapConfig.groundPointSubTopic))
29  {
30  ROS_ERROR("No ground point sub topic set.");
31  return -1;
32  }
33 
34  if (!_nh.getParam("nonground_points_sub_topic", _mapConfig.nonGroundPointSubTopic))
35  {
36  ROS_ERROR("No nonground points sub topic set.");
37  return -1;
38  }
39 
40  if (!_nh.getParam("map_frame_id", _mapConfig.mapFrameId))
41  {
42  ROS_ERROR("No map frame_id set.");
43  return -1;
44  }
45 
46  if (!_nh.getParam("vehicle_frame_id", _mapConfig.vehicleFrameId))
47  {
48  ROS_ERROR("No vehicle frame_id set.");
49  return -1;
50  }
51 
52  int mapLen;
53  if (!_nh.getParam("map_len", mapLen))
54  {
55  ROS_ERROR("No map length set.");
56  return -1;
57  }
58 
59  _mapConfig.len = grid_map::Length(mapLen, mapLen);
60 
61  if (!_nh.getParam("resolution", _mapConfig.resolution))
62  {
63  ROS_ERROR("No map resolution set.");
64  return -1;
65  }
66 
67  if (!_nh.getParam("obstacle_filter_ns", _mapConfig.obstacleFilterNs))
68  {
69  ROS_ERROR("No obstacle filter ns specified.");
70  return -1;
71  }
72 
73  if (!_nh.getParam("map_operations_filter_ns", _mapConfig.mapOperationsFilterNs))
74  {
75  ROS_ERROR("No map operations filter ns specified.");
76  return -1;
77  }
78 
79  // Optional parameters
80  _nh.param<std::string>("map_name", _mapConfig.mapName, "Map");
81 
82  // Empty string notifies we won't be subscribed to these
83  _nh.param<std::string>("marker_sub_topic", _mapConfig.markerSubTopic, "");
84  _nh.param<std::string>("static_map_sub_topic", _mapConfig.staticMapSubTopic, "");
85 
86  // Settigns for saving history of readings
87  _nh.param<std::string>("history_layer_prefix", _mapConfig.historyLayerPrefix, "history_");
88  _nh.param<int>("num_history_layers", _mapConfig.numHistoryLayers, 10);
89 
90  // Probability for setting permanent obstacles cells in the map
91  _nh.param<bool>("enable_permanent_obstacles", _mapConfig.enablePermanentObstacles, false);
92  _nh.param<double>("permanent_obstacle_probability", _mapConfig.permanentFilterProb, 1);
93 
94  // Enable or disable height filtering
95  _nh.param<bool>("enable_height_point_filtering", _mapConfig.enablePointHeightFilter, false);
96 
97  // -1 for no filtering
98  _nh.param<double>("max_point_height", _mapConfig.maxPointHeight, -1);
99  // We assume that the odom message is from the center of the robot
100  _nh.param<bool>("enable_bounding_box_filter", _mapConfig.enableBoundingBoxFilter, true);
101  _nh.param<double>("footprint_len_m", _mapConfig.footPrintLen, 4);
102  _nh.param<double>("footprint_width_m", _mapConfig.footPrintWidth, 2);
103 
104  return 0;
105 }
106 
107 int main(int argc, char **argv)
108 {
109  ros::init(argc, argv, "t_sensor_map");
110  ros::NodeHandle nh("~");
112 
113  if (getParameters(nh, mapConfig) < 0)
114  {
115  ROS_ERROR("Configuration error. Unable to get required parameters.");
116  exit(1);
117  }
118 
119  // ROS_INFO("Map Name: %s, Ground Topic: %s, Nonground Topic: %s, Odom Sub Topic: %s, Marker Topic: %s, "
120  // "Output Topic: %s, Frame Id: %s, Filter NS: %s, Len: %f, Res: %f",
121  // mapConfig.mapName.c_str(), mapConfig.groundPointSubTopic.c_str(),
122  // mapConfig.nonGroundPointSubTopic.c_str(), mapConfig.odomSubTopic.c_str(), mapConfig.markerSubTopic.c_str(),
123  // mapConfig.occupancyOutputTopic.c_str(), mapConfig.frameId.c_str(),
124  // mapConfig.filterNs.c_str(), mapConfig.len.x(), mapConfig.resolution);
125 
126  mitre_fast_layered_map::SensorMap sensorMap(&nh, mapConfig);
127 
128  if (sensorMap.init() < 0)
129  {
130  ROS_ERROR("Unable to initialize map. Exiting...");
131  exit(-1);
132  }
133 
134  ros::Rate rate(10);
135 
136  while(ros::ok())
137  {
138  if(sensorMap.once() != 0)
139  {
140  ROS_WARN_THROTTLE(1, "Map unable to publish.");
141  }
142  rate.sleep();
143  ros::spinOnce();
144  }
145 }
#define ROS_WARN_THROTTLE(rate,...)
std::string obstacleFilterNs
Filter chain for filtering sensor data into obstacles.
Definition: sensor_map.hpp:65
int getParameters(ros::NodeHandle _nh, mitre_fast_layered_map::MapConfiguration &_mapConfig)
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
std::string nonGroundPointSubTopic
Ros topic with nonground (obstacle) points.
Definition: sensor_map.hpp:40
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
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
int main(int argc, char **argv)
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
double footPrintLen
Length of robot.
Definition: sensor_map.hpp:61
double resolution
Cell size of map.
Definition: sensor_map.hpp:52
bool param(const std::string &param_name, T &param_val, const T &default_val) const
std::string occupancyOutputTopic
Topic the occupancy map should be output on.
Definition: sensor_map.hpp:45
ROSCPP_DECL bool ok()
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
double maxPointHeight
If height filter is enabled, filter points more than this height above vehicle.
Definition: sensor_map.hpp:69
bool sleep()
bool getParam(const std::string &key, std::string &s) const
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
std::string mapOperationsFilterNs
Filter chain for map operations after obstacles have been determined.
Definition: sensor_map.hpp:66
ROSCPP_DECL void spinOnce()
std::string markerSubTopic
Ros topic to recieve obstacles from other sources.
Definition: sensor_map.hpp:43
#define ROS_ERROR(...)
Eigen::Array2d Length
std::string mapName
Name that will refer to this instance of map.
Definition: sensor_map.hpp:49


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