39 #include <costmap_2d/costmap_math.h>
40 #include <pluginlib/class_list_macros.h>
44 using costmap_2d::NO_INFORMATION;
45 using costmap_2d::LETHAL_OBSTACLE;
46 using costmap_2d::FREE_SPACE;
50 RappStaticLayer::RappStaticLayer() : dsrv_(NULL) {}
60 ros::NodeHandle nh(
"~/" + name_), g_nh;
65 std::string map_service;
66 nh.param(
"map_service", map_service, std::string(
"/static_map"));
72 int temp_lethal_threshold, temp_unknown_cost_value;
73 nh.param(
"lethal_cost_threshold", temp_lethal_threshold,
int(100));
74 nh.param(
"unknown_cost_value", temp_unknown_cost_value,
int(-1));
80 ROS_INFO(
"Requesting the map...");
82 ros::ServiceManager srv_manager;
83 std::string host_name;
85 ROS_DEBUG_STREAM(
"COSTMAP calls:\n" << map_service);
87 if (srv_manager.lookupService(map_service,host_name, port_srv)){
88 ros::ServiceClient map_client = nh.serviceClient<nav_msgs::GetMap>(map_service);
91 if (map_client.call(srv))
93 nav_msgs::OccupancyGrid
const new_map = srv.response.map;
95 auto a_ptr=boost::make_shared<::nav_msgs::OccupancyGrid const>(new_map);
98 nav_msgs::OccupancyGridConstPtr
const new_map_occupancy_ptr = a_ptr;
108 ROS_ERROR(
"Costmap2D can not request new map from rapp_map_server");
109 ROS_ERROR_STREAM(
"Requested service:\n"<<map_service);
123 std::string node_name = ros::this_node::getName();
125 ROS_INFO_STREAM(
"Starting rapp_costmap for: " << node_name);
127 ROS_INFO(
"Received a %d X %d map at %f m/pix", getSizeInCellsX(), getSizeInCellsY(), getResolution());
132 ROS_DEBUG(
"Subscribing to updates");
143 dsrv_ =
new dynamic_reconfigure::Server<costmap_2d::GenericPluginConfig>(nh);
144 dynamic_reconfigure::Server<costmap_2d::GenericPluginConfig>::CallbackType cb = boost::bind(
146 dsrv_->setCallback(cb);
149 rapp_platform_ros_communications::Costmap2dRosSrvResponse& res){
151 nav_msgs::OccupancyGrid
const new_map = req.map;
153 auto a_ptr=boost::make_shared<::nav_msgs::OccupancyGrid const>(new_map);
156 nav_msgs::OccupancyGridConstPtr
const new_map_occupancy_ptr = a_ptr;
163 if (config.enabled != enabled_)
165 enabled_ = config.enabled;
175 Costmap2D* master = layered_costmap_->getCostmap();
176 resizeMap(master->getSizeInCellsX(), master->getSizeInCellsY(), master->getResolution(),
177 master->getOriginX(), master->getOriginY());
184 return NO_INFORMATION;
186 return LETHAL_OBSTACLE;
191 return scale * LETHAL_OBSTACLE;
196 unsigned int size_x = new_map->info.width, size_y = new_map->info.height;
198 ROS_DEBUG(
"Received a %d X %d map at %f m/pix", size_x, size_y, new_map->info.resolution);
201 Costmap2D* master = layered_costmap_->getCostmap();
202 if (master->getSizeInCellsX() != size_x ||
203 master->getSizeInCellsY() != size_y ||
204 master->getResolution() != new_map->info.resolution ||
205 master->getOriginX() != new_map->info.origin.position.x ||
206 master->getOriginY() != new_map->info.origin.position.y ||
207 !layered_costmap_->isSizeLocked())
209 ROS_INFO(
"Resizing costmap to %d X %d at %f m/pix", size_x, size_y, new_map->info.resolution);
210 layered_costmap_->resizeMap(size_x, size_y, new_map->info.resolution, new_map->info.origin.position.x,
211 new_map->info.origin.position.y,
true);
212 }
else if(size_x_ != size_x || size_y_ != size_y ||
213 resolution_ != new_map->info.resolution ||
214 origin_x_ != new_map->info.origin.position.x ||
215 origin_y_ != new_map->info.origin.position.y){
219 unsigned int index = 0;
222 for (
unsigned int i = 0; i < size_y; ++i)
224 for (
unsigned int j = 0; j < size_x; ++j)
226 unsigned char value = new_map->data[index];
241 for (
unsigned int y = 0; y < update->height ; y++)
243 unsigned int index_base = (update->y + y) * size_x_;
244 for (
unsigned int x = 0; x < update->width ; x++)
246 unsigned int index = index_base + x + update->x;
276 double* max_x,
double* max_y)
281 useExtraBounds(min_x, min_y, max_x, max_y);
285 mapToWorld(
x_,
y_, mx, my);
286 *min_x = std::min(mx, *min_x);
287 *min_y = std::min(my, *min_y);
290 *max_x = std::max(mx, *max_x);
291 *max_y = std::max(my, *max_y);
301 updateWithTrueOverwrite(master_grid, min_i, min_j, max_i, max_j);
303 updateWithMax(master_grid, min_i, min_j, max_i, max_j);
bool track_unknown_space_
unsigned char lethal_threshold_
virtual void updateBounds(double robot_x, double robot_y, double robot_yaw, double *min_x, double *min_y, double *max_x, double *max_y)
virtual void deactivate()
virtual ~RappStaticLayer()
ros::Subscriber map_update_sub_
std::string global_frame_
The global frame for the costmap.
virtual void updateCosts(costmap_2d::Costmap2D &master_grid, int min_i, int min_j, int max_i, int max_j)
bool incomingUpdateService(rapp_platform_ros_communications::Costmap2dRosSrvRequest &req, rapp_platform_ros_communications::Costmap2dRosSrvResponse &res)
void incomingUpdate(const map_msgs::OccupancyGridUpdateConstPtr &update)
ros::ServiceServer costmap_update_service
unsigned char interpretValue(unsigned char value)
void incomingMap(const nav_msgs::OccupancyGridConstPtr &new_map)
Callback to update the costmap's map from the map_server.
virtual void onInitialize()
bool subscribe_to_updates_
void reconfigureCB(costmap_2d::GenericPluginConfig &config, uint32_t level)
unsigned char unknown_cost_value_
dynamic_reconfigure::Server< costmap_2d::GenericPluginConfig > * dsrv_