From 43d453eb38c5800ffae3b464769a7bc1e0feaba2 Mon Sep 17 00:00:00 2001 From: Trey Smith Date: Tue, 19 Dec 2023 11:12:12 -0500 Subject: [PATCH] plan_interpreter.py works with default arguments again --- .../data/sample_output_plan.yaml | 50 ++++++++----------- .../survey_planner/tools/plan_interpreter.py | 44 ++++++++-------- 2 files changed, 43 insertions(+), 51 deletions(-) diff --git a/astrobee/survey_manager/survey_planner/data/sample_output_plan.yaml b/astrobee/survey_manager/survey_planner/data/sample_output_plan.yaml index d17b7e1c..f4b5d2fe 100644 --- a/astrobee/survey_manager/survey_planner/data/sample_output_plan.yaml +++ b/astrobee/survey_manager/survey_planner/data/sample_output_plan.yaml @@ -47,8 +47,7 @@ - 11.0 - -7.0 - 4.8 - run: 1 - duration_seconds: '900.000' + duration_seconds: '780.000' - start_time_seconds: '100.004' action: type: panorama @@ -58,9 +57,8 @@ - 11.0 - -9.7 - 4.8 - run: 1 - duration_seconds: '900.000' -- start_time_seconds: '990.005' + duration_seconds: '780.000' +- start_time_seconds: '870.005' action: type: move robot: bumble @@ -70,7 +68,7 @@ - -6.0 - 4.8 duration_seconds: '20.000' -- start_time_seconds: '1000.005' +- start_time_seconds: '880.005' action: type: move robot: honey @@ -80,7 +78,7 @@ - -9.0 - 4.8 duration_seconds: '20.000' -- start_time_seconds: '1010.006' +- start_time_seconds: '890.006' action: type: panorama robot: bumble @@ -89,9 +87,8 @@ - 11.0 - -6.0 - 4.8 - run: 1 - duration_seconds: '900.000' -- start_time_seconds: '1020.006' + duration_seconds: '780.000' +- start_time_seconds: '900.006' action: type: panorama robot: honey @@ -100,9 +97,8 @@ - 11.0 - -9.0 - 4.8 - run: 1 - duration_seconds: '900.000' -- start_time_seconds: '1910.007' + duration_seconds: '780.000' +- start_time_seconds: '1670.007' action: type: move robot: bumble @@ -112,7 +108,7 @@ - -5.0 - 4.8 duration_seconds: '20.000' -- start_time_seconds: '1930.008' +- start_time_seconds: '1690.008' action: type: panorama robot: bumble @@ -121,9 +117,8 @@ - 11.0 - -5.0 - 4.8 - run: 1 - duration_seconds: '900.000' -- start_time_seconds: '2830.009' + duration_seconds: '780.000' +- start_time_seconds: '2470.009' action: type: move robot: bumble @@ -133,7 +128,7 @@ - -4.0 - 4.8 duration_seconds: '20.000' -- start_time_seconds: '2850.010' +- start_time_seconds: '2490.010' action: type: panorama robot: bumble @@ -142,16 +137,14 @@ - 11.0 - -4.0 - 4.8 - run: 1 - duration_seconds: '900.000' -- start_time_seconds: '3750.011' + duration_seconds: '780.000' +- start_time_seconds: '3270.011' action: type: stereo robot: bumble fplan: jem_stereo_mapping_bay1_to_bay3.fplan - run: 1 duration_seconds: '600.000' -- start_time_seconds: '4350.012' +- start_time_seconds: '3870.012' action: type: move robot: honey @@ -161,7 +154,7 @@ - -8.0 - 4.8 duration_seconds: '20.000' -- start_time_seconds: '4370.013' +- start_time_seconds: '3890.013' action: type: panorama robot: honey @@ -170,9 +163,8 @@ - 11.0 - -8.0 - 4.8 - run: 1 - duration_seconds: '900.000' -- start_time_seconds: '5270.014' + duration_seconds: '780.000' +- start_time_seconds: '4670.014' action: type: move robot: honey @@ -182,7 +174,7 @@ - -9.0 - 4.8 duration_seconds: '20.000' -- start_time_seconds: '5290.015' +- start_time_seconds: '4690.015' action: type: move robot: honey @@ -192,7 +184,7 @@ - -9.7 - 4.8 duration_seconds: '20.000' -- start_time_seconds: '5310.016' +- start_time_seconds: '4710.016' action: type: dock robot: honey diff --git a/astrobee/survey_manager/survey_planner/tools/plan_interpreter.py b/astrobee/survey_manager/survey_planner/tools/plan_interpreter.py index 782f8633..3d9e9374 100755 --- a/astrobee/survey_manager/survey_planner/tools/plan_interpreter.py +++ b/astrobee/survey_manager/survey_planner/tools/plan_interpreter.py @@ -34,10 +34,17 @@ import pathlib import re import sys -from typing import Any, Dict, List +from typing import Any, Dict, Iterable, List import yaml +from problem_generator import CWD, DATA_DIR, PDDL_DIR, load_yaml, path_list + +DEFAULT_CONFIGS = [ + DATA_DIR / "jem_survey_static.yaml", + # Dynamic config not needed for interpreting the plan +] + ACTION_TYPE_OPTIONS = ("dock", "undock", "move", "panorama", "stereo") @@ -54,14 +61,6 @@ ) -def load_yaml(yaml_path: pathlib.Path) -> YamlMapping: - """ - Return the YAML parse result for the file at `yaml_path`. - """ - with yaml_path.open(encoding="utf-8") as yaml_stream: - return yaml.safe_load(yaml_stream) - - class PlanAction: """ Class representing one entry in the output plan sequence of a PDDL planner. @@ -187,7 +186,9 @@ def ignore_aliases(self, data): def plan_interpreter( - config_static_path: pathlib.Path, plan_path: pathlib.Path, output_path: pathlib.Path + config_paths: Iterable[pathlib.Path], + plan_path: pathlib.Path, + output_path: pathlib.Path, ) -> None: """ The main function that interprets an entire plan file. @@ -195,11 +196,12 @@ def plan_interpreter( However, if you are receiving one action at a time from an executor, you may prefer to import this module and call yaml_action_from_pddl() directly. """ - config_static = load_yaml(config_static_path) + config = {} + for config_path in config_paths: + config.update(load_yaml(config_path)) pddl_actions = parse_plan(plan_path) yaml_actions = [ - yaml_plan_action_from_pddl(plan_action, config_static) - for plan_action in pddl_actions + yaml_plan_action_from_pddl(plan_action, config) for plan_action in pddl_actions ] with output_path.open("w", encoding="utf-8") as output_stream: yaml.dump(yaml_actions, output_stream, Dumper=NoAliasDumper, sort_keys=False) @@ -217,30 +219,28 @@ def main(): description=__doc__, formatter_class=CustomFormatter ) parser.add_argument( - "--config-static", - help="Path to input static problem config YAML (module geometry, available stereo surveys, etc.)", - type=pathlib.Path, - default="jem_survey_static.yaml", + "--config", + help="Comma-separated list of paths to YAML problem config inputs (only static config needed)", + type=path_list, + default=DEFAULT_CONFIGS, ) parser.add_argument( "--plan", help="Path to input plan generated by PDDL planner (parser currently tuned for POPF idiosyncrasies)", type=pathlib.Path, - default="sample_output_plan.txt", + default=DATA_DIR / "sample_output_plan.txt", ) parser.add_argument( "-o", "--output", help="Path for output converted to YAML format", type=pathlib.Path, - default="sample_output_plan.yaml", + default=DATA_DIR / "sample_output_plan.yaml", ) args = parser.parse_args() plan_interpreter( - config_static_path=args.config_static, - plan_path=args.plan, - output_path=args.output, + config_paths=args.config, plan_path=args.plan, output_path=args.output )