32 #include <nav_msgs/OccupancyGrid.h> 34 #include <sensor_msgs/LaserScan.h> 53 nav_msgs::OccupancyGrid
map;
78 pnh_.
param(
"z_min", z_min_, std::numeric_limits<double>::lowest());
79 pnh_.
param(
"z_max", z_max_, std::numeric_limits<double>::max());
80 pnh_.
param(
"global_frame", global_frame_, std::string(
"map"));
81 pnh_.
param(
"robot_frame", robot_frame_, std::string(
"base_link"));
83 double accum_duration;
84 pnh_.
param(
"accum_duration", accum_duration, 1.0);
87 pub_map_ = neonavigation_common::compat::advertise<nav_msgs::OccupancyGrid>(
89 pnh_,
"map", 1,
true);
93 pnh_.param(
"width", width_param, 30);
94 height_ = width_ = width_param;
98 pnh_.param(
"resolution", resolution, 0.1);
99 map.info.resolution = resolution;
102 map.data.resize(map.info.width * map.info.height);
105 pnh_.param(
"hz", hz, 1.0);
110 void cbScan(
const sensor_msgs::LaserScan::ConstPtr& scan)
112 sensor_msgs::PointCloud2 cloud;
113 sensor_msgs::PointCloud2 cloud_global;
118 global_frame_, cloud.header.frame_id, cloud.header.stamp,
ros::Duration(0.5));
126 cloud_global, cloud_global.header.stamp));
129 if (published_ + publish_interval_ > now)
139 auto pos = trans.getOrigin();
140 float x =
static_cast<int>(pos.x() / map.info.resolution) * map.info.resolution;
141 float y = static_cast<int>(pos.y() / map.info.resolution) * map.info.resolution;
142 map.info.origin.position.x = x - map.info.width * map.info.resolution * 0.5;
143 map.info.origin.position.y =
y - map.info.height * map.info.resolution * 0.5;
144 map.info.origin.position.z = 0.0;
145 map.info.origin.orientation.w = 1.0;
146 origin_x_ = x - width_ * map.info.resolution * 0.5;
147 origin_y_ =
y - height_ * map.info.resolution * 0.5;
155 for (
auto& cell : map.data)
158 for (
auto& pc : accum_)
163 for (; itr_x != itr_x.end(); ++itr_x, ++itr_y)
165 if (*itr_z - robot_z < z_min_ || z_max_ < *itr_z - robot_z)
167 unsigned int x = int(
168 (*itr_x - map.info.origin.position.x) / map.info.resolution);
169 unsigned int y = int(
170 (*itr_y - map.info.origin.position.y) / map.info.resolution);
171 if (x >= map.info.width || y >= map.info.height)
173 map.data[x + y * map.info.width] = 100;
181 int main(
int argc,
char** argv)
183 ros::init(argc, argv,
"laserscan_to_map");
void projectLaser(const sensor_msgs::LaserScan &scan_in, sensor_msgs::PointCloud &cloud_out, double range_cutoff=-1.0, int channel_options=channel_option::Default)
void publish(const boost::shared_ptr< M > &message) const
void reset(const ros::Duration &duration)
laser_geometry::LaserProjection projector_
std::string global_frame_
nav_msgs::OccupancyGrid map
int main(int argc, char **argv)
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)
void doTransform(const T &data_in, T &data_out, const geometry_msgs::TransformStamped &transform)
TFSIMD_FORCE_INLINE const tfScalar & y() const
ROSCPP_DECL void spin(Spinner &spinner)
tf2_ros::TransformListener tfl_
costmap_cspace::PointcloudAccumurator< sensor_msgs::PointCloud2 > accum_
ros::Subscriber sub_scan_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void fromMsg(const A &, B &b)
ros::Duration publish_interval_
TFSIMD_FORCE_INLINE const tfScalar & x() const
void cbScan(const sensor_msgs::LaserScan::ConstPtr &scan)
void push(const Points &points)