38 lines
967 B
Python
38 lines
967 B
Python
from typing import Dict, Any
|
|
|
|
ALLOWED_SKILLS = {
|
|
"pick": ["object"],
|
|
"align": ["object", "target_fixture"],
|
|
"insert": ["object", "target_fixture"],
|
|
"release": ["object"],
|
|
}
|
|
|
|
ALLOWED_PREDICATES = {
|
|
"object_in_fixture",
|
|
"depth_in_range",
|
|
"pose_in_tolerance",
|
|
}
|
|
|
|
|
|
def validate_task_spec(task: Dict[str, Any]) -> None:
|
|
assert "skills" in task
|
|
assert "goal" in task
|
|
|
|
# ---- skills ----
|
|
for s in task["skills"]:
|
|
name = s["name"]
|
|
args = s.get("args", {})
|
|
|
|
if name not in ALLOWED_SKILLS:
|
|
raise ValueError(f"Unknown skill: {name}")
|
|
|
|
required_args = ALLOWED_SKILLS[name]
|
|
for k in required_args:
|
|
if k not in args:
|
|
raise ValueError(f"Skill {name} missing arg: {k}")
|
|
|
|
# ---- predicates ----
|
|
for p in task["goal"]["success_conditions"]:
|
|
if p["type"] not in ALLOWED_PREDICATES:
|
|
raise ValueError(f"Unknown predicate: {p['type']}")
|