Skip to content

Commit 7c06d54

Browse files
author
Tiago Silva
authored
cherry-picked melodic fix #200 (#201)
1 parent 14e7f5e commit 7c06d54

File tree

4 files changed

+44
-16
lines changed

4 files changed

+44
-16
lines changed

include/spatio_temporal_voxel_layer/spatio_temporal_voxel_grid.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
// STL
4949
#include <math.h>
5050
#include <unordered_map>
51+
#include <unordered_set>
5152
#include <ctime>
5253
#include <iostream>
5354
#include <utility>
@@ -131,7 +132,8 @@ class SpatioTemporalVoxelGrid
131132
// Core making and clearing functions
132133
void Mark(const std::vector<observation::MeasurementReading>& marking_observations);
133134
void operator()(const observation::MeasurementReading& obs) const;
134-
void ClearFrustums(const std::vector<observation::MeasurementReading>& clearing_observations);
135+
void ClearFrustums(const std::vector<observation::MeasurementReading>& clearing_observations, \
136+
std::unordered_set<occupany_cell>& cleared_cells);
135137

136138
// Get the pointcloud of the underlying occupancy grid
137139
void GetOccupancyPointCloud(sensor_msgs::PointCloud2::Ptr& pc2);
@@ -158,7 +160,8 @@ class SpatioTemporalVoxelGrid
158160
double GetTemporalClearingDuration(const double& time_delta);
159161
double GetFrustumAcceleration(const double& time_delta, \
160162
const double& acceleration_factor);
161-
void TemporalClearAndGenerateCostmap(std::vector<frustum_model>& frustums);
163+
void TemporalClearAndGenerateCostmap(std::vector<frustum_model>& frustums, \
164+
std::unordered_set<occupany_cell>& cleared_cells);
162165

163166
// Populate the costmap ROS api and pointcloud with a marked point
164167
void PopulateCostmapAndPointcloud(const openvdb::Coord& pt);

include/spatio_temporal_voxel_layer/spatio_temporal_voxel_layer.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ class SpatioTemporalVoxelLayer : public costmap_2d::CostmapLayer
114114
void ObservationsResetAfterReading() const;
115115

116116
// Functions to interact with maps
117-
void UpdateROSCostmap(double* min_x, double* min_y, double* max_x, double* max_y);
117+
void UpdateROSCostmap(double* min_x, double* min_y, double* max_x, double* max_y, \
118+
std::unordered_set<volume_grid::occupany_cell>& cleared_cells);
118119
bool updateFootprint(double robot_x, double robot_y, double robot_yaw, \
119120
double* min_x, double* min_y, double* max_x, double* max_y);
120121
void ResetGrid(void);

src/spatio_temporal_voxel_grid.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ void SpatioTemporalVoxelGrid::InitializeGrid(void)
9898
}
9999

100100
/*****************************************************************************/
101-
void SpatioTemporalVoxelGrid::ClearFrustums(const \
102-
std::vector<observation::MeasurementReading>& clearing_readings)
101+
void SpatioTemporalVoxelGrid::ClearFrustums( \
102+
const std::vector<observation::MeasurementReading>& clearing_readings, \
103+
std::unordered_set<occupany_cell>& cleared_cells)
103104
/*****************************************************************************/
104105
{
105106
boost::unique_lock<boost::mutex> lock(_grid_lock);
@@ -117,7 +118,7 @@ void SpatioTemporalVoxelGrid::ClearFrustums(const \
117118

118119
if(clearing_readings.size() == 0)
119120
{
120-
TemporalClearAndGenerateCostmap(obs_frustums);
121+
TemporalClearAndGenerateCostmap(obs_frustums, cleared_cells);
121122
return;
122123
}
123124

@@ -156,13 +157,14 @@ void SpatioTemporalVoxelGrid::ClearFrustums(const \
156157
frustum->TransformModel();
157158
obs_frustums.emplace_back(frustum, it->_decay_acceleration);
158159
}
159-
TemporalClearAndGenerateCostmap(obs_frustums);
160+
TemporalClearAndGenerateCostmap(obs_frustums, cleared_cells);
160161
return;
161162
}
162163

163164
/*****************************************************************************/
164165
void SpatioTemporalVoxelGrid::TemporalClearAndGenerateCostmap( \
165-
std::vector<frustum_model>& frustums)
166+
std::vector<frustum_model>& frustums, \
167+
std::unordered_set<occupany_cell>& cleared_cells)
166168
/*****************************************************************************/
167169
{
168170
// sample time once for all clearing readings
@@ -173,9 +175,11 @@ void SpatioTemporalVoxelGrid::TemporalClearAndGenerateCostmap( \
173175
for (cit_grid; cit_grid.test(); ++cit_grid)
174176
{
175177
const openvdb::Coord pt_index(cit_grid.getCoord());
178+
const openvdb::Vec3d pose_world = this->IndexToWorld(pt_index);
176179

177180
std::vector<frustum_model>::iterator frustum_it = frustums.begin();
178181
bool frustum_cycle = false;
182+
bool cleared_point = false;
179183

180184
const double time_since_marking = cur_time - cit_grid.getValue();
181185
const double base_duration_to_decay = GetTemporalClearingDuration( \
@@ -188,7 +192,7 @@ void SpatioTemporalVoxelGrid::TemporalClearAndGenerateCostmap( \
188192
continue;
189193
}
190194

191-
if ( frustum_it->frustum->IsInside(this->IndexToWorld(pt_index)) )
195+
if ( frustum_it->frustum->IsInside(pose_world) )
192196
{
193197
frustum_cycle = true;
194198

@@ -200,10 +204,12 @@ void SpatioTemporalVoxelGrid::TemporalClearAndGenerateCostmap( \
200204
if (time_until_decay < 0.)
201205
{
202206
// expired by acceleration
207+
cleared_point = true;
203208
if(!this->ClearGridPoint(pt_index))
204209
{
205210
std::cout << "Failed to clear point." << std::endl;
206211
}
212+
break;
207213
}
208214
else
209215
{
@@ -224,15 +230,23 @@ void SpatioTemporalVoxelGrid::TemporalClearAndGenerateCostmap( \
224230
if (base_duration_to_decay < 0.)
225231
{
226232
// expired by temporal clearing
233+
cleared_point = true;
227234
if(!this->ClearGridPoint(pt_index))
228235
{
229236
std::cout << "Failed to clear point." << std::endl;
230237
}
231-
continue;
232238
}
233239
}
234-
// if here, we can add to costmap and PC2
235-
PopulateCostmapAndPointcloud(pt_index);
240+
241+
if (cleared_point)
242+
{
243+
cleared_cells.insert(occupany_cell(pose_world[0], pose_world[1]));
244+
}
245+
else
246+
{
247+
// if here, we can add to costmap and PC2
248+
PopulateCostmapAndPointcloud(pt_index);
249+
}
236250
}
237251
}
238252

src/spatio_temporal_voxel_layer.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,10 @@ void SpatioTemporalVoxelLayer::updateCosts( \
679679
}
680680

681681
/*****************************************************************************/
682-
void SpatioTemporalVoxelLayer::UpdateROSCostmap(double* min_x, double* min_y, \
683-
double* max_x, double* max_y)
682+
void SpatioTemporalVoxelLayer::UpdateROSCostmap( \
683+
double* min_x, double* min_y, \
684+
double* max_x, double* max_y, \
685+
std::unordered_set<volume_grid::occupany_cell>& cleared_cells)
684686
/*****************************************************************************/
685687
{
686688
// grabs map of occupied cells from grid and adds to costmap_
@@ -698,6 +700,12 @@ void SpatioTemporalVoxelLayer::UpdateROSCostmap(double* min_x, double* min_y, \
698700
touch(it->first.x, it->first.y, min_x, min_y, max_x, max_y);
699701
}
700702
}
703+
704+
std::unordered_set<volume_grid::occupany_cell>::iterator cell;
705+
for (cell = cleared_cells.begin(); cell != cleared_cells.end(); ++cell)
706+
{
707+
touch(cell->x, cell->y, min_x, min_y, max_x, max_y);
708+
}
701709
}
702710

703711
/*****************************************************************************/
@@ -733,10 +741,12 @@ void SpatioTemporalVoxelLayer::updateBounds( \
733741
ObservationsResetAfterReading();
734742
current_ = current;
735743

744+
std::unordered_set<volume_grid::occupany_cell> cleared_cells;
745+
736746
// navigation mode: clear observations, mapping mode: save maps and publish
737747
if (!_mapping_mode)
738748
{
739-
_voxel_grid->ClearFrustums(clearing_observations);
749+
_voxel_grid->ClearFrustums(clearing_observations, cleared_cells);
740750
}
741751
else if (ros::Time::now() - _last_map_save_time > _map_save_duration)
742752
{
@@ -757,7 +767,7 @@ void SpatioTemporalVoxelLayer::updateBounds( \
757767
_voxel_grid->Mark(marking_observations);
758768

759769
// update the ROS Layered Costmap
760-
UpdateROSCostmap(min_x, min_y, max_x, max_y);
770+
UpdateROSCostmap(min_x, min_y, max_x, max_y, cleared_cells);
761771

762772
// publish point cloud in navigation mode
763773
if (_publish_voxels && !_mapping_mode)

0 commit comments

Comments
 (0)