31 #include <geometry_msgs/PolygonStamped.h> 32 #include <nav_msgs/OccupancyGrid.h> 33 #include <sensor_msgs/PointCloud.h> 39 #include <costmap_cspace_msgs/CSpace3D.h> 40 #include <costmap_cspace_msgs/CSpace3DUpdate.h> 60 std::pair<nav_msgs::OccupancyGrid::ConstPtr,
64 const nav_msgs::OccupancyGrid::ConstPtr& msg,
67 if (map->getAngularGrid() <= 0)
70 std::runtime_error(
"ang_resolution is not set.");
77 if (map_buffer_.size() > 0)
79 for (
auto& map : map_buffer_)
81 ROS_INFO(
"%ld buffered costmaps processed", map_buffer_.size());
86 const nav_msgs::OccupancyGrid::ConstPtr& msg,
91 auto map_msg = map->getMap();
92 if (map_msg->info.width < 1 ||
93 map_msg->info.height < 1)
95 map_buffer_.push_back(
96 std::pair<nav_msgs::OccupancyGrid::ConstPtr,
101 map->processMapOverlay(msg);
106 const costmap_cspace_msgs::CSpace3DUpdate::Ptr update)
109 pub_costmap_.
publish<costmap_cspace_msgs::CSpace3D>(*map);
114 const costmap_cspace_msgs::CSpace3DUpdate::Ptr update)
117 pub_costmap_update_.
publish(*update);
124 sensor_msgs::PointCloud pc;
125 pc.header = map.header;
127 for (
size_t yaw = 0; yaw < map.info.angle; yaw++)
129 for (
unsigned int i = 0; i < map.info.width * map.info.height; i++)
131 int gx = i % map.info.width;
132 int gy = i / map.info.width;
133 if (map.data[i + yaw * map.info.width * map.info.height] < 100)
135 geometry_msgs::Point32 p;
136 p.x = gx * map.info.linear_resolution + map.info.origin.position.x;
137 p.y = gy * map.info.linear_resolution + map.info.origin.position.y;
139 pc.points.push_back(p);
146 auto footprint = msg;
148 pub_footprint_.
publish(footprint);
152 const std::string overlay_mode_str)
154 if (overlay_mode_str ==
"overwrite")
158 else if (overlay_mode_str ==
"max")
162 ROS_FATAL(
"Unknown overlay_mode \"%s\"", overlay_mode_str.c_str());
163 throw std::runtime_error(
"Unknown overlay_mode.");
172 pub_costmap_ = neonavigation_common::compat::advertise<costmap_cspace_msgs::CSpace3D>(
174 pnh_,
"costmap", 1,
true);
175 pub_costmap_update_ = neonavigation_common::compat::advertise<costmap_cspace_msgs::CSpace3DUpdate>(
176 nh_,
"costmap_update",
177 pnh_,
"costmap_update", 1,
true);
178 pub_footprint_ = pnh_.advertise<geometry_msgs::PolygonStamped>(
"footprint", 2,
true);
179 pub_debug_ = pnh_.advertise<sensor_msgs::PointCloud>(
"debug", 1,
true);
182 pnh_.param(
"ang_resolution", ang_resolution, 16);
185 if (!pnh_.hasParam(
"footprint"))
187 ROS_FATAL(
"Footprint doesn't specified");
188 throw std::runtime_error(
"Footprint doesn't specified.");
190 pnh_.getParam(
"footprint", footprint_xml);
196 catch (
const std::exception& e)
207 pnh_.param(
"linear_expand", linear_expand, 0.2
f);
208 pnh_.param(
"linear_spread", linear_spread, 0.5
f);
210 root_layer->setFootprint(footprint);
212 if (pnh_.hasParam(
"static_layers"))
215 pnh_.getParam(
"static_layers", layers_xml);
219 ROS_FATAL(
"static_layers parameter must contain at least one layer config.");
221 "Migration from old version:\n" 224 " YOUR_LAYER_NAME:\n" 225 " type: LAYER_TYPE\n" 226 " parameters: values\n" 229 " - name: YOUR_LAYER_NAME\n" 230 " type: LAYER_TYPE\n" 231 " parameters: values\n" 233 throw std::runtime_error(
"layers parameter must contain at least one layer config.");
235 for (
int i = 0; i < layers_xml.
size(); ++i)
237 auto layer_xml = std::pair<std::string, XmlRpc::XmlRpcValue>(
238 layers_xml[i][
"name"], layers_xml[i]);
239 ROS_INFO(
"New static layer: %s", layer_xml.first.c_str());
244 layer_xml.second[
"overlay_mode"]);
246 ROS_WARN(
"overlay_mode of the static layer is not specified. Using MAX mode.");
250 type = std::string(layer_xml.second[
"type"]);
253 ROS_FATAL(
"Layer type is not specified.");
254 throw std::runtime_error(
"Layer type is not specified.");
257 if (!layer_xml.second.hasMember(
"footprint"))
258 layer_xml.second[
"footprint"] = footprint_xml;
262 costmap_->addLayer(layer, overlay_mode);
263 layer->loadConfig(layer_xml.second);
265 sub_map_overlay_.push_back(nh_.subscribe<nav_msgs::OccupancyGrid>(
274 sub_map_ = nh_.subscribe<nav_msgs::OccupancyGrid>(
278 if (pnh_.hasParam(
"layers"))
281 pnh_.getParam(
"layers", layers_xml);
285 ROS_FATAL(
"layers parameter must contain at least one layer config.");
287 "Migration from old version:\n" 290 " YOUR_LAYER_NAME:\n" 291 " type: LAYER_TYPE\n" 292 " parameters: values\n" 295 " - name: YOUR_LAYER_NAME\n" 296 " type: LAYER_TYPE\n" 297 " parameters: values\n" 299 throw std::runtime_error(
"layers parameter must contain at least one layer config.");
301 for (
int i = 0; i < layers_xml.
size(); ++i)
303 auto layer_xml = std::pair<std::string, XmlRpc::XmlRpcValue>(
304 layers_xml[i][
"name"], layers_xml[i]);
305 ROS_INFO(
"New layer: %s", layer_xml.first.c_str());
310 layer_xml.second[
"overlay_mode"]);
312 ROS_WARN(
"overlay_mode of the layer is not specified. Using MAX mode.");
316 type = std::string(layer_xml.second[
"type"]);
319 ROS_FATAL(
"Layer type is not specified.");
320 throw std::runtime_error(
"Layer type is not specified.");
323 if (!layer_xml.second.hasMember(
"footprint"))
324 layer_xml.second[
"footprint"] = footprint_xml;
328 costmap_->addLayer(layer, overlay_mode);
329 layer->loadConfig(layer_xml.second);
331 sub_map_overlay_.push_back(nh_.subscribe<nav_msgs::OccupancyGrid>(
340 std::string overlay_mode_str;
341 pnh_.param(
"overlay_mode", overlay_mode_str, std::string(
"max"));
342 if (overlay_mode_str.compare(
"overwrite") == 0)
344 else if (overlay_mode_str.compare(
"max") == 0)
348 ROS_FATAL(
"Unknown overlay_mode \"%s\"", overlay_mode_str.c_str());
349 throw std::runtime_error(
"Unknown overlay_mode.");
351 ROS_INFO(
"costmap_3d: %s mode", overlay_mode_str.c_str());
354 layer_xml[
"footprint"] = footprint_xml;
355 layer_xml[
"linear_expand"] = linear_expand;
356 layer_xml[
"linear_spread"] = linear_spread;
360 sub_map_overlay_.push_back(nh_.subscribe<nav_msgs::OccupancyGrid>(
368 const geometry_msgs::PolygonStamped footprint_msg = footprint.
toMsg();
369 timer_footprint_ = nh_.createTimer(
375 int main(
int argc,
char* argv[])
void publish(const boost::shared_ptr< M > &message) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
geometry_msgs::PolygonStamped toMsg() const
void cbMapOverlay(const nav_msgs::OccupancyGrid::ConstPtr &msg, const costmap_cspace::Costmap3dLayerBase::Ptr map)
Type const & getType() const
std::vector< ros::Subscriber > sub_map_overlay_
bool cbUpdate(const costmap_cspace::CSpace3DMsg::Ptr map, const costmap_cspace_msgs::CSpace3DUpdate::Ptr update)
ROSCPP_DECL void spin(Spinner &spinner)
ros::Timer timer_footprint_
ros::Publisher pub_debug_
bool cbUpdateStatic(const costmap_cspace::CSpace3DMsg::Ptr map, const costmap_cspace_msgs::CSpace3DUpdate::Ptr update)
std::vector< std::pair< nav_msgs::OccupancyGrid::ConstPtr, costmap_cspace::Costmap3dLayerBase::Ptr > > map_buffer_
uint32_t getNumSubscribers() const
static costmap_cspace::MapOverlayMode getMapOverlayModeFromString(const std::string overlay_mode_str)
std::shared_ptr< CSpace3DMsg > Ptr
ros::Publisher pub_footprint_
void publishDebug(const costmap_cspace_msgs::CSpace3D &map)
costmap_cspace::Costmap3d::Ptr costmap_
std::shared_ptr< Costmap3dLayerBase > Ptr
ros::Publisher pub_costmap_update_
void cbPublishFootprint(const ros::TimerEvent &event, const geometry_msgs::PolygonStamped msg)
void setHandler(Callback cb)
std::shared_ptr< Costmap3d > Ptr
ros::Publisher pub_costmap_
int main(int argc, char *argv[])
static Costmap3dLayerBase::Ptr loadClass(const std::string &name)
void cbMap(const nav_msgs::OccupancyGrid::ConstPtr &msg, const costmap_cspace::Costmap3dLayerBase::Ptr map)