-
Notifications
You must be signed in to change notification settings - Fork 170
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
Add ros2 service info
command
#703
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Copyright 2022 PickNik Inc. | ||
# | ||
# 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 ros2cli.node.strategy import NodeStrategy | ||
from ros2service.api import get_service_clients_and_servers | ||
from ros2service.api import ServiceNameCompleter | ||
from ros2service.verb import VerbExtension | ||
|
||
|
||
class InfoVerb(VerbExtension): | ||
"""Print information about a service.""" | ||
|
||
def add_arguments(self, parser, cli_name): | ||
arg = parser.add_argument( | ||
'service_name', | ||
help="Name of the ROS service to print info about (e.g. '/talker/list_parameters')") | ||
arg.completer = ServiceNameCompleter( | ||
include_hidden_services_key='include_hidden_services') | ||
parser.add_argument( | ||
'-t', '--show-types', action='store_true', | ||
help='Additionally show the service type') | ||
parser.add_argument( | ||
'-c', '--count', action='store_true', | ||
help='Only display the number of service clients and service servers') | ||
Comment on lines
+30
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if possible, It seems good to be consistent in the same format and option. (https://docs.ros.org/en/rolling/Tutorials/Beginner-CLI-Tools/Understanding-ROS2-Topics/Understanding-ROS2-Topics.html#ros2-topic-info) |
||
|
||
def main(self, *, args): | ||
with NodeStrategy(args) as node: | ||
|
||
service_clients, service_servers = get_service_clients_and_servers( | ||
node=node, | ||
service_name=args.service_name | ||
) | ||
|
||
print('Service: {}'.format(args.service_name)) | ||
print('Service clients: {}'.format(len(service_clients))) | ||
if not args.count: | ||
for client_name, client_types in service_clients: | ||
if args.show_types: | ||
types_formatted = ', '.join(client_types) | ||
print(f' {client_name} [{types_formatted}]') | ||
else: | ||
print(f' {client_name}') | ||
print('Service servers: {}'.format(len(service_servers))) | ||
if not args.count: | ||
for server_name, server_types in service_servers: | ||
if args.show_types: | ||
types_formatted = ', '.join(server_types) | ||
print(f' {server_name} [{types_formatted}]') | ||
else: | ||
print(f' {server_name}') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright 2022 PickNik, Inc. | ||
# | ||
# 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. | ||
|
||
import sys | ||
|
||
import rclpy | ||
from rclpy.node import Node | ||
|
||
from test_msgs.srv import BasicTypes | ||
|
||
|
||
class EchoClient(Node): | ||
|
||
def __init__(self): | ||
super().__init__('echo_server') | ||
self.client = self.create_client(BasicTypes, 'echo') | ||
|
||
|
||
def main(args=None): | ||
rclpy.init(args=args) | ||
|
||
node = EchoClient() | ||
try: | ||
rclpy.spin(node) | ||
except KeyboardInterrupt: | ||
print('server stopped cleanly') | ||
except BaseException: | ||
print('exception in server:', file=sys.stderr) | ||
raise | ||
finally: | ||
# Destroy the node explicitly | ||
# (optional - Done automatically when node is garbage collected) | ||
node.destroy_node() | ||
rclpy.shutdown() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.