Skip to content

Commit 7b40d0a

Browse files
committed
add more fixed for the corner cases
1 parent 49371a7 commit 7b40d0a

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

controller_manager/include/controller_manager/controller_manager.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,13 @@ class ControllerManager : public rclcpp::Node
458458
*
459459
* \param[in] controllers list with controllers.
460460
* \param[in] activation_list list with controllers to activate.
461+
* \param[in] strictness strictness of the controller switching
461462
* \param[out] message describing the result of the check.
462463
* \return return_type::OK if all interfaces are available, otherwise return_type::ERROR.
463464
*/
464465
controller_interface::return_type check_for_interfaces_availability_to_activate(
465466
const std::vector<ControllerSpec> & controllers, const std::vector<std::string> activation_list,
466-
std::string & message);
467+
int strictness, std::string & message);
467468

468469
/**
469470
* @brief Inserts a controller into an ordered list based on dependencies to compute the

controller_manager/src/controller_manager.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,7 +1980,7 @@ controller_interface::return_type ControllerManager::switch_controller_cb(
19801980

19811981
if (
19821982
check_for_interfaces_availability_to_activate(
1983-
controllers, switch_params_.activate_request, message) !=
1983+
controllers, switch_params_.activate_request, strictness, message) !=
19841984
controller_interface::return_type::OK)
19851985
{
19861986
clear_requests();
@@ -2456,7 +2456,7 @@ void ControllerManager::activate_controllers(
24562456
}
24572457
// Now prepare and perform the stop interface switching as this is needed for exclusive
24582458
// interfaces
2459-
if (
2459+
else if (
24602460
!failed_controllers_command_interfaces.empty() &&
24612461
(!resource_manager_->prepare_command_mode_switch({}, failed_controllers_command_interfaces) ||
24622462
!resource_manager_->perform_command_mode_switch({}, failed_controllers_command_interfaces)))
@@ -2963,6 +2963,8 @@ void ControllerManager::manage_switch()
29632963
switch_params_.deactivate_command_interface_request))
29642964
{
29652965
RCLCPP_ERROR(get_logger(), "Error while performing mode switch.");
2966+
// If the hardware switching fails, there is no point in continuing to switch controllers
2967+
return;
29662968
}
29672969
execution_time_.switch_perform_mode_time =
29682970
std::chrono::duration<double, std::micro>(std::chrono::steady_clock::now() - start_time)
@@ -3926,7 +3928,7 @@ void ControllerManager::publish_activity()
39263928

39273929
controller_interface::return_type ControllerManager::check_for_interfaces_availability_to_activate(
39283930
const std::vector<ControllerSpec> & controllers, const std::vector<std::string> activation_list,
3929-
std::string & message)
3931+
int strictness, std::string & message)
39303932
{
39313933
std::vector<std::string> future_unavailable_cmd_interfaces = {};
39323934
for (const auto & controller_name : activation_list)
@@ -3960,7 +3962,9 @@ controller_interface::return_type ControllerManager::check_for_interfaces_availa
39603962
RCLCPP_WARN(get_logger(), "%s", message.c_str());
39613963
return controller_interface::return_type::ERROR;
39623964
}
3963-
if (ros2_control::has_item(future_unavailable_cmd_interfaces, cmd_itf))
3965+
if (
3966+
ros2_control::has_item(future_unavailable_cmd_interfaces, cmd_itf) &&
3967+
strictness == controller_manager_msgs::srv::SwitchController::Request::STRICT)
39643968
{
39653969
message = fmt::format(
39663970
FMT_COMPILE(

controller_manager/test/test_release_interfaces.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ TEST_F(TestReleaseInterfaces, switch_controllers_same_interface)
185185
auto switch_future = std::async(
186186
std::launch::async, &controller_manager::ControllerManager::switch_controller, cm_,
187187
start_controllers, stop_controllers, STRICT, true, rclcpp::Duration(0, 0));
188-
ASSERT_EQ(std::future_status::timeout, switch_future.wait_for(std::chrono::milliseconds(100)))
188+
ASSERT_EQ(std::future_status::ready, switch_future.wait_for(std::chrono::milliseconds(100)))
189189
<< "switch_controller should be blocking until next update cycle";
190190
ControllerManagerRunner cm_runner(this);
191191
EXPECT_EQ(controller_interface::return_type::ERROR, switch_future.get());

0 commit comments

Comments
 (0)