-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Rviz tool to get cost of costmap cell #4546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SteveMacenski
merged 11 commits into
ros-navigation:main
from
JatinPatil2003:costmap_cost_srv
Jul 25, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e5cb4b9
Added GetCost srv
JatinPatil2003 aec05ee
Added Service in costmap_2d
JatinPatil2003 462ab7b
Added Rviz tool
JatinPatil2003 de50235
Fixed Styling
JatinPatil2003 3a25582
Fixed Styles and Linting
JatinPatil2003 ccc055f
Fixed Linting
JatinPatil2003 fc6efda
Added Bool use_footprint to srv
JatinPatil2003 0593b24
Added unit test for costmap costcell cost service
JatinPatil2003 2644b47
Fixed unit test script
JatinPatil2003 601bbcf
Added theta, Updated unit test, Updated rviz tool service call logic
JatinPatil2003 5a85be0
Updated requested changes
JatinPatil2003 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| // Copyright (c) 2024 Jatin Patil | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <memory> | ||
| #include <chrono> | ||
|
|
||
| #include <rclcpp/rclcpp.hpp> | ||
| #include "nav2_msgs/srv/get_cost.hpp" | ||
| #include "nav2_costmap_2d/costmap_2d_ros.hpp" | ||
|
|
||
| class RclCppFixture | ||
| { | ||
| public: | ||
| RclCppFixture() {rclcpp::init(0, nullptr);} | ||
| ~RclCppFixture() {rclcpp::shutdown();} | ||
| }; | ||
| RclCppFixture g_rclcppfixture; | ||
|
|
||
| using namespace std::chrono_literals; | ||
|
|
||
| class GetCostServiceTest : public ::testing::Test | ||
| { | ||
| protected: | ||
| void SetUp() override | ||
| { | ||
| costmap_ = std::make_shared<nav2_costmap_2d::Costmap2DROS>("costmap"); | ||
| client_ = costmap_->create_client<nav2_msgs::srv::GetCost>( | ||
| "/costmap/get_cost_costmap"); | ||
| costmap_->on_configure(rclcpp_lifecycle::State()); | ||
| ASSERT_TRUE(client_->wait_for_service(10s)); | ||
| } | ||
|
|
||
| std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_; | ||
| rclcpp::Client<nav2_msgs::srv::GetCost>::SharedPtr client_; | ||
| }; | ||
|
|
||
| TEST_F(GetCostServiceTest, TestWithoutFootprint) | ||
| { | ||
| auto request = std::make_shared<nav2_msgs::srv::GetCost::Request>(); | ||
| request->x = 0.5; | ||
| request->y = 1.0; | ||
| request->use_footprint = false; | ||
|
|
||
| auto result_future = client_->async_send_request(request); | ||
| if (rclcpp::spin_until_future_complete( | ||
| costmap_, | ||
| result_future) == rclcpp::FutureReturnCode::SUCCESS) | ||
|
SteveMacenski marked this conversation as resolved.
|
||
| { | ||
| auto response = result_future.get(); | ||
| EXPECT_GE(response->cost, 0.0) << "Cost is less than 0"; | ||
| EXPECT_LE(response->cost, 255.0) << "Cost is greater than 255"; | ||
| } else { | ||
| FAIL() << "Failed to call service"; | ||
| } | ||
| } | ||
|
|
||
| TEST_F(GetCostServiceTest, TestWithFootprint) | ||
| { | ||
| auto request = std::make_shared<nav2_msgs::srv::GetCost::Request>(); | ||
| request->x = 1.0; | ||
| request->y = 1.0; | ||
| request->theta = 0.5; | ||
| request->use_footprint = true; | ||
|
|
||
| auto result_future = client_->async_send_request(request); | ||
|
SteveMacenski marked this conversation as resolved.
|
||
| if (rclcpp::spin_until_future_complete( | ||
| costmap_, | ||
| result_future) == rclcpp::FutureReturnCode::SUCCESS) | ||
| { | ||
| auto response = result_future.get(); | ||
| EXPECT_GE(response->cost, 0.0) << "Cost is less than 0"; | ||
| EXPECT_LE(response->cost, 255.0) << "Cost is greater than 255"; | ||
| } else { | ||
| FAIL() << "Failed to call service"; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Get costmap cost at given point | ||
|
|
||
| bool use_footprint | ||
| float32 x | ||
| float32 y | ||
|
SteveMacenski marked this conversation as resolved.
|
||
| float32 theta | ||
| --- | ||
| float32 cost | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
nav2_rviz_plugins/include/nav2_rviz_plugins/costmap_cost_tool.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Copyright (c) 2024 Jatin Patil | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #ifndef NAV2_RVIZ_PLUGINS__COSTMAP_COST_TOOL_HPP_ | ||
| #define NAV2_RVIZ_PLUGINS__COSTMAP_COST_TOOL_HPP_ | ||
|
|
||
| #include <nav2_msgs/srv/get_cost.hpp> | ||
| #include <rviz_common/tool.hpp> | ||
| #include <rviz_default_plugins/tools/point/point_tool.hpp> | ||
| #include <rclcpp/rclcpp.hpp> | ||
|
|
||
| namespace nav2_rviz_plugins | ||
| { | ||
| class CostmapCostTool : public rviz_common::Tool | ||
| { | ||
| Q_OBJECT | ||
|
|
||
| public: | ||
| CostmapCostTool(); | ||
| virtual ~CostmapCostTool(); | ||
|
|
||
| void onInitialize() override; | ||
| void activate() override; | ||
| void deactivate() override; | ||
|
|
||
| int processMouseEvent(rviz_common::ViewportMouseEvent & event) override; | ||
|
|
||
| void callCostService(float x, float y); | ||
|
|
||
| void handleLocalCostResponse(rclcpp::Client<nav2_msgs::srv::GetCost>::SharedFuture); | ||
| void handleGlobalCostResponse(rclcpp::Client<nav2_msgs::srv::GetCost>::SharedFuture); | ||
|
|
||
| private Q_SLOTS: | ||
| void updateAutoDeactivate(); | ||
|
|
||
| private: | ||
| rclcpp::Client<nav2_msgs::srv::GetCost>::SharedPtr local_cost_client_; | ||
| rclcpp::Client<nav2_msgs::srv::GetCost>::SharedPtr global_cost_client_; | ||
| rclcpp::Node::SharedPtr node_; | ||
|
|
||
| QCursor std_cursor_; | ||
| QCursor hit_cursor_; | ||
| rviz_common::properties::BoolProperty * auto_deactivate_property_; | ||
| rviz_common::properties::QosProfileProperty * qos_profile_property_; | ||
|
|
||
| rclcpp::QoS qos_profile_; | ||
| }; | ||
|
|
||
| } // namespace nav2_rviz_plugins | ||
|
|
||
| #endif // NAV2_RVIZ_PLUGINS__COSTMAP_COST_TOOL_HPP_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.