Skip to content

Commit

Permalink
[DEX][CostmapTopicCollisionChecker] Alternative constructor footprint
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Doisy <[email protected]>
  • Loading branch information
Guillaume Doisy committed Feb 18, 2025
1 parent 5bb4c76 commit d3f7fc7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ class CostmapTopicCollisionChecker
FootprintSubscriber & footprint_sub,
std::string name = "collision_checker");

/**
* @brief Alternative constructor with a footprint string instead of a subscriber. It needs to be
* defined relative to the robot frame
*/
CostmapTopicCollisionChecker(
CostmapSubscriber & costmap_sub,
std::string footprint_string,
std::string name = "collision_checker");

/**
* @brief A destructor
*/
Expand Down Expand Up @@ -90,10 +99,11 @@ class CostmapTopicCollisionChecker
// Name used for logging
std::string name_;
CostmapSubscriber & costmap_sub_;
FootprintSubscriber & footprint_sub_;
std::shared_ptr<FootprintSubscriber> footprint_sub_;
FootprintCollisionChecker<std::shared_ptr<Costmap2D>> collision_checker_;
rclcpp::Clock::SharedPtr clock_;
Footprint footprint_;
std::string footprint_string_;
};

} // namespace nav2_costmap_2d
Expand Down
22 changes: 19 additions & 3 deletions nav2_costmap_2d/src/costmap_topic_collision_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,21 @@ CostmapTopicCollisionChecker::CostmapTopicCollisionChecker(
std::string name)
: name_(name),
costmap_sub_(costmap_sub),
footprint_sub_(footprint_sub),
footprint_sub_(&footprint_sub),
collision_checker_(nullptr)
{}

CostmapTopicCollisionChecker::CostmapTopicCollisionChecker(
CostmapSubscriber & costmap_sub,
std::string footprint_string,
std::string name)
: name_(name),
costmap_sub_(costmap_sub),
collision_checker_(nullptr)
{
makeFootprintFromString(footprint_string, footprint_);
}

bool CostmapTopicCollisionChecker::isCollisionFree(
const geometry_msgs::msg::Pose2D & pose,
bool fetch_costmap_and_footprint)
Expand Down Expand Up @@ -90,8 +101,13 @@ Footprint CostmapTopicCollisionChecker::getFootprint(
{
if (fetch_latest_footprint) {
std_msgs::msg::Header header;
if (!footprint_sub_.getFootprintInRobotFrame(footprint_, header)) {
throw CollisionCheckerException("Current footprint not available.");

// if footprint_sub_ was not initialized (alternative constructor), we are using the
// footprint built from the footprint_string alternative constructor argument.
if (footprint_sub_) {
if (!footprint_sub_->getFootprintInRobotFrame(footprint_, header)) {
throw CollisionCheckerException("Current footprint not available.");
}
}
}
Footprint footprint;
Expand Down

0 comments on commit d3f7fc7

Please sign in to comment.