Skip to content
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

Deprecate and rename start and stop nomenclature toward user to activate and deactivate #ABI-breaking #755

Merged
merged 4 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ def reload_controller_libraries(node, controller_manager_name, force_kill):
ReloadControllerLibraries, request)


def switch_controllers(node, controller_manager_name, stop_controllers,
start_controllers, strict, start_asap, timeout):
def switch_controllers(node, controller_manager_name, deactivate_controllers,
activate_controllers, strict, activate_asap, timeout):
request = SwitchController.Request()
request.start_controllers = start_controllers
request.stop_controllers = stop_controllers
request.activate_controllers = activate_controllers
request.deactivate_controllers = deactivate_controllers
if strict:
request.strictness = SwitchController.Request.STRICT
else:
request.strictness = SwitchController.Request.BEST_EFFORT
request.start_asap = start_asap
request.activate_asap = activate_asap
request.timeout = rclpy.duration.Duration(seconds=timeout).to_msg()
return service_caller(node, f'{controller_manager_name}/switch_controller',
SwitchController, request)
Expand Down
2 changes: 1 addition & 1 deletion controller_manager/controller_manager/launch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def generate_load_controller_launch_description(controller_name,

Returns a list of LaunchDescription actions adding the 'controller_manager_name' and
'unload_on_kill' LaunchArguments and a Node action that runs the controller_manager
spawner node to load and start a controller
spawner node to load and activate a controller

Examples # noqa: D416
--------
Expand Down
24 changes: 16 additions & 8 deletions controller_manager/controller_manager/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ def main(args=None):
'--load-only', help='Only load the controller and leave unconfigured.',
action='store_true', required=False)
parser.add_argument(
'--stopped', help='Load and configure the controller, however do not start them',
'--stopped', help='Load and configure the controller, however do not activate them',
action='store_true', required=False)
parser.add_argument(
'--inactive', help='Load and configure the controller, however do not activate them',
action='store_true', required=False)
parser.add_argument(
'-t', '--controller-type',
Expand Down Expand Up @@ -193,7 +196,7 @@ def main(args=None):
node.get_logger().info('Failed to configure controller')
return 1

if not args.stopped:
if not args.stopped and not args.inactive:
ret = switch_controllers(
node,
controller_manager_name,
Expand All @@ -203,11 +206,13 @@ def main(args=None):
True,
5.0)
if not ret.ok:
node.get_logger().info('Failed to start controller')
node.get_logger().info('Failed to activate controller')
return 1

node.get_logger().info(bcolors.OKGREEN + 'Configured and started ' +
node.get_logger().info(bcolors.OKGREEN + 'Configured and activated ' +
bcolors.OKCYAN + controller_name + bcolors.ENDC)
elif args.stopped:
node.get_logger.warn('"--stopped" flag is deprecated use "--inactive" instead')

if not args.unload_on_kill:
return 0
Expand All @@ -217,8 +222,8 @@ def main(args=None):
while True:
time.sleep(1)
except KeyboardInterrupt:
if not args.stopped:
node.get_logger().info('Interrupt captured, stopping and unloading controller')
if not args.stopped and not args.inactive:
node.get_logger().info('Interrupt captured, deactivating and unloading controller')
ret = switch_controllers(
node,
controller_manager_name,
Expand All @@ -228,10 +233,13 @@ def main(args=None):
True,
5.0)
if not ret.ok:
node.get_logger().info('Failed to stop controller')
node.get_logger().info('Failed to deactivate controller')
return 1

node.get_logger().info('Stopped controller')
node.get_logger().info('Deactivated controller')

elif args.stopped:
node.get_logger.warn('"--stopped" flag is deprecated use "--inactive" instead')

ret = unload_controller(
node, controller_manager_name, controller_name)
Expand Down
2 changes: 1 addition & 1 deletion controller_manager/controller_manager/unspawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def main(args=None):
True,
True,
5.0)
node.get_logger().info('Stopped controller')
node.get_logger().info('Deactivated controller')

ret = unload_controller(node, controller_manager_name, controller_name)
if not ret.ok:
Expand Down
51 changes: 44 additions & 7 deletions controller_manager/src/controller_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,9 @@ controller_interface::return_type ControllerManager::switch_controller(
{
RCLCPP_WARN(
get_logger(),
"Could not activate controller with name '%s'. (Check above warnings for more details.) "
"Could not activate controller with name '%s'. Check above warnings for more details. "
"Check the state of the controllers and their required interfaces using "
"`ros2 control list_controllers -v` to get more information.",
"`ros2 control list_controllers -v` CLI to get more information.",
(*ctrl_it).c_str());
if (strictness == controller_manager_msgs::srv::SwitchController::Request::BEST_EFFORT)
{
Expand Down Expand Up @@ -690,7 +690,7 @@ controller_interface::return_type ControllerManager::switch_controller(
if (!is_controller_active(controller_it->c))
{
RCLCPP_WARN(
get_logger(), "Controller with name '%s' can not be deactivated since is not active.",
get_logger(), "Controller with name '%s' can not be deactivated since it is not active.",
controller_it->info.name.c_str());
ret = controller_interface::return_type::ERROR;
}
Expand All @@ -703,9 +703,9 @@ controller_interface::return_type ControllerManager::switch_controller(
{
RCLCPP_WARN(
get_logger(),
"Could not deactivate controller with name '%s'. (Check above warnings for more details.)"
"Could not deactivate controller with name '%s'. Check above warnings for more details. "
"Check the state of the controllers and their required interfaces using "
"`ros2 control list_controllers -v` to get more information.",
"`ros2 control list_controllers -v` CLI to get more information.",
(*ctrl_it).c_str());
if (strictness == controller_manager_msgs::srv::SwitchController::Request::BEST_EFFORT)
{
Expand Down Expand Up @@ -1503,9 +1503,46 @@ void ControllerManager::switch_controller_service_cb(
std::lock_guard<std::mutex> guard(services_lock_);
RCLCPP_DEBUG(get_logger(), "switching service locked");

// response->ok = switch_controller(
// request->activate_controllers, request->deactivate_controllers, request->strictness,
// request->activate_asap, request->timeout) == controller_interface::return_type::OK;
// TODO(destogl): remove this after deprecated fields are removed from service and use the
// commented three lines above
// BEGIN: remove when deprecated removed
auto activate_controllers = request->activate_controllers;
auto deactivate_controllers = request->deactivate_controllers;

if (!request->start_controllers.empty())
{
RCLCPP_WARN(
get_logger(),
"'start_controllers' field is deprecated, use 'activate_controllers' field instead!");
activate_controllers.insert(
activate_controllers.end(), request->start_controllers.begin(),
request->start_controllers.end());
}
if (!request->stop_controllers.empty())
{
RCLCPP_WARN(
get_logger(),
"'stop_controllers' field is deprecated, use 'deactivate_controllers' field instead!");
deactivate_controllers.insert(
deactivate_controllers.end(), request->stop_controllers.begin(),
request->stop_controllers.end());
}

auto activate_asap = request->activate_asap;
if (request->start_asap)
{
RCLCPP_WARN(
get_logger(), "'start_asap' field is deprecated, use 'activate_asap' field instead!");
activate_asap = request->start_asap;
}

response->ok = switch_controller(
request->start_controllers, request->stop_controllers, request->strictness,
request->start_asap, request->timeout) == controller_interface::return_type::OK;
activate_controllers, deactivate_controllers, request->strictness, activate_asap,
request->timeout) == controller_interface::return_type::OK;
// END: remove when deprecated removed

RCLCPP_DEBUG(get_logger(), "switching service finished");
}
Expand Down
25 changes: 14 additions & 11 deletions controller_manager_msgs/srv/SwitchController.srv
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# The SwitchController service allows you stop a number of controllers
# and start a number of controllers, all in one single timestep of the
# controller_manager control loop.
# The SwitchController service allows you deactivate a number of controllers
# and activate a number of controllers, all in one single timestep of the
# controller manager's control loop.

# To switch controllers, specify
# * the list of controller names to start,
# * the list of controller names to stop, and
# * the list of controller names to activate,
# * the list of controller names to deactivate, and
# * the strictness (BEST_EFFORT or STRICT)
# * STRICT means that switching will fail if anything goes wrong (an invalid
# controller name, a controller that failed to start, etc. )
# controller name, a controller that failed to activate, etc. )
# * BEST_EFFORT means that even when something goes wrong with on controller,
# the service will still try to start/stop the remaining controllers
# * start the controllers as soon as their hardware dependencies are ready, will
# the service will still try to activate/stop the remaining controllers
# * activate the controllers as soon as their hardware dependencies are ready, will
# wait for all interfaces to be ready otherwise
# * the timeout before aborting pending controllers. Zero for infinite

Expand All @@ -19,12 +19,15 @@
# specified strictness.


string[] start_controllers
string[] stop_controllers
string[] activate_controllers
string[] deactivate_controllers
string[] start_controllers # DEPRECATED: Use activate_controllers filed instead
string[] stop_controllers # DEPRECATED: Use deactivate_controllers filed instead
int32 strictness
int32 BEST_EFFORT=1
int32 STRICT=2
bool start_asap
bool start_asap # DEPRECATED: Use activate_asap filed instead
bool activate_asap
destogl marked this conversation as resolved.
Show resolved Hide resolved
builtin_interfaces/Duration timeout
---
bool ok
20 changes: 10 additions & 10 deletions ros2controlcli/doc/userdoc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ load_controller
.. code-block:: console

$ ros2 control load_controller -h
usage: ros2 control load_controller [-h] [--spin-time SPIN_TIME] [--set_state {configure,start}] [-c CONTROLLER_MANAGER] [--include-hidden-nodes] controller_name
usage: ros2 control load_controller [-h] [--spin-time SPIN_TIME] [--set_state {configure,activate}] [-c CONTROLLER_MANAGER] [--include-hidden-nodes] controller_name

Load a controller in a controller manager

Expand All @@ -120,7 +120,7 @@ load_controller
-h, --help show this help message and exit
--spin-time SPIN_TIME
Spin time in seconds to wait for discovery (only applies when not using an already running daemon)
--set_state {configure,start}
--set_state {configured,active}
Set the state of the loaded controller
-c CONTROLLER_MANAGER, --controller-manager CONTROLLER_MANAGER
Name of the controller manager ROS node
Expand Down Expand Up @@ -153,13 +153,13 @@ set_controller_state
.. code-block:: console

$ ros2 control set_controller_state -h
usage: ros2 control set_controller_state [-h] [--spin-time SPIN_TIME] [-c CONTROLLER_MANAGER] [--include-hidden-nodes] controller_name {configure,start,stop}
usage: ros2 control set_controller_state [-h] [--spin-time SPIN_TIME] [-c CONTROLLER_MANAGER] [--include-hidden-nodes] controller_name {inactive,active}

Adjust the state of the controller

positional arguments:
controller_name Name of the controller to be changed
{configure,start,stop}
{inactive,active}
State in which the controller should be changed to

optional arguments:
Expand All @@ -177,7 +177,7 @@ switch_controllers
.. code-block:: console

$ ros2 control switch_controllers -h
usage: ros2 control switch_controllers [-h] [--spin-time SPIN_TIME] [--stop [STOP [STOP ...]]] [--start [START [START ...]]] [--strict] [--start-asap] [--switch-timeout SWITCH_TIMEOUT] [-c CONTROLLER_MANAGER]
usage: ros2 control switch_controllers [-h] [--spin-time SPIN_TIME] [--deactivate [CTRL1 [CTRL2 ...]]] [--activate [CTRL1 [CTRL2 ...]]] [--strict] [--activate-asap] [--switch-timeout SWITCH_TIMEOUT] [-c CONTROLLER_MANAGER]
[--include-hidden-nodes]

Switch controllers in a controller manager
Expand All @@ -186,12 +186,12 @@ switch_controllers
-h, --help show this help message and exit
--spin-time SPIN_TIME
Spin time in seconds to wait for discovery (only applies when not using an already running daemon)
--stop [STOP [STOP ...]]
Name of the controllers to be stopped
--start [START [START ...]]
Name of the controllers to be started
--deactivate [CTRL1 [CTRL2 ...]]
Name of the controllers to be deactivate
--activate [CTRL1 [CTRL2 ...]]
Name of the controllers to be activated
--strict Strict switch
--start-asap Start asap controllers
--activate-asap Activate asap controllers
--switch-timeout SWITCH_TIMEOUT
Timeout for switching controllers
-c CONTROLLER_MANAGER, --controller-manager CONTROLLER_MANAGER
Expand Down
9 changes: 7 additions & 2 deletions ros2controlcli/ros2controlcli/verb/load_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def add_arguments(self, parser, cli_name):
arg.completer = ControllerNameCompleter()
arg = parser.add_argument(
'--set-state',
choices=['configure', 'start'],
choices=['configured', 'active'],
help='Set the state of the loaded controller',
)
add_controller_mgr_parsers(parser)
Expand All @@ -50,12 +50,17 @@ def main(self, *, args):
if not response.ok:
return 'Error configuring controller'

# TODO(destogl): remove in humble+
if args.set_state == 'start':
print('Setting state "start" is deprecated "activate" instead!')
args.set_state == 'activate'

if args.set_state == 'active':
response = switch_controllers(
node, args.controller_manager, [], [args.controller_name], True, True, 5.0
)
if not response.ok:
return 'Error starting controller, check controller_manager logs'
return 'Error activating controller, check controller_manager logs'

print(f'Sucessfully loaded controller {args.controller_name} into '
f'state { "inactive" if args.set_state == "configure" else "active" }')
Expand Down
Loading