Skip to content

Commit

Permalink
Merge pull request iris-ua#5 from UbiquityRobotics/feature/set_map
Browse files Browse the repository at this point in the history
[slam2d] Add an interface to set a new occupancy map.
  • Loading branch information
eupedrosa authored Jan 29, 2021
2 parents 673e877 + 68c5fae commit c2931f8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/lama/slam2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ class Slam2D {
inline void resumeMapping()
{ do_mapping_ = true; }

// Switch to a new occupancy map.
// The current maps (occupancy and distance) will be deleted.
// We also assume ownership of the map object.
bool setOccupancyMap(FrequencyOccupancyMap* map);

private:

StrategyPtr makeStrategy(const std::string& name, const VectorXd& parameters);
Expand Down
24 changes: 24 additions & 0 deletions src/slam2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,30 @@ void lama::Slam2D::useCompression(bool compression, const std::string& algorithm
occupancy_map_->useCompression(compression, 60, algorithm);
}

bool lama::Slam2D::setOccupancyMap(FrequencyOccupancyMap* map)
{
if (map == nullptr)
return false;

double l2_max = distance_map_->maxDistance();

delete occupancy_map_;
delete distance_map_;

occupancy_map_ = map;
distance_map_ = new DynamicDistanceMap(map->resolution, map->patch_length);
distance_map_->setMaxDistance(l2_max);

map->visit_all_cells([this, &map](auto& coords){
if (map->isOccupied(coords))
this->distance_map_->addObstacle(coords);
});

distance_map_->update();
return true;
}


lama::Slam2D::StrategyPtr lama::Slam2D::makeStrategy(const std::string& name, const VectorXd& parameters)
{
if (name == "lm"){
Expand Down

0 comments on commit c2931f8

Please sign in to comment.