56 void NonPersistentVoxelLayer::onInitialize()
58 ObstacleLayer::onInitialize();
61 private_nh.
param(
"publish_voxel_map", publish_voxel_,
false);
62 private_nh.
param(
"footprint_clearing_enabled", footprint_clearing_enabled_,
true);
64 voxel_pub_ = private_nh.
advertise < costmap_2d::VoxelGrid > (
"voxel_grid", 1);
69 voxel_dsrv_ =
new dynamic_reconfigure::Server<costmap_2d::NonPersistentVoxelPluginConfig>(nh);
70 dynamic_reconfigure::Server<costmap_2d::NonPersistentVoxelPluginConfig>::CallbackType cb = boost::bind(
71 &NonPersistentVoxelLayer::reconfigureCB,
this, _1, _2);
72 voxel_dsrv_->setCallback(cb);
75 NonPersistentVoxelLayer::~NonPersistentVoxelLayer()
81 void NonPersistentVoxelLayer::reconfigureCB(costmap_2d::NonPersistentVoxelPluginConfig &config, uint32_t level)
83 enabled_ = config.enabled;
84 max_obstacle_height_ = config.max_obstacle_height;
85 size_z_ = config.z_voxels;
86 origin_z_ = config.origin_z;
87 z_resolution_ = config.z_resolution;
88 unknown_threshold_ = config.unknown_threshold + (
VOXEL_BITS - size_z_);
89 mark_threshold_ = config.mark_threshold;
90 combination_method_ = config.combination_method;
94 void NonPersistentVoxelLayer::updateFootprint(
double robot_x,
double robot_y,
double robot_yaw,
double* min_x,
double* min_y,
95 double* max_x,
double* max_y)
97 if (!footprint_clearing_enabled_)
99 transformFootprint(robot_x, robot_y, robot_yaw, getFootprint(), transformed_footprint_);
101 for (
unsigned int i = 0; i < transformed_footprint_.size(); i++)
103 touch(transformed_footprint_[i].
x, transformed_footprint_[i].
y, min_x, min_y, max_x, max_y);
110 void NonPersistentVoxelLayer::matchSize()
112 ObstacleLayer::matchSize();
113 voxel_grid_.resize(size_x_, size_y_, size_z_);
114 ROS_ASSERT(voxel_grid_.sizeX() == size_x_ && voxel_grid_.sizeY() == size_y_);
117 void NonPersistentVoxelLayer::reset()
125 void NonPersistentVoxelLayer::resetMaps()
127 Costmap2D::resetMaps();
131 void NonPersistentVoxelLayer::updateBounds(
double robot_x,
double robot_y,
double robot_yaw,
double* min_x,
132 double* min_y,
double* max_x,
double* max_y)
137 updateOrigin(robot_x - getSizeInMetersX() / 2, robot_y - getSizeInMetersY() / 2);
148 useExtraBounds(min_x, min_y, max_x, max_y);
152 std::vector<Observation> observations;
153 current = getMarkingObservations(observations) && current;
159 for (std::vector<Observation>::const_iterator it = observations.begin(); it != observations.end(); ++it)
161 const Observation& obs = *it;
163 #if ROS_VERSION_MINIMUM(1,14,0) 165 pcl::PointCloud<pcl::PointXYZ> cloud;
169 const pcl::PointCloud<pcl::PointXYZ>& cloud = *(obs.
cloud_);
174 for (
unsigned int i = 0; i < cloud.points.size(); ++i)
177 if (cloud.points[i].z > max_obstacle_height_)
181 double sq_dist = (cloud.points[i].x - obs.
origin_.x) * (cloud.points[i].x - obs.
origin_.x)
182 + (cloud.points[i].y - obs.
origin_.y) * (cloud.points[i].y - obs.
origin_.y)
183 + (cloud.points[i].z - obs.
origin_.z) * (cloud.points[i].z - obs.
origin_.z);
186 if (sq_dist >= sq_obstacle_range)
190 unsigned int mx, my, mz;
191 if (cloud.points[i].z < origin_z_)
193 if (!worldToMap3D(cloud.points[i].x, cloud.points[i].y, origin_z_, mx, my, mz))
196 else if (!worldToMap3D(cloud.points[i].x, cloud.points[i].y, cloud.points[i].z, mx, my, mz))
202 if (voxel_grid_.markVoxelInMap(mx, my, mz, mark_threshold_))
204 unsigned int index = getIndex(mx, my);
206 costmap_[index] = LETHAL_OBSTACLE;
207 touch((
double)cloud.points[i].x, (
double)cloud.points[i].y, min_x, min_y, max_x, max_y);
214 costmap_2d::VoxelGrid grid_msg;
215 unsigned int size = voxel_grid_.sizeX() * voxel_grid_.sizeY();
216 grid_msg.size_x = voxel_grid_.sizeX();
217 grid_msg.size_y = voxel_grid_.sizeY();
218 grid_msg.size_z = voxel_grid_.sizeZ();
219 grid_msg.data.resize(size);
220 memcpy(&grid_msg.data[0], voxel_grid_.getData(), size *
sizeof(
unsigned int));
222 grid_msg.origin.x = origin_x_;
223 grid_msg.origin.y = origin_y_;
224 grid_msg.origin.z = origin_z_;
226 grid_msg.resolutions.x = resolution_;
227 grid_msg.resolutions.y = resolution_;
228 grid_msg.resolutions.z = z_resolution_;
229 grid_msg.header.frame_id = global_frame_;
231 voxel_pub_.publish(grid_msg);
234 updateFootprint(robot_x, robot_y, robot_yaw, min_x, min_y, max_x, max_y);
237 void NonPersistentVoxelLayer::updateOrigin(
double new_origin_x,
double new_origin_y)
240 int cell_ox, cell_oy;
241 cell_ox = int((new_origin_x - origin_x_) / resolution_);
242 cell_oy = int((new_origin_y - origin_y_) / resolution_);
245 origin_x_ = origin_x_ + cell_ox * resolution_;
246 origin_y_ = origin_y_ + cell_oy * resolution_;
geometry_msgs::Point origin_
pcl::PointCloud< pcl::PointXYZ > * cloud_
PLUGINLIB_EXPORT_CLASS(BAGReader, nodelet::Nodelet)
void fromROSMsg(const sensor_msgs::PointCloud2 &cloud, pcl::PointCloud< T > &pcl_cloud)
TFSIMD_FORCE_INLINE const tfScalar & y() const
static const unsigned char FREE_SPACE
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
TFSIMD_FORCE_INLINE const tfScalar & x() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void transformFootprint(double x, double y, double theta, const std::vector< geometry_msgs::Point > &footprint_spec, std::vector< geometry_msgs::Point > &oriented_footprint)