From 6ac392ea20d40ed65829803a804feceeac114e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20L=C3=BCdtke?= Date: Fri, 13 Nov 2015 13:50:39 +0100 Subject: [PATCH 1/2] Introduce prepareSwitch, replacement of canSwitch RobotHW::prepareSwitch is intended as a substitute for RobotHW::canSwitch. The main reasons for the change are a non-const signature to allow changing state and a more descriptive name. RobotHW::canSwitch will be deprecated in a later ROS distro. --- controller_manager/src/controller_manager.cpp | 2 +- hardware_interface/include/hardware_interface/robot_hw.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/controller_manager/src/controller_manager.cpp b/controller_manager/src/controller_manager.cpp index 20439c064..99a12baf4 100644 --- a/controller_manager/src/controller_manager.cpp +++ b/controller_manager/src/controller_manager.cpp @@ -472,7 +472,7 @@ bool ControllerManager::switchController(const std::vector& start_c return false; } - if (!robot_hw_->canSwitch(start_list, stop_list)) + if (!robot_hw_->prepareSwitch(start_list, stop_list)) { ROS_ERROR("Could not switch controllers. The hardware interface combination for the requested controllers is unfeasible."); stop_request_.clear(); diff --git a/hardware_interface/include/hardware_interface/robot_hw.h b/hardware_interface/include/hardware_interface/robot_hw.h index 8f601695e..aecdd78bf 100644 --- a/hardware_interface/include/hardware_interface/robot_hw.h +++ b/hardware_interface/include/hardware_interface/robot_hw.h @@ -101,9 +101,17 @@ class RobotHW : public InterfaceManager * Check (in non-realtime) if given controllers could be started and stopped from the current state of the RobotHW * with regard to necessary hardware interface switches. Start and stop list are disjoint. * This is just a check, the actual switch is done in doSwitch() + * @deprecated: Implement prepareSwitch() instead */ virtual bool canSwitch(const std::list& /*start_list*/, const std::list& /*stop_list*/) const { return true; } + /** + * Check (in non-realtime) if given controllers could be started and stopped from the current state of the RobotHW + * with regard to necessary hardware interface switches and prepare the switching. Start and stop list are disjoint. + * This handles the check and preparation, the actual switch is commited in doSwitch() + */ + virtual bool prepareSwitch(const std::list& start_list, const std::list& stop_list) { return canSwitch(start_list, stop_list); } + /** * Perform (in non-realtime) all necessary hardware interface switches in order to start and stop the given controllers. * Start and stop list are disjoint. The feasability was checked in canSwitch() beforehand. From d19eeac9a35362322615e7a6fcf6f34af583df55 Mon Sep 17 00:00:00 2001 From: Adolfo Rodriguez Tsouroukdissian Date: Fri, 13 Nov 2015 15:39:08 +0100 Subject: [PATCH 2/2] Cosmetic: Wrap method args across multiple lines --- hardware_interface/include/hardware_interface/robot_hw.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hardware_interface/include/hardware_interface/robot_hw.h b/hardware_interface/include/hardware_interface/robot_hw.h index aecdd78bf..c664435e6 100644 --- a/hardware_interface/include/hardware_interface/robot_hw.h +++ b/hardware_interface/include/hardware_interface/robot_hw.h @@ -103,20 +103,23 @@ class RobotHW : public InterfaceManager * This is just a check, the actual switch is done in doSwitch() * @deprecated: Implement prepareSwitch() instead */ - virtual bool canSwitch(const std::list& /*start_list*/, const std::list& /*stop_list*/) const { return true; } + virtual bool canSwitch(const std::list& /*start_list*/, + const std::list& /*stop_list*/) const { return true; } /** * Check (in non-realtime) if given controllers could be started and stopped from the current state of the RobotHW * with regard to necessary hardware interface switches and prepare the switching. Start and stop list are disjoint. * This handles the check and preparation, the actual switch is commited in doSwitch() */ - virtual bool prepareSwitch(const std::list& start_list, const std::list& stop_list) { return canSwitch(start_list, stop_list); } + virtual bool prepareSwitch(const std::list& start_list, + const std::list& stop_list) { return canSwitch(start_list, stop_list); } /** * Perform (in non-realtime) all necessary hardware interface switches in order to start and stop the given controllers. * Start and stop list are disjoint. The feasability was checked in canSwitch() beforehand. */ - virtual void doSwitch(const std::list& /*start_list*/, const std::list& /*stop_list*/) {} + virtual void doSwitch(const std::list& /*start_list*/, + const std::list& /*stop_list*/) {} }; }