35 #include <nav_msgs/OccupancyGrid.h> 36 #include <sensor_msgs/PointCloud2.h> 53 nav_msgs::OccupancyGrid
map_;
68 std::vector<costmap_cspace::PointcloudAccumurator<sensor_msgs::PointCloud2>>
accums_;
78 pnh_.
param(
"z_min", z_min_, 0.1);
79 pnh_.
param(
"z_max", z_max_, 1.0);
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);
88 pub_map_ = neonavigation_common::compat::advertise<nav_msgs::OccupancyGrid>(
90 pnh_,
"map", 1,
true);
91 sub_cloud_ = nh_.subscribe<sensor_msgs::PointCloud2>(
94 sub_cloud_single_ = nh_.subscribe<sensor_msgs::PointCloud2>(
95 "cloud_singleshot", 100,
99 pnh_.param(
"width", width_param, 30);
100 height_ = width_ = width_param;
104 pnh_.param(
"resolution", resolution, 0.1);
105 map_.info.resolution = resolution;
108 map_.data.resize(map_.info.width * map_.info.height);
111 pnh_.param(
"hz", hz, 1.0);
116 void cbCloud(
const sensor_msgs::PointCloud2::ConstPtr& cloud,
const bool singleshot)
118 sensor_msgs::PointCloud2 cloud_global;
119 geometry_msgs::TransformStamped trans;
132 const int buffer = singleshot ? 1 : 0;
134 cloud_global, cloud_global.header.stamp));
137 if (published_ + publish_interval_ > now)
147 auto pos = trans.getOrigin();
148 float x =
static_cast<int>(pos.x() / map_.info.resolution) * map_.info.resolution;
149 float y = static_cast<int>(pos.y() / map_.info.resolution) * map_.info.resolution;
150 map_.info.origin.position.x = x - map_.info.width * map_.info.resolution * 0.5;
151 map_.info.origin.position.y =
y - map_.info.height * map_.info.resolution * 0.5;
152 map_.info.origin.position.z = 0.0;
153 map_.info.origin.orientation.w = 1.0;
154 origin_x_ = x - width_ * map_.info.resolution * 0.5;
155 origin_y_ =
y - height_ * map_.info.resolution * 0.5;
163 for (
auto& cell : map_.data)
166 for (
auto& accum : accums_)
168 for (
auto& pc : accum)
173 for (; iter_x != iter_x.
end(); ++iter_x, ++iter_y, ++iter_z)
175 if (*iter_z - robot_z < z_min_ || z_max_ < *iter_z - robot_z)
177 unsigned int x = int(
178 (*iter_x - map_.info.origin.position.x) / map_.info.resolution);
179 unsigned int y = int(
180 (*iter_y - map_.info.origin.position.y) / map_.info.resolution);
181 if (x >= map_.info.width || y >= map_.info.height)
183 map_.data[x + y * map_.info.width] = 100;
192 int main(
int argc,
char** argv)
194 ros::init(argc, argv,
"pointcloud2_to_map");
std::vector< costmap_cspace::PointcloudAccumurator< sensor_msgs::PointCloud2 > > accums_
void publish(const boost::shared_ptr< M > &message) const
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)
nav_msgs::OccupancyGrid map_
TFSIMD_FORCE_INLINE const tfScalar & y() const
ROSCPP_DECL void spin(Spinner &spinner)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
std::string global_frame_
void fromMsg(const A &, B &b)
ros::Subscriber sub_cloud_single_
void cbCloud(const sensor_msgs::PointCloud2::ConstPtr &cloud, const bool singleshot)
TFSIMD_FORCE_INLINE const tfScalar & x() const
ros::Duration publish_interval_
int main(int argc, char **argv)
ros::Subscriber sub_cloud_
PointCloud2Iterator< T > end() const
tf2_ros::TransformListener tfl_