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

NodeStrategy supports node name argument. #941

Merged
merged 3 commits into from
Nov 7, 2024
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
9 changes: 5 additions & 4 deletions ros2cli/ros2cli/node/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@

class NodeStrategy:

def __init__(self, args):
def __init__(self, args, *, node_name=None):
use_daemon = not getattr(args, 'no_daemon', False)
if use_daemon and is_daemon_running(args):
self._daemon_node = DaemonNode(args)
self._direct_node = None
if not self._daemon_node.connected:
self._direct_node = DirectNode(args)
self._direct_node = DirectNode(args, node_name=node_name)
self._daemon_node = None
else:
if use_daemon:
spawn_daemon(args)
self._direct_node = DirectNode(args)
self._direct_node = DirectNode(args, node_name=node_name)
self._daemon_node = None
self._args = args
self._node_name = node_name
self._in_scope = False

@property
Expand All @@ -45,7 +46,7 @@ def daemon_node(self):
@property
def direct_node(self):
if self._direct_node is None:
self._direct_node = DirectNode(self._args)
self._direct_node = DirectNode(self._args, node_name=self._node_name)
if self._in_scope:
self._direct_node.__enter__()
return self._direct_node
Expand Down
5 changes: 4 additions & 1 deletion ros2topic/ros2topic/verb/echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def add_arguments(self, parser, cli_name):
parser.add_argument(
'--clear', '-c', action='store_true',
help='Clear screen before printing next message')
parser.add_argument(
'-n', '--node-name', type=str, default=None,
help='The name of the echoing node; by default, will be a hidden node name')

def choose_qos(self, node, args):

Expand Down Expand Up @@ -200,7 +203,7 @@ def main(self, *, args):

self.include_message_info = args.include_message_info

with NodeStrategy(args) as node:
with NodeStrategy(args, node_name=args.node_name) as node:

qos_profile = self.choose_qos(node, args)

Expand Down