55 std::string costmap_topic;
56 std::string footprint_topic;
57 std::string costmap_updates_topic;
58 param_nh.
param(
"costmap_topic", costmap_topic, std::string(
"costmap"));
59 param_nh.
param(
"costmap_updates_topic", costmap_updates_topic,
60 std::string(
"costmap_updates"));
62 std::string(
"base_link"));
69 [
this](
const nav_msgs::OccupancyGrid::ConstPtr& msg) {
72 ROS_INFO(
"Waiting for costmap to become available, topic: %s",
73 costmap_topic.c_str());
74 auto costmap_msg = ros::topic::waitForMessage<nav_msgs::OccupancyGrid>(
75 costmap_topic, subscription_nh);
80 subscription_nh.
subscribe<map_msgs::OccupancyGridUpdate>(
81 costmap_updates_topic, 1000,
82 [
this](
const map_msgs::OccupancyGridUpdate::ConstPtr& msg) {
102 "Timed out waiting for transform from %s to %s to become available " 103 "before subscribing to costmap, tf error: %s",
119 unsigned int size_in_cells_x = msg->info.width;
120 unsigned int size_in_cells_y = msg->info.height;
121 double resolution = msg->info.resolution;
122 double origin_x = msg->info.origin.position.x;
123 double origin_y = msg->info.origin.position.y;
125 ROS_DEBUG(
"received full new map, resizing to: %d, %d", size_in_cells_x,
132 std::lock_guard<costmap_2d::Costmap2D::mutex_t> lock(*mutex);
137 ROS_DEBUG(
"full map update, %lu values", costmap_size);
138 for (
size_t i = 0; i < costmap_size && i < msg->data.size(); ++i) {
139 unsigned char cell_cost =
static_cast<unsigned char>(msg->data[i]);
140 costmap_data[i] = cost_translation_table__[cell_cost];
142 ROS_DEBUG(
"map updated, written %lu values", costmap_size);
146 const map_msgs::OccupancyGridUpdate::ConstPtr& msg)
148 ROS_DEBUG(
"received partial map update");
151 if (msg->x < 0 || msg->y < 0) {
152 ROS_ERROR(
"negative coordinates, invalid update. x: %d, y: %d", msg->x,
157 size_t x0 =
static_cast<size_t>(msg->x);
158 size_t y0 =
static_cast<size_t>(msg->y);
159 size_t xn = msg->width + x0;
160 size_t yn = msg->height + y0;
164 std::lock_guard<costmap_2d::Costmap2D::mutex_t> lock(*mutex);
169 if (xn > costmap_xn || x0 > costmap_xn || yn > costmap_yn ||
171 ROS_WARN(
"received update doesn't fully fit into existing map, " 172 "only part will be copied. received: [%lu, %lu], [%lu, %lu] " 173 "map is: [0, %lu], [0, %lu]",
174 x0, xn, y0, yn, costmap_xn, costmap_yn);
180 for (
size_t y = y0;
y < yn &&
y < costmap_yn; ++
y) {
181 for (
size_t x = x0;
x < xn &&
x < costmap_xn; ++
x) {
183 unsigned char cell_cost =
static_cast<unsigned char>(msg->data[i]);
184 costmap_data[idx] = cost_translation_table__[cell_cost];
193 global_pose.setIdentity();
195 robot_pose.setIdentity();
222 "%.4f, global_pose stamp: %.4f, tolerance: %.4f",
228 geometry_msgs::PoseStamped msg;
235 std::array<unsigned char, 256> cost_translation_table;
238 for (
size_t i = 0; i < 256; ++i) {
239 cost_translation_table[i] =
240 static_cast<unsigned char>(1 + (251 * (i - 1)) / 97);
244 cost_translation_table[0] = 0;
245 cost_translation_table[99] = 253;
246 cost_translation_table[100] = 254;
247 cost_translation_table[
static_cast<unsigned char>(-1)] = 255;
249 return cost_translation_table;
std::array< unsigned char, 256 > init_translation_table()
void resizeMap(unsigned int size_x, unsigned int size_y, double resolution, double origin_x, double origin_y)
#define ROS_WARN_THROTTLE(rate,...)
std::string getPrefixParam(ros::NodeHandle &nh)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
static void poseStampedTFToMsg(const Stamped< Pose > &bt, geometry_msgs::PoseStamped &msg)
double transform_tolerance_
timeout before transform errors
geometry_msgs::Pose getRobotPose() const
Get the pose of the robot in the global frame of the costmap.
void updatePartialMap(const map_msgs::OccupancyGridUpdate::ConstPtr &msg)
TFSIMD_FORCE_INLINE const tfScalar & y() const
unsigned char * getCharMap() const
ros::Subscriber costmap_updates_sub_
void updateFullMap(const nav_msgs::OccupancyGrid::ConstPtr &msg)
std::string resolve(const std::string &prefix, const std::string &frame_name)
#define ROS_ERROR_THROTTLE(rate,...)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
TFSIMD_FORCE_INLINE const tfScalar & x() const
unsigned int getSizeInCellsY() const
ros::Subscriber costmap_sub_
std::string robot_base_frame_
The frame_id of the robot base.
unsigned int getSizeInCellsX() const
costmap_2d::Costmap2D costmap_
Costmap2DClient(ros::NodeHandle ¶m_nh, ros::NodeHandle &subscription_nh, const tf::TransformListener *tf_listener)
Contructs client and start listening.
const tf::TransformListener *const tf_
Used for transforming point clouds.
ROSCPP_DECL void spinOnce()
std::string global_frame_
The global frame for the costmap.
unsigned int getIndex(unsigned int mx, unsigned int my) const
static const std::array< unsigned char, 256 > cost_translation_table__