Skip to content

Commit 2de6f09

Browse files
authored
[ros2action] Support multiple part action type names for 'send_goal' verb (#261)
Similar to the changes made in #247 and #259. Signed-off-by: Jacob Perron <[email protected]>
1 parent 7ebaea9 commit 2de6f09

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

ros2action/ros2action/verb/send_goal.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def add_arguments(self, parser, cli_name):
3737
arg.completer = action_name_completer
3838
arg = parser.add_argument(
3939
'action_type',
40-
help="Type of the ROS action (e.g. 'example_interfaces/Fibonacci')")
40+
help="Type of the ROS action (e.g. 'example_interfaces/action/Fibonacci')")
4141
arg.completer = ActionTypeCompleter(action_name_key='action_name')
4242
parser.add_argument(
4343
'goal',
@@ -79,12 +79,21 @@ def send_goal(action_name, action_type, goal_values, feedback_callback):
7979
node = None
8080
action_client = None
8181
try:
82-
# TODO(jacobperron): This logic should come from a rosidl related package
83-
package_name, action_type = action_type.split('/', 2)
84-
if not package_name or not action_type:
82+
try:
83+
# TODO(jacobperron): This logic should come from a rosidl related package
84+
parts = action_type.split('/')
85+
if len(parts) == 1:
86+
raise ValueError()
87+
if len(parts) == 2:
88+
parts = [parts[0], 'action', parts[1]]
89+
package_name = parts[0]
90+
action_type = parts[-1]
91+
if not all(parts):
92+
raise ValueError()
93+
except ValueError:
8594
raise RuntimeError('The passed action type is invalid')
8695

87-
module = importlib.import_module(package_name + '.action')
96+
module = importlib.import_module('.'.join(parts[:-1]))
8897
action_module = getattr(module, action_type)
8998
goal_dict = yaml.safe_load(goal_values)
9099

0 commit comments

Comments
 (0)