Skip to content

Commit

Permalink
Added Bool use_footprint to srv
Browse files Browse the repository at this point in the history
Signed-off-by: Jatin Patil <[email protected]>
  • Loading branch information
JatinPatil2003 committed Jul 23, 2024
1 parent ccc055f commit fc6efda
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
23 changes: 19 additions & 4 deletions nav2_costmap_2d/src/costmap_2d_ros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,13 +828,28 @@ void Costmap2DROS::getCostCallback(
const std::shared_ptr<nav2_msgs::srv::GetCost::Request> request,
const std::shared_ptr<nav2_msgs::srv::GetCost::Response> response)
{
RCLCPP_INFO(
get_logger(), "Received request to get cost at point (%f, %f)", request->x, request->y);
unsigned int mx, my;

auto costmap = layered_costmap_->getCostmap();

unsigned int mx, my;
if (costmap->worldToMap(request->x, request->y, mx, my)) {
if (request->use_footprint) {
geometry_msgs::msg::PoseStamped global_pose;
// get the pose of footprint
if (!getRobotPose(global_pose)) {
RCLCPP_WARN(get_logger(), "Failed to get robot pose");
response->cost = -1.0;
}
RCLCPP_INFO(
get_logger(), "Received request to get cost at point (%f, %f)", global_pose.pose.position.x,
global_pose.pose.position.y);
// Get the cost at the map coordinates
if (costmap->worldToMap(global_pose.pose.position.x, global_pose.pose.position.y, mx, my)) {
auto cost = static_cast<float>(costmap->getCost(mx, my));
response->cost = cost;
}
} else if (costmap->worldToMap(request->x, request->y, mx, my)) {
RCLCPP_INFO(
get_logger(), "Received request to get cost at point (%f, %f)", request->x, request->y);
// Get the cost at the map coordinates
auto cost = static_cast<float>(costmap->getCost(mx, my));
response->cost = cost;
Expand Down
1 change: 1 addition & 0 deletions nav2_msgs/srv/GetCost.srv
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Get costmap cost at given point

bool use_footprint
float32 x
float32 y
---
Expand Down
4 changes: 2 additions & 2 deletions nav2_rviz_plugins/src/costmap_cost_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void CostmapCostTool::handleLocalCostResponse(
{
auto response = future.get();
if (response->cost != -1) {
RCLCPP_INFO(node_->get_logger(), "Local costmap cost: %f", response->cost);
RCLCPP_INFO(node_->get_logger(), "Local costmap cost: %.1f", response->cost);
} else {
RCLCPP_ERROR(node_->get_logger(), "Failed to get local costmap cost");
}
Expand All @@ -126,7 +126,7 @@ void CostmapCostTool::handleGlobalCostResponse(
{
auto response = future.get();
if (response->cost != -1) {
RCLCPP_INFO(node_->get_logger(), "Global costmap cost: %f", response->cost);
RCLCPP_INFO(node_->get_logger(), "Global costmap cost: %.1f", response->cost);
} else {
RCLCPP_ERROR(node_->get_logger(), "Failed to get global costmap cost");
}
Expand Down

0 comments on commit fc6efda

Please sign in to comment.