23 #include "nav2_costmap_2d/costmap_topic_collision_checker.hpp"
25 #include "nav2_costmap_2d/cost_values.hpp"
26 #include "nav2_costmap_2d/exceptions.hpp"
27 #include "nav2_costmap_2d/footprint.hpp"
28 #include "nav2_util/line_iterator.hpp"
30 using namespace std::chrono_literals;
35 CostmapTopicCollisionChecker::CostmapTopicCollisionChecker(
40 costmap_sub_(costmap_sub),
41 footprint_sub_(&footprint_sub),
42 collision_checker_(nullptr)
47 std::string footprint_string,
50 costmap_sub_(costmap_sub),
51 collision_checker_(nullptr)
59 const geometry_msgs::msg::Pose2D & pose,
60 bool fetch_costmap_and_footprint)
63 if (
scorePose(pose, fetch_costmap_and_footprint) >= LETHAL_OBSTACLE) {
68 RCLCPP_ERROR(rclcpp::get_logger(name_),
"%s", e.what());
71 RCLCPP_ERROR(rclcpp::get_logger(name_),
"%s", e.what());
74 RCLCPP_ERROR(rclcpp::get_logger(name_),
"Failed to check pose score!");
80 const geometry_msgs::msg::Pose2D & pose,
81 bool fetch_costmap_and_footprint)
83 if (fetch_costmap_and_footprint) {
85 collision_checker_.setCostmap(costmap_sub_.
getCostmap());
86 }
catch (
const std::runtime_error & e) {
91 unsigned int cell_x, cell_y;
92 if (!collision_checker_.worldToMap(pose.x, pose.y, cell_x, cell_y)) {
93 RCLCPP_DEBUG(rclcpp::get_logger(name_),
"Map Cell: [%d, %d]", cell_x, cell_y);
97 return collision_checker_.footprintCost(
getFootprint(pose, fetch_costmap_and_footprint));
101 const geometry_msgs::msg::Pose2D & pose,
102 bool fetch_latest_footprint)
104 if (fetch_latest_footprint) {
105 std_msgs::msg::Header header;
Exceptions thrown if collision checker determines a pose is in collision with the environment costmap...
Subscribes to the costmap via a ros topic.
std::shared_ptr< Costmap2D > getCostmap()
Get current costmap.
Footprint getFootprint(const geometry_msgs::msg::Pose2D &pose, bool fetch_latest_footprint=true)
Get a footprint at a set pose.
double scorePose(const geometry_msgs::msg::Pose2D &pose, bool fetch_costmap_and_footprint=true)
Returns the obstacle footprint score for a particular pose.
CostmapTopicCollisionChecker(CostmapSubscriber &costmap_sub, FootprintSubscriber &footprint_sub, std::string name="collision_checker")
A constructor.
bool isCollisionFree(const geometry_msgs::msg::Pose2D &pose, bool fetch_costmap_and_footprint=true)
Returns if a pose is collision free.
Thrown when CollisionChecker encounters a fatal error.
void transformFootprint(double x, double y, double theta, const std::vector< geometry_msgs::msg::Point > &footprint_spec, std::vector< geometry_msgs::msg::Point > &oriented_footprint)
Given a pose and base footprint, build the oriented footprint of the robot (list of Points)
bool makeFootprintFromString(const std::string &footprint_string, std::vector< geometry_msgs::msg::Point > &footprint)
Make the footprint from the given string.