voxel_layer.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2008, 2013, Willow Garage, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Willow Garage, Inc. nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  * Author: Eitan Marder-Eppstein
36  * David V. Lu!!
37  *********************************************************************/
38 #ifndef COSTMAP_2D_VOXEL_LAYER_H_
39 #define COSTMAP_2D_VOXEL_LAYER_H_
40 
41 #include <ros/ros.h>
42 #include <costmap_2d/layer.h>
45 #include <costmap_2d/VoxelGrid.h>
46 #include <nav_msgs/OccupancyGrid.h>
47 #include <sensor_msgs/LaserScan.h>
49 #include <sensor_msgs/PointCloud.h>
50 #include <sensor_msgs/PointCloud2.h>
53 #include <dynamic_reconfigure/server.h>
54 #include <costmap_2d/VoxelPluginConfig.h>
56 #include <voxel_grid/voxel_grid.h>
57 
58 namespace costmap_2d
59 {
60 
61 class VoxelLayer : public ObstacleLayer
62 {
63 public:
65  voxel_grid_(0, 0, 0)
66  {
67  costmap_ = NULL; // this is the unsigned char* member of parent class's parent class Costmap2D.
68  }
69 
70  virtual ~VoxelLayer();
71 
72  virtual void onInitialize();
73  virtual void updateBounds(double robot_x, double robot_y, double robot_yaw, double* min_x, double* min_y,
74  double* max_x, double* max_y);
75 
76  void updateOrigin(double new_origin_x, double new_origin_y);
78  {
79  return true;
80  }
81  virtual void matchSize();
82  virtual void reset();
83 
84 
85 protected:
86  virtual void setupDynamicReconfigure(ros::NodeHandle& nh);
87 
88  virtual void resetMaps();
89 
90 private:
91  void reconfigureCB(costmap_2d::VoxelPluginConfig &config, uint32_t level);
92  void clearNonLethal(double wx, double wy, double w_size_x, double w_size_y, bool clear_no_info);
93  virtual void raytraceFreespace(const costmap_2d::Observation& clearing_observation, double* min_x, double* min_y,
94  double* max_x, double* max_y);
95 
96  dynamic_reconfigure::Server<costmap_2d::VoxelPluginConfig> *voxel_dsrv_;
97 
104  sensor_msgs::PointCloud clearing_endpoints_;
105 
106  inline bool worldToMap3DFloat(double wx, double wy, double wz, double& mx, double& my, double& mz)
107  {
108  if (wx < origin_x_ || wy < origin_y_ || wz < origin_z_)
109  return false;
110  mx = ((wx - origin_x_) / resolution_);
111  my = ((wy - origin_y_) / resolution_);
112  mz = ((wz - origin_z_) / z_resolution_);
113  if (mx < size_x_ && my < size_y_ && mz < size_z_)
114  return true;
115 
116  return false;
117  }
118 
119  inline bool worldToMap3D(double wx, double wy, double wz, unsigned int& mx, unsigned int& my, unsigned int& mz)
120  {
121  if (wx < origin_x_ || wy < origin_y_ || wz < origin_z_)
122  return false;
123 
124  mx = (int)((wx - origin_x_) / resolution_);
125  my = (int)((wy - origin_y_) / resolution_);
126  mz = (int)((wz - origin_z_) / z_resolution_);
127 
128  if (mx < size_x_ && my < size_y_ && mz < size_z_)
129  return true;
130 
131  return false;
132  }
133 
134  inline void mapToWorld3D(unsigned int mx, unsigned int my, unsigned int mz, double& wx, double& wy, double& wz)
135  {
136  // returns the center point of the cell
137  wx = origin_x_ + (mx + 0.5) * resolution_;
138  wy = origin_y_ + (my + 0.5) * resolution_;
139  wz = origin_z_ + (mz + 0.5) * z_resolution_;
140  }
141 
142  inline double dist(double x0, double y0, double z0, double x1, double y1, double z1)
143  {
144  return sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0) + (z1 - z0) * (z1 - z0));
145  }
146 };
147 
148 } // namespace costmap_2d
149 
150 #endif // COSTMAP_2D_VOXEL_LAYER_H_
unsigned int unknown_threshold_
Definition: voxel_layer.h:102
sensor_msgs::PointCloud clearing_endpoints_
Definition: voxel_layer.h:104
virtual void resetMaps()
Resets the costmap and static_map to be unknown space.
void clearNonLethal(double wx, double wy, double w_size_x, double w_size_y, bool clear_no_info)
ros::Publisher voxel_pub_
Definition: voxel_layer.h:99
unsigned int size_y_
Definition: costmap_2d.h:422
ros::Publisher clearing_endpoints_pub_
Definition: voxel_layer.h:103
unsigned int mark_threshold_
Definition: voxel_layer.h:102
voxel_grid::VoxelGrid voxel_grid_
Definition: voxel_layer.h:100
Stores an observation in terms of a point cloud and the origin of the source.
Definition: observation.h:46
virtual void matchSize()
Implement this to make this layer match the size of the parent costmap.
Definition: voxel_layer.cpp:95
unsigned int size_x_
Definition: costmap_2d.h:421
double dist(double x0, double y0, double z0, double x1, double y1, double z1)
Definition: voxel_layer.h:142
void mapToWorld3D(unsigned int mx, unsigned int my, unsigned int mz, double &wx, double &wy, double &wz)
Definition: voxel_layer.h:134
virtual void reset()
void updateOrigin(double new_origin_x, double new_origin_y)
Move the origin of the costmap to a new location.... keeping data when it can.
virtual void setupDynamicReconfigure(ros::NodeHandle &nh)
Definition: voxel_layer.cpp:67
virtual void onInitialize()
This is called at the end of initialize(). Override to implement subclass-specific initialization...
Definition: voxel_layer.cpp:55
virtual void updateBounds(double robot_x, double robot_y, double robot_yaw, double *min_x, double *min_y, double *max_x, double *max_y)
This is called by the LayeredCostmap to poll this plugin as to how much of the costmap it needs to up...
bool worldToMap3D(double wx, double wy, double wz, unsigned int &mx, unsigned int &my, unsigned int &mz)
Definition: voxel_layer.h:119
dynamic_reconfigure::Server< costmap_2d::VoxelPluginConfig > * voxel_dsrv_
Definition: voxel_layer.h:96
virtual void raytraceFreespace(const costmap_2d::Observation &clearing_observation, double *min_x, double *min_y, double *max_x, double *max_y)
Clear freespace based on one observation.
unsigned int size_z_
Definition: voxel_layer.h:102
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
bool worldToMap3DFloat(double wx, double wy, double wz, double &mx, double &my, double &mz)
Definition: voxel_layer.h:106
unsigned char * costmap_
Definition: costmap_2d.h:426
void reconfigureCB(costmap_2d::VoxelPluginConfig &config, uint32_t level)
Definition: voxel_layer.cpp:81


costmap_2d
Author(s): Eitan Marder-Eppstein, David V. Lu!!, Dave Hershberger, contradict@gmail.com
autogenerated on Wed Jun 22 2022 02:07:03