-
Notifications
You must be signed in to change notification settings - Fork 227
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 rosnode and rostopic functionality #9
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
565d03e
Add rosnode functionality
vmayoral 1239733
rosnode: commend invalid code
vmayoral d7388a8
init: minor style fix
vmayoral 2d7c11c
Add rostopic skelethon
vmayoral 727c759
style fixes
vmayoral 8033bf6
rostopic: add socket import
vmayoral 37418eb
rostopic echo: minimal test implementation
vmayoral 64e07ef
rostopic echo: add additional comments
vmayoral faff377
Add basic structure for get remote topic names and types
ahcorde 8714181
complete rclpy_get_remote_topic_names_and_types implementation
ahcorde File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# Copyright 2016 Erle Robotics, LLC | ||
# | ||
# A relevant part of the code has been written taking inpiration | ||
# from ROS 1 ros_comm package attributed to Open Source Robotics Foundation, 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 rclpy | ||
import time | ||
import os | ||
import errno | ||
import sys | ||
|
||
from optparse import OptionParser | ||
|
||
NAME='rosnode' | ||
|
||
# TODO implement | ||
def _rosnode_cmd_ping(argv): | ||
print("NOT IMPLEMENTED\n") | ||
sys.exit(0) | ||
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 is a standard Python exception called |
||
|
||
# TODO implement | ||
def _rosnode_cmd_info(argv): | ||
print("NOT IMPLEMENTED\n") | ||
sys.exit(0) | ||
|
||
# TODO implement | ||
def _rosnode_cmd_machine(argv): | ||
print("NOT IMPLEMENTED\n") | ||
sys.exit(0) | ||
|
||
# TODO implement | ||
def _rosnode_cmd_cleanup(argv): | ||
print("NOT IMPLEMENTED\n") | ||
sys.exit(0) | ||
|
||
# TODO implement | ||
def _rosnode_cmd_kill(argv): | ||
print("NOT IMPLEMENTED\n") | ||
sys.exit(0) | ||
|
||
def _rosnode_cmd_list(argv): | ||
""" | ||
Implements rosnode 'list' command. | ||
""" | ||
args = argv[2:] | ||
parser = OptionParser(usage="usage: %prog list", prog=NAME) | ||
parser.add_option("-u", | ||
dest="list_uri", default=False, | ||
action="store_true", | ||
help="list XML-RPC URIs (NOT IMPLEMENTED)") | ||
parser.add_option("-a","--all", | ||
dest="list_all", default=False, | ||
action="store_true", | ||
help="list all information (NOT IMPLEMENTED)") | ||
(options, args) = parser.parse_args(args) | ||
namespace = None | ||
if len(args) > 1: | ||
parser.error("invalid args: you may only specify one namespace") | ||
elif len(args) == 1: | ||
#namespace = rosgraph.names.script_resolve_name('rostopic', args[0]) | ||
pass | ||
|
||
# In ROS 1, the rosnode list invocation was performed using: | ||
# rosnode_listnodes(namespace=namespace, list_uri=options.list_uri, list_all=options.list_all) | ||
|
||
result = rclpy.get_node_names() | ||
for node in result: | ||
print(node) | ||
|
||
|
||
def _fullusage(return_error=True): | ||
""" | ||
Prints rosnode usage information. | ||
@param return_error whether to exit with error code os.EX_USAGE | ||
""" | ||
print("""rosnode is a command-line tool for printing information about ROS Nodes. | ||
Commands: | ||
\trosnode ping\ttest connectivity to node (NOT IMPLEMENTED) | ||
\trosnode list\tlist active nodes | ||
\trosnode info\tprint information about node (NOT IMPLEMENTED) | ||
\trosnode machine\tlist nodes running on a particular machine or list machines | ||
\trosnode kill\tkill a running node (NOT IMPLEMENTED) | ||
\trosnode cleanup\tpurge registration information of unreachable nodes (NOT IMPLEMENTED) | ||
Type rosnode <command> -h for more detailed usage, e.g. 'rosnode ping -h' | ||
""") | ||
if return_error: | ||
sys.exit(getattr(os, 'EX_USAGE', 1)) | ||
else: | ||
sys.exit(0) | ||
|
||
def rosnodemain(argv=None): | ||
""" | ||
Prints rosnode main entrypoint. | ||
@param argv: override sys.argv | ||
@param argv: [str] | ||
""" | ||
if argv == None: | ||
argv = sys.argv | ||
if len(argv) == 1: | ||
_fullusage() | ||
try: | ||
command = argv[1] | ||
if command == 'ping': | ||
sys.exit(_rosnode_cmd_ping(argv) or 0) | ||
elif command == 'list': | ||
sys.exit(_rosnode_cmd_list(argv) or 0) | ||
elif command == 'info': | ||
sys.exit(_rosnode_cmd_info(argv) or 0) | ||
elif command == 'machine': | ||
sys.exit(_rosnode_cmd_machine(argv) or 0) | ||
elif command == 'cleanup': | ||
sys.exit(_rosnode_cmd_cleanup(argv) or 0) | ||
elif command == 'kill': | ||
sys.exit(_rosnode_cmd_kill(argv) or 0) | ||
elif command == '--help': | ||
_fullusage(False) | ||
else: | ||
_fullusage() | ||
except KeyboardInterrupt: | ||
pass |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We'll probably have to change this to
argparse
, we don't useoptparse
as it is obsolete (argparse
was designed to replace it).