Skip to content

Commit

Permalink
add action send_goal prototype completer
Browse files Browse the repository at this point in the history
Signed-off-by: artivis <jeremie.deray@canonical.com>
  • Loading branch information
artivis committed Aug 7, 2019
1 parent 8841312 commit 1eeba50
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 13 additions & 0 deletions ros2action/ros2action/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from rclpy.expand_topic_name import expand_topic_name
from rclpy.validate_full_topic_name import validate_full_topic_name
from ros2cli.node.direct import DirectNode
from rosidl_runtime_py.convert import message_to_yaml
from rosidl_runtime_py.utilities import get_action


def _is_action_status_topic(topic_name, action_name):
Expand Down Expand Up @@ -139,3 +141,14 @@ def __call__(self, prefix, parsed_args, **kwargs):
if n == action_name:
return t
return []


class ActionGoalPrototypeCompleter:
"""Callable returning an action goal prototype."""

def __init__(self, *, action_type_key=None):
self.action_type_key = action_type_key

def __call__(self, prefix, parsed_args, **kwargs):
action = get_action(getattr(parsed_args, self.action_type_key))
return [message_to_yaml(action.Goal())]
4 changes: 3 additions & 1 deletion ros2action/ros2action/verb/send_goal.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import rclpy
from rclpy.action import ActionClient
from ros2action.api import action_name_completer
from ros2action.api import ActionGoalPrototypeCompleter
from ros2action.api import ActionTypeCompleter
from ros2action.verb import VerbExtension
from ros2cli.node import NODE_NAME_PREFIX
Expand All @@ -39,9 +40,10 @@ def add_arguments(self, parser, cli_name):
'action_type',
help="Type of the ROS action (e.g. 'example_interfaces/action/Fibonacci')")
arg.completer = ActionTypeCompleter(action_name_key='action_name')
parser.add_argument(
arg = parser.add_argument(
'goal',
help="Goal request values in YAML format (e.g. '{order: 10}')")
arg.completer = ActionGoalPrototypeCompleter(action_type_key='action_type')
parser.add_argument(
'-f', '--feedback', action='store_true',
help='Echo feedback messages for the goal')
Expand Down

0 comments on commit 1eeba50

Please sign in to comment.