-
Notifications
You must be signed in to change notification settings - Fork 303
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
Fix exclusive hardware control mode switching on controller failed activation #1522
Open
saikishor
wants to merge
16
commits into
ros-controls:master
Choose a base branch
from
saikishor:fix/exclusive_hw_interface_switching
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
caef921
added an actuator interface with exclusive interface handling
c4c601d
ran precommit
992b9f5
renamed into test_actuator_exclusive_interfaces
1b218a0
formatting fix
e93dff2
added a test controller that fails at activation
eb2fc5c
forgot to run pre-commit
624a4e2
Fix issues in the setup of the test controller that fails on activate
saikishor 6c322fe
Added test to reproduce the failure of switching with exclusive inter…
saikishor 0ee3e31
Throw an exception when requesting already claimed exclusive interface
saikishor 1757b41
add the perform switching logic to fix the issue with exclusive inter…
saikishor c638e40
remove the scoping
saikishor fd36abf
Collect all failed activated controllers and perform command switch a…
saikishor 886d5dd
added some documentation about the determinism
saikishor f04b680
add naming changes from state to lifecycle_state
saikishor 547df98
Merge branch 'master' into fix/exclusive_hw_interface_switching
christophfroehlich 3a19634
Merge branch 'master' into fix/exclusive_hw_interface_switching
christophfroehlich 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
66 changes: 66 additions & 0 deletions
66
controller_manager/test/test_controller_failed_activate/test_controller_failed_activate.cpp
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,66 @@ | ||
// Copyright 2021 Department of Engineering Cybernetics, NTNU. | ||
// | ||
// 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 "test_controller_failed_activate.hpp" | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "lifecycle_msgs/msg/transition.hpp" | ||
|
||
namespace test_controller_failed_activate | ||
{ | ||
TestControllerFailedActivate::TestControllerFailedActivate() | ||
: controller_interface::ControllerInterface() | ||
{ | ||
} | ||
|
||
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn | ||
TestControllerFailedActivate::on_init() | ||
{ | ||
return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS; | ||
} | ||
|
||
controller_interface::return_type TestControllerFailedActivate::update( | ||
const rclcpp::Time & /*time*/, const rclcpp::Duration & /*period*/) | ||
{ | ||
return controller_interface::return_type::OK; | ||
} | ||
|
||
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn | ||
TestControllerFailedActivate::on_configure(const rclcpp_lifecycle::State & /*previous_state&*/) | ||
{ | ||
return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS; | ||
} | ||
|
||
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn | ||
TestControllerFailedActivate::on_activate(const rclcpp_lifecycle::State & /*previous_state&*/) | ||
{ | ||
// Simply simulate a controller that can not be activated | ||
return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::FAILURE; | ||
} | ||
|
||
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn | ||
TestControllerFailedActivate::on_cleanup(const rclcpp_lifecycle::State & /*previous_state*/) | ||
{ | ||
return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS; | ||
} | ||
|
||
} // namespace test_controller_failed_activate | ||
|
||
#include "pluginlib/class_list_macros.hpp" | ||
|
||
PLUGINLIB_EXPORT_CLASS( | ||
test_controller_failed_activate::TestControllerFailedActivate, | ||
controller_interface::ControllerInterface) |
75 changes: 75 additions & 0 deletions
75
controller_manager/test/test_controller_failed_activate/test_controller_failed_activate.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,75 @@ | ||
// Copyright 2020 Department of Engineering Cybernetics, NTNU | ||
// | ||
// 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 TEST_CONTROLLER_FAILED_ACTIVATE__TEST_CONTROLLER_FAILED_ACTIVATE_HPP_ | ||
#define TEST_CONTROLLER_FAILED_ACTIVATE__TEST_CONTROLLER_FAILED_ACTIVATE_HPP_ | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "controller_interface/visibility_control.h" | ||
#include "controller_manager/controller_manager.hpp" | ||
|
||
namespace test_controller_failed_activate | ||
{ | ||
// Corresponds to the name listed within the pluginglib xml | ||
constexpr char TEST_CONTROLLER_WITH_INTERFACES_CLASS_NAME[] = | ||
"controller_manager/test_controller_failed_activate"; | ||
// Corresponds to the command interface to claim | ||
constexpr char TEST_CONTROLLER_COMMAND_INTERFACE[] = "joint2/velocity"; | ||
class TestControllerFailedActivate : public controller_interface::ControllerInterface | ||
{ | ||
public: | ||
CONTROLLER_MANAGER_PUBLIC | ||
TestControllerFailedActivate(); | ||
|
||
CONTROLLER_MANAGER_PUBLIC | ||
virtual ~TestControllerFailedActivate() = default; | ||
|
||
controller_interface::InterfaceConfiguration command_interface_configuration() const override | ||
{ | ||
return controller_interface::InterfaceConfiguration{ | ||
controller_interface::interface_configuration_type::INDIVIDUAL, | ||
{TEST_CONTROLLER_COMMAND_INTERFACE}}; | ||
} | ||
|
||
controller_interface::InterfaceConfiguration state_interface_configuration() const override | ||
{ | ||
return controller_interface::InterfaceConfiguration{ | ||
controller_interface::interface_configuration_type::NONE}; | ||
} | ||
|
||
CONTROLLER_MANAGER_PUBLIC | ||
controller_interface::return_type update( | ||
const rclcpp::Time & time, const rclcpp::Duration & period) override; | ||
|
||
CONTROLLER_MANAGER_PUBLIC | ||
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_init() override; | ||
|
||
CONTROLLER_MANAGER_PUBLIC | ||
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_configure( | ||
const rclcpp_lifecycle::State & previous_state) override; | ||
|
||
CONTROLLER_MANAGER_PUBLIC | ||
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_activate( | ||
const rclcpp_lifecycle::State & previous_state) override; | ||
|
||
CONTROLLER_MANAGER_PUBLIC | ||
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_cleanup( | ||
const rclcpp_lifecycle::State & previous_state) override; | ||
}; | ||
|
||
} // namespace test_controller_failed_activate | ||
|
||
#endif // TEST_CONTROLLER_FAILED_ACTIVATE__TEST_CONTROLLER_FAILED_ACTIVATE_HPP_ |
9 changes: 9 additions & 0 deletions
9
controller_manager/test/test_controller_failed_activate/test_controller_failed_activate.xml
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,9 @@ | ||
<library path="test_controller_failed_activate"> | ||
|
||
<class name="controller_manager/test_controller_failed_activate" type="test_controller_failed_activate::TestControllerFailedActivate" base_class_type="controller_interface::ControllerInterface"> | ||
<description> | ||
Controller used for testing | ||
</description> | ||
</class> | ||
|
||
</library> |
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 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -20,6 +20,7 @@ | |||||||||||
#include "controller_manager/controller_manager.hpp" | ||||||||||||
#include "controller_manager_test_common.hpp" | ||||||||||||
#include "lifecycle_msgs/msg/state.hpp" | ||||||||||||
#include "test_controller_failed_activate/test_controller_failed_activate.hpp" | ||||||||||||
#include "test_controller_with_interfaces/test_controller_with_interfaces.hpp" | ||||||||||||
|
||||||||||||
using ::testing::_; | ||||||||||||
|
@@ -29,6 +30,19 @@ class TestReleaseInterfaces : public ControllerManagerFixture<controller_manager | |||||||||||
{ | ||||||||||||
}; | ||||||||||||
|
||||||||||||
class TestReleaseExclusiveInterfaces | ||||||||||||
: public ControllerManagerFixture<controller_manager::ControllerManager> | ||||||||||||
{ | ||||||||||||
public: | ||||||||||||
TestReleaseExclusiveInterfaces() | ||||||||||||
: ControllerManagerFixture<controller_manager::ControllerManager>( | ||||||||||||
std::string(ros2_control_test_assets::urdf_head) + | ||||||||||||
std::string(ros2_control_test_assets::hardware_resources_with_exclusive_interface) + | ||||||||||||
std::string(ros2_control_test_assets::urdf_tail)) | ||||||||||||
{ | ||||||||||||
} | ||||||||||||
}; | ||||||||||||
|
||||||||||||
TEST_F(TestReleaseInterfaces, switch_controllers_same_interface) | ||||||||||||
{ | ||||||||||||
std::string controller_type = | ||||||||||||
|
@@ -197,3 +211,69 @@ TEST_F(TestReleaseInterfaces, switch_controllers_same_interface) | |||||||||||
abstract_test_controller2.c->get_lifecycle_state().id()); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
TEST_F(TestReleaseExclusiveInterfaces, test_exclusive_interface_switching_failure) | ||||||||||||
{ | ||||||||||||
std::string controller_type = | ||||||||||||
test_controller_failed_activate::TEST_CONTROLLER_WITH_INTERFACES_CLASS_NAME; | ||||||||||||
|
||||||||||||
// Load two controllers of different names | ||||||||||||
std::string controller_name1 = "test_controller1"; | ||||||||||||
std::string controller_name2 = "test_controller2"; | ||||||||||||
ASSERT_NO_THROW(cm_->load_controller(controller_name1, controller_type)); | ||||||||||||
ASSERT_NO_THROW(cm_->load_controller( | ||||||||||||
controller_name2, test_controller_with_interfaces::TEST_CONTROLLER_WITH_INTERFACES_CLASS_NAME)); | ||||||||||||
ASSERT_EQ(2u, cm_->get_loaded_controllers().size()); | ||||||||||||
controller_manager::ControllerSpec abstract_test_controller1 = cm_->get_loaded_controllers()[0]; | ||||||||||||
controller_manager::ControllerSpec abstract_test_controller2 = cm_->get_loaded_controllers()[1]; | ||||||||||||
|
||||||||||||
// Configure controllers | ||||||||||||
ASSERT_EQ(controller_interface::return_type::OK, cm_->configure_controller(controller_name1)); | ||||||||||||
ASSERT_EQ(controller_interface::return_type::OK, cm_->configure_controller(controller_name2)); | ||||||||||||
|
||||||||||||
ASSERT_EQ( | ||||||||||||
lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE, | ||||||||||||
abstract_test_controller1.c->get_lifecycle_state().id()); | ||||||||||||
ASSERT_EQ( | ||||||||||||
lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE, | ||||||||||||
abstract_test_controller2.c->get_lifecycle_state().id()); | ||||||||||||
|
||||||||||||
{ // Test starting the first controller | ||||||||||||
RCLCPP_INFO(cm_->get_logger(), "Starting controller #1"); | ||||||||||||
std::vector<std::string> start_controllers = {controller_name1}; | ||||||||||||
std::vector<std::string> stop_controllers = {}; | ||||||||||||
auto switch_future = std::async( | ||||||||||||
std::launch::async, &controller_manager::ControllerManager::switch_controller, cm_, | ||||||||||||
start_controllers, stop_controllers, STRICT, true, rclcpp::Duration(0, 0)); | ||||||||||||
ASSERT_EQ(std::future_status::timeout, switch_future.wait_for(std::chrono::milliseconds(100))) | ||||||||||||
<< "switch_controller should be blocking until next update cycle"; | ||||||||||||
ControllerManagerRunner cm_runner(this); | ||||||||||||
EXPECT_EQ(controller_interface::return_type::OK, switch_future.get()); | ||||||||||||
ASSERT_EQ( | ||||||||||||
lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE, | ||||||||||||
abstract_test_controller1.c->get_lifecycle_state().id()); | ||||||||||||
ASSERT_EQ( | ||||||||||||
lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE, | ||||||||||||
abstract_test_controller2.c->get_lifecycle_state().id()); | ||||||||||||
} | ||||||||||||
|
||||||||||||
{ // Test starting the second controller when the first is running | ||||||||||||
// Fails as they have the same command interface | ||||||||||||
Comment on lines
+260
to
+261
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
RCLCPP_INFO(cm_->get_logger(), "Starting controller #2"); | ||||||||||||
std::vector<std::string> start_controllers = {controller_name2}; | ||||||||||||
std::vector<std::string> stop_controllers = {}; | ||||||||||||
auto switch_future = std::async( | ||||||||||||
std::launch::async, &controller_manager::ControllerManager::switch_controller, cm_, | ||||||||||||
start_controllers, stop_controllers, STRICT, true, rclcpp::Duration(0, 0)); | ||||||||||||
ASSERT_EQ(std::future_status::timeout, switch_future.wait_for(std::chrono::milliseconds(100))) | ||||||||||||
<< "switch_controller should be blocking until next update cycle"; | ||||||||||||
ControllerManagerRunner cm_runner(this); | ||||||||||||
EXPECT_EQ(controller_interface::return_type::OK, switch_future.get()); | ||||||||||||
ASSERT_EQ( | ||||||||||||
lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE, | ||||||||||||
abstract_test_controller1.c->get_lifecycle_state().id()); | ||||||||||||
ASSERT_EQ( | ||||||||||||
lifecycle_msgs::msg::State::PRIMARY_STATE_ACTIVE, | ||||||||||||
abstract_test_controller2.c->get_lifecycle_state().id()); | ||||||||||||
} | ||||||||||||
} |
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
Oops, something went wrong.
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.
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.