-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Ensure that plugin initialization to be called before updating routines #3307
Merged
SteveMacenski
merged 1 commit into
ros-navigation:main
from
AlexeyMerzlyakov:costmap_plugin_api_order_fix
Dec 6, 2022
Merged
Changes from all commits
Commits
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 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 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 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 |
---|---|---|
@@ -1,4 +1,24 @@ | ||
# Bresenham2D corner cases test | ||
ament_add_gtest(costmap_bresenham_2d costmap_bresenham_2d.cpp) | ||
target_link_libraries(costmap_bresenham_2d | ||
nav2_costmap_2d_core | ||
) | ||
|
||
# OrderLayer for checking Costmap2D plugins API calling order | ||
add_library(order_layer SHARED | ||
order_layer.cpp) | ||
ament_target_dependencies(order_layer | ||
${dependencies} | ||
) | ||
install(TARGETS | ||
order_layer | ||
ARCHIVE DESTINATION lib | ||
LIBRARY DESTINATION lib | ||
RUNTIME DESTINATION bin | ||
) | ||
|
||
# Costmap2D plugins API calling order test | ||
ament_add_gtest(plugin_api_order plugin_api_order.cpp) | ||
target_link_libraries(plugin_api_order | ||
nav2_costmap_2d_core | ||
) |
This file contains 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,60 @@ | ||
// Copyright (c) 2022 Samsung R&D Institute Russia | ||
// | ||
// 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. Reserved. | ||
|
||
#include "order_layer.hpp" | ||
|
||
#include <chrono> | ||
#include <stdexcept> | ||
|
||
using namespace std::chrono_literals; | ||
|
||
namespace nav2_costmap_2d | ||
{ | ||
|
||
OrderLayer::OrderLayer() | ||
: activated_(false) | ||
{ | ||
} | ||
|
||
void OrderLayer::activate() | ||
{ | ||
std::this_thread::sleep_for(100ms); | ||
activated_ = true; | ||
} | ||
|
||
void OrderLayer::deactivate() | ||
{ | ||
activated_ = false; | ||
} | ||
|
||
void OrderLayer::updateBounds( | ||
double, double, double, double *, double *, double *, double *) | ||
{ | ||
if (!activated_) { | ||
throw std::runtime_error("update before activated"); | ||
} | ||
} | ||
|
||
void OrderLayer::updateCosts( | ||
nav2_costmap_2d::Costmap2D &, int, int, int, int) | ||
{ | ||
if (!activated_) { | ||
throw std::runtime_error("update before activated"); | ||
} | ||
} | ||
|
||
} // namespace nav2_costmap_2d | ||
|
||
#include "pluginlib/class_list_macros.hpp" | ||
PLUGINLIB_EXPORT_CLASS(nav2_costmap_2d::OrderLayer, nav2_costmap_2d::Layer) |
This file contains 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,46 @@ | ||
// Copyright (c) 2022 Samsung R&D Institute Russia | ||
// | ||
// 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. Reserved. | ||
|
||
#ifndef NAV2_COSTMAP_2D__ORDER_LAYER_HPP_ | ||
#define NAV2_COSTMAP_2D__ORDER_LAYER_HPP_ | ||
|
||
#include "nav2_costmap_2d/layer.hpp" | ||
|
||
namespace nav2_costmap_2d | ||
{ | ||
|
||
class OrderLayer : public nav2_costmap_2d::Layer | ||
{ | ||
public: | ||
OrderLayer(); | ||
|
||
virtual void activate(); | ||
virtual void deactivate(); | ||
|
||
virtual void reset() {} | ||
virtual bool isClearable() {return false;} | ||
|
||
virtual void updateBounds( | ||
double, double, double, double *, double *, double *, double *); | ||
|
||
virtual void updateCosts( | ||
nav2_costmap_2d::Costmap2D &, int, int, int, int); | ||
|
||
private: | ||
bool activated_; | ||
}; | ||
|
||
} // namespace nav2_costmap_2d | ||
|
||
#endif // NAV2_COSTMAP_2D__ORDER_LAYER_HPP_ |
This file contains 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,7 @@ | ||
<class_libraries> | ||
<library path="order_layer"> | ||
<class type="nav2_costmap_2d::OrderLayer" base_class_type="nav2_costmap_2d::Layer"> | ||
<description>Plugin checking order of activate() and updateBounds()/updateCosts() calls</description> | ||
</class> | ||
</library> | ||
</class_libraries> |
This file contains 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,53 @@ | ||
// Copyright (c) 2022 Samsung R&D Institute Russia | ||
// | ||
// 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. Reserved. | ||
|
||
#include <string> | ||
#include <vector> | ||
#include <memory> | ||
|
||
#include <nav2_costmap_2d/costmap_2d_ros.hpp> | ||
#include <gtest/gtest.h> | ||
|
||
TEST(CostmapPluginsTester, checkPluginAPIOrder) | ||
{ | ||
std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros = | ||
std::make_shared<nav2_costmap_2d::Costmap2DROS>("costmap_ros"); | ||
|
||
// Workaround to avoid setting base_link->map transform | ||
costmap_ros->set_parameter(rclcpp::Parameter("robot_base_frame", "map")); | ||
// Specifying order verification plugin in the parameters | ||
std::vector<std::string> plugins_str; | ||
plugins_str.push_back("order_layer"); | ||
costmap_ros->set_parameter(rclcpp::Parameter("plugins", plugins_str)); | ||
costmap_ros->declare_parameter( | ||
"order_layer.plugin", | ||
rclcpp::ParameterValue(std::string("nav2_costmap_2d::OrderLayer"))); | ||
|
||
// Do actual test: ensure that plugin->updateBounds()/updateCosts() | ||
// will be called after plugin->activate() | ||
costmap_ros->on_configure(costmap_ros->get_current_state()); | ||
costmap_ros->on_activate(costmap_ros->get_current_state()); | ||
|
||
// Do cleanup | ||
costmap_ros->on_deactivate(costmap_ros->get_current_state()); | ||
costmap_ros->on_cleanup(costmap_ros->get_current_state()); | ||
costmap_ros->on_shutdown(costmap_ros->get_current_state()); | ||
} | ||
|
||
int main(int argc, char ** argv) | ||
{ | ||
rclcpp::init(argc, argv); | ||
testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a good way, this change should be checked through
std::atomic<bool>
, as well as other parallel accessed variables, such asinitialized_
(https://github.com/ros-planning/navigation2/blob/main/nav2_costmap_2d/src/costmap_2d_ros.cpp#L494 and https://github.com/ros-planning/navigation2/blob/main/nav2_costmap_2d/src/costmap_2d_ros.cpp#L527). This is rather a subject of separate ticket, I think.