Skip to content

Commit

Permalink
NodeStrategy supports node name argument. (#941)
Browse files Browse the repository at this point in the history
* NodeStrategy supports node name argument.

Signed-off-by: Tomoya Fujita <[email protected]>

* default node name should be None.

Signed-off-by: Tomoya Fujita <[email protected]>

* adjust help message for ros2 echo node name option.

Signed-off-by: Tomoya Fujita <[email protected]>

---------

Signed-off-by: Tomoya Fujita <[email protected]>
  • Loading branch information
fujitatomoya authored Nov 7, 2024
1 parent fce8ae7 commit 775ea35
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
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

0 comments on commit 775ea35

Please sign in to comment.