31 #include <nav_msgs/OccupancyGrid.h> 62 pnh_.
param(
"robot_frame", robot_frame_, std::string(
"base_link"));
64 pub_map_ = neonavigation_common::compat::advertise<nav_msgs::OccupancyGrid>(
66 pnh_,
"map", 1,
true);
69 pnh_.param(
"width", width_, 30);
72 pnh_.param(
"hz", hz, 1.0);
81 void cbLargeMap(
const nav_msgs::OccupancyGrid::ConstPtr& msg)
99 nav_msgs::OccupancyGrid map;
100 map.header.frame_id = large_map_->header.frame_id;
102 map.info = large_map_->info;
106 const auto pos = trans.getOrigin();
107 const float x =
static_cast<int>(pos.x() / map.info.resolution) * map.info.resolution;
108 const float y = static_cast<int>(pos.y() / map.info.resolution) * map.info.resolution;
109 map.info.origin.position.x = x - map.info.width * map.info.resolution * 0.5;
110 map.info.origin.position.y =
y - map.info.height * map.info.resolution * 0.5;
111 map.info.origin.position.z = 0.0;
112 map.info.origin.orientation.w = 1.0;
113 map.data.resize(width_ * width_);
116 lroundf((map.info.origin.position.x - large_map_->info.origin.position.x) / map.info.resolution);
118 lroundf((map.info.origin.position.y - large_map_->info.origin.position.y) / map.info.resolution);
122 for (
int x = gx; x < gx +
width_; ++x)
124 const size_t addr = (
y - gy) * width_ + (x - gx);
125 const size_t addr_large =
y * large_map_->info.width + x;
126 if (x < 0 ||
y < 0 ||
127 x >= static_cast<int>(large_map_->info.width) ||
128 y >=
static_cast<int>(large_map_->info.height))
134 map.data[addr] = large_map_->data[addr_large];
143 int main(
int argc,
char** argv)
145 ros::init(argc, argv,
"largemap_to_map");
tf2_ros::TransformListener tfl_
void cbTimer(const ros::TimerEvent &event)
void publish(const boost::shared_ptr< M > &message) const
void cbLargeMap(const nav_msgs::OccupancyGrid::ConstPtr &msg)
ros::Subscriber sub_largemap_
virtual geometry_msgs::TransformStamped lookupTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, const ros::Duration timeout) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
TFSIMD_FORCE_INLINE const tfScalar & y() const
nav_msgs::OccupancyGrid::ConstPtr large_map_
ROSCPP_DECL void spin(Spinner &spinner)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void fromMsg(const A &, B &b)
TFSIMD_FORCE_INLINE const tfScalar & x() const
int main(int argc, char **argv)