forked from ros-controls/ros2_control
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes ros-controls#796 - Adds list_hardware_components to CLI
- Loading branch information
1 parent
0741a49
commit 7dc2bbe
Showing
6 changed files
with
143 additions
and
1 deletion.
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
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
77 changes: 77 additions & 0 deletions
77
ros2controlcli/ros2controlcli/verb/list_hardware_components.py
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,77 @@ | ||
# Copyright 2023 ROS2-Control Development Team | ||
# | ||
# 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. | ||
|
||
from controller_manager import list_hardware_components | ||
from controller_manager.spawner import bcolors | ||
|
||
from ros2cli.node.direct import add_arguments | ||
from ros2cli.node.strategy import NodeStrategy | ||
from ros2cli.verb import VerbExtension | ||
from ros2controlcli.api import add_controller_mgr_parsers | ||
|
||
|
||
class ListHardwareComponentsVerb(VerbExtension): | ||
"""Output the list of available hardware components.""" | ||
|
||
def add_arguments(self, parser, cli_name): | ||
add_arguments(parser) | ||
add_controller_mgr_parsers(parser) | ||
|
||
def main(self, *, args): | ||
with NodeStrategy(args) as node: | ||
hardware_components = list_hardware_components(node, args.controller_manager) | ||
|
||
for idx, component in enumerate(hardware_components.component): | ||
print(f'Hardware Component {idx}') | ||
print(f'\tname: {component.name}') | ||
print(f'\ttype: {component.type}') | ||
if hasattr(component, 'plugin_name'): | ||
print(f'\tplugin name: {component.plugin_name}') | ||
elif hasattr(component, 'class_type'): | ||
print(f'\tclass type: {component.class_type}') | ||
else: | ||
print(f'\t{bcolors.WARNING}Could not determine class/plugin type{bcolors.ENDC}') | ||
|
||
print(f'\tstate: id={component.state.id} label={component.state.label}') | ||
print('\tcommand interfaces') | ||
for cmd_interface in component.command_interfaces: | ||
|
||
if cmd_interface.is_available: | ||
available_str = f'{bcolors.OKBLUE}[available]{bcolors.ENDC}' | ||
else: | ||
available_str = f'{bcolors.WARNING}[unavailable]{bcolors.ENDC}' | ||
|
||
if cmd_interface.is_claimed: | ||
claimed_str = f'{bcolors.OKBLUE}[claimed]{bcolors.ENDC}' | ||
else: | ||
claimed_str = '[unclaimed]' | ||
|
||
print(f'\t\t{cmd_interface.name} {available_str} {claimed_str}') | ||
|
||
print('\tstate interfaces') | ||
for state_interface in component.command_interfaces: | ||
|
||
if state_interface.is_available: | ||
available_str = f'{bcolors.OKBLUE}[available]{bcolors.ENDC}' | ||
else: | ||
available_str = f'{bcolors.WARNING}[unavailable]{bcolors.ENDC}' | ||
|
||
if state_interface.is_claimed: | ||
claimed_str = f'{bcolors.OKBLUE}[claimed]{bcolors.ENDC}' | ||
else: | ||
claimed_str = '[unclaimed]' | ||
|
||
print(f'\t\t{state_interface.name} {available_str} {claimed_str}') | ||
|
||
return 0 |
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