Skip to content

Commit

Permalink
plan_interpreter.py works with default arguments again
Browse files Browse the repository at this point in the history
  • Loading branch information
trey0 committed Dec 19, 2023
1 parent 9dba17c commit 43d453e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 51 deletions.
50 changes: 21 additions & 29 deletions astrobee/survey_manager/survey_planner/data/sample_output_plan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
44 changes: 22 additions & 22 deletions astrobee/survey_manager/survey_planner/tools/plan_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand All @@ -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.
Expand Down Expand Up @@ -187,19 +186,22 @@ 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.
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)
Expand All @@ -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
)


Expand Down

0 comments on commit 43d453e

Please sign in to comment.