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 Jul 17, 2019
1 parent 8841312 commit 09f6a08
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
24 changes: 24 additions & 0 deletions ros2action/ros2action/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
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_parser.definition import AbstractNestedType
from rosidl_parser.definition import NamespacedType
from rosidl_runtime_py.convert import message_to_yaml
from rosidl_runtime_py.import_message import import_message_from_namespaced_type


def _is_action_status_topic(topic_name, action_name):
Expand Down Expand Up @@ -139,3 +143,23 @@ 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):
full_action_type = getattr(parsed_args, self.action_type_key)
try:
parts = full_action_type.split('/')
package_name = parts[0]
interface_type = parts[1]
action_type = parts[-1]
except LookupError as e:
return None
action = import_message_from_namespaced_type(
AbstractNestedType(NamespacedType([package_name, interface_type], action_type)))
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 @@ -19,6 +19,7 @@
from rclpy.action import ActionClient
from ros2action.api import action_name_completer
from ros2action.api import ActionTypeCompleter
from ros2action.api import ActionGoalPrototypeCompleter
from ros2action.verb import VerbExtension
from ros2cli.node import NODE_NAME_PREFIX
from rosidl_runtime_py import message_to_yaml
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 09f6a08

Please sign in to comment.