Skip to content

Commit

Permalink
Add changes to fix the issue with the spawner
Browse files Browse the repository at this point in the history
  • Loading branch information
saikishor committed Dec 14, 2024
1 parent bdedcf7 commit 43ffcfc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
4 changes: 2 additions & 2 deletions controller_manager/controller_manager/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def main(args=None):
)
if not ret.ok:
node.get_logger().error(
bcolors.FAIL + "Failed to activate controller" + bcolors.ENDC
f"{bcolors.FAIL}Failed to activate controller : {controller_name}{bcolors.ENDC}"
)
return 1

Expand All @@ -279,7 +279,7 @@ def main(args=None):
)
if not ret.ok:
node.get_logger().error(
bcolors.FAIL + "Failed to activate the parsed controllers list" + bcolors.ENDC
f"{bcolors.FAIL}Failed to activate the parsed controllers list : {controller_names}{bcolors.ENDC}"
)
return 1

Expand Down
33 changes: 31 additions & 2 deletions controller_manager/src/controller_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,7 @@ controller_interface::return_type ControllerManager::switch_controller(
to = controllers;

// update the claimed interface controller info
auto switch_result = controller_interface::return_type::OK;
for (auto & controller : to)
{
if (is_controller_active(controller.c))
Expand All @@ -1488,6 +1489,28 @@ controller_interface::return_type ControllerManager::switch_controller(
{
controller.info.claimed_interfaces.clear();
}
if (
std::find(activate_request_.begin(), activate_request_.end(), controller.info.name) !=
activate_request_.end())
{
if (!is_controller_active(controller.c))
{
RCLCPP_ERROR(
get_logger(), "Could not activate controller : '%s'", controller.info.name.c_str());
switch_result = controller_interface::return_type::ERROR;
}
}
if (
std::find(deactivate_request_.begin(), deactivate_request_.end(), controller.info.name) !=
deactivate_request_.end())
{
if (is_controller_active(controller.c))
{
RCLCPP_ERROR(
get_logger(), "Could not deactivate controller : '%s'", controller.info.name.c_str());
switch_result = controller_interface::return_type::ERROR;
}
}
}

// switch lists
Expand All @@ -1497,8 +1520,10 @@ controller_interface::return_type ControllerManager::switch_controller(

clear_requests();

RCLCPP_DEBUG(get_logger(), "Successfully switched controllers");
return controller_interface::return_type::OK;
RCLCPP_DEBUG_EXPRESSION(
get_logger(), switch_result == controller_interface::return_type::OK,
"Successfully switched controllers");
return switch_result;
}

controller_interface::ControllerInterfaceBaseSharedPtr ControllerManager::add_controller_impl(
Expand Down Expand Up @@ -1730,6 +1755,7 @@ void ControllerManager::activate_controllers(
get_logger(),
"Resource conflict for controller '%s'. Command interface '%s' is already claimed.",
controller_name.c_str(), command_interface.c_str());
command_loans.clear();
assignment_successful = false;
break;
}
Expand All @@ -1744,6 +1770,7 @@ void ControllerManager::activate_controllers(
"Caught exception of type : %s while claiming the command interfaces. Can't activate "
"controller '%s': %s",
typeid(e).name(), controller_name.c_str(), e.what());
command_loans.clear();
assignment_successful = false;
break;
}
Expand Down Expand Up @@ -1813,13 +1840,15 @@ void ControllerManager::activate_controllers(
RCLCPP_ERROR(
get_logger(), "Caught exception of type : %s while activating the controller '%s': %s",
typeid(e).name(), controller_name.c_str(), e.what());
controller->release_interfaces();
continue;
}
catch (...)
{
RCLCPP_ERROR(
get_logger(), "Caught unknown exception while activating the controller '%s'",
controller_name.c_str());
controller->release_interfaces();
continue;
}

Expand Down

0 comments on commit 43ffcfc

Please sign in to comment.