Skip to content

Commit

Permalink
Merge pull request #520 from aiplan4eu/TAMP-doc
Browse files Browse the repository at this point in the history
Documentation and example for Task and Motion Planning
  • Loading branch information
arbimo authored Dec 15, 2023
2 parents 9599545 + 23b7cf5 commit 01c4614
Show file tree
Hide file tree
Showing 8 changed files with 712 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/code_snippets/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from functools import partial
import os, uuid, tempfile as tf


# Define the function that will be executed instead
def _function(original_function, *args, **kwargs):
try:
Expand Down
116 changes: 116 additions & 0 deletions docs/code_snippets/tamp_problem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import math
import os
from unified_planning.shortcuts import *

t_robot = MovableType("robot")

occ_map = OccupancyMap(
os.path.join("../notebooks", "maps", "office-map-1.yaml"), (0, 0)
)

t_robot_config = ConfigurationType("robot_config", occ_map, 3)
t_parcel = UserType("parcel")

robot_at = Fluent("robot_at", BoolType(), robot=t_robot, configuration=t_robot_config)
parcel_at = Fluent(
"parcel_at", BoolType(), parcel=t_parcel, configuration=t_robot_config
)
carries = Fluent("carries", BoolType(), robot=t_robot, parcel=t_parcel)

park1 = ConfigurationObject("parking-1", t_robot_config, (46.0, 26.0, 3 * math.pi / 2))
park2 = ConfigurationObject("parking-2", t_robot_config, (40.0, 26.0, 3 * math.pi / 2))

office1 = ConfigurationObject("office-1", t_robot_config, (4.0, 4.0, 3 * math.pi / 2))
office2 = ConfigurationObject("office-2", t_robot_config, (14.0, 4.0, math.pi / 2))
office3 = ConfigurationObject("office-3", t_robot_config, (24.0, 4.0, 3 * math.pi / 2))
office4 = ConfigurationObject("office-4", t_robot_config, (32.0, 4.0, 3 * math.pi / 2))
office5 = ConfigurationObject("office-5", t_robot_config, (4.0, 24.0, 3 * math.pi / 2))
office6 = ConfigurationObject("office-6", t_robot_config, (14.0, 24.0, math.pi / 2))
office7 = ConfigurationObject("office-7", t_robot_config, (24.0, 24.0, math.pi / 2))
office8 = ConfigurationObject("office-8", t_robot_config, (32.0, 24.0, math.pi / 2))

r1 = MovableObject(
"robot-1",
t_robot,
footprint=[(-1.0, 0.5), (1.0, 0.5), (1.0, -0.5), (-1.0, -0.5)],
motion_model=MotionModels.REEDSSHEPP,
parameters={"turning_radius": 2.0},
)

r2 = MovableObject(
"robot-2",
t_robot,
footprint=[(-1.0, 0.5), (1.0, 0.5), (1.0, -0.5), (-1.0, -0.5)],
motion_model=MotionModels.REEDSSHEPP,
parameters={"turning_radius": 2.0},
)

nothing = Object("nothing", t_parcel)
p1 = Object("parcel-1", t_parcel)
p2 = Object("parcel-2", t_parcel)

move = InstantaneousMotionAction(
"move", robot=t_robot, c_from=t_robot_config, c_to=t_robot_config
)
robot = move.parameter("robot")
c_from = move.parameter("c_from")
c_to = move.parameter("c_to")
move.add_precondition(robot_at(robot, c_from))
move.add_effect(robot_at(robot, c_from), False)
move.add_effect(robot_at(robot, c_to), True)
move.add_motion_constraint(Waypoints(robot, c_from, [c_to]))

pick = InstantaneousMotionAction(
"pick", robot=t_robot, loc=t_robot_config, parcel=t_parcel
)
pick_robot = pick.parameter("robot")
pick_loc = pick.parameter("loc")
pick_parcel = pick.parameter("parcel")
pick.add_precondition(robot_at(pick_robot, pick_loc))
pick.add_precondition(parcel_at(pick_parcel, pick_loc))
pick.add_precondition(carries(pick_robot, nothing))
pick.add_precondition(Not(carries(pick_robot, pick_parcel)))
pick.add_effect(carries(pick_robot, pick_parcel), True)
pick.add_effect(parcel_at(pick_parcel, pick_loc), False)
pick.add_effect(carries(pick_robot, nothing), False)

place = InstantaneousMotionAction(
"place", robot=t_robot, loc=t_robot_config, parcel=t_parcel
)
place_robot = place.parameter("robot")
place_loc = place.parameter("loc")
place_parcel = place.parameter("parcel")
place.add_precondition(robot_at(place_robot, place_loc))
place.add_precondition(carries(place_robot, place_parcel))
place.add_precondition(Not(parcel_at(place_parcel, place_loc)))
place.add_precondition(Not(carries(place_robot, nothing)))
place.add_effect(carries(place_robot, place_parcel), False)
place.add_effect(carries(place_robot, nothing), True)
place.add_effect(parcel_at(place_parcel, place_loc), True)

problem = Problem("tamp")
problem.add_fluent(robot_at, default_initial_value=False)
problem.add_fluent(parcel_at, default_initial_value=False)
problem.add_fluent(carries, default_initial_value=False)
problem.add_action(move)
problem.add_action(pick)
problem.add_action(place)

problem.add_objects([park1, park2])
problem.add_objects([office1, office2, office3, office4])
problem.add_objects([office5, office6, office7, office8])
problem.add_objects([r1, r2])
problem.add_object(nothing)
problem.add_objects([p1, p2])

problem.set_initial_value(carries(r1, nothing), True)
problem.set_initial_value(carries(r2, nothing), True)

problem.set_initial_value(parcel_at(p1, office1), True)
problem.set_initial_value(parcel_at(p2, office6), True)

problem.set_initial_value(robot_at(r1, park1), True)

problem.add_goal(robot_at(r1, park1))
problem.add_goal(parcel_at(p1, office2))
problem.add_goal(parcel_at(p2, office3))
11 changes: 9 additions & 2 deletions docs/engines/01_available_engines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ Scheduling
The only planner with full support for scheduling is `Aries`_. Integration work is known for the `discrete-optimization suite <https://github.com/aiplan4eu/up-discreteoptimization>`_ and for `PPS <https://github.com/aiplan4eu/up-pps>`_.

Multi-Agent Planning
^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^

.. list-table::
.. list-table::

* - Engine
- Operation modes
Expand All @@ -145,6 +145,12 @@ Multi-Agent Planning
- Y
- Y

Task and Motion Planning
^^^^^^^^^^^^^^^^^^^^^^^^

Support for task and motion planning is currently provided by the `Spiderplan`_ engine.


.. _`aries`: https://github.com/plaans/aries/blob/master/planning/unified/plugin/README.md
.. _`fast-downward`: https://github.com/aiplan4eu/up-fast-downward/blob/main/README.md
.. _`tamer`: https://github.com/aiplan4eu/up-tamer/blob/master/README.md
Expand All @@ -154,3 +160,4 @@ Multi-Agent Planning
.. _`lpg`: https://github.com/aiplan4eu/up-lpg/blob/master/README.md
.. _`pyperplan`: https://github.com/aiplan4eu/up-pyperplan/blob/master/README.md
.. _`ma-plan-validator`: https://github.com/aiplan4eu/ma-plan-validator/blob/master/README.md

13 changes: 13 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,19 @@ MA-PDDL Writer

In this notebook we show how to write a unified_planning problem in MA-PDDL.

Task and Motion Planning
------------------------

In this notebook we show how to create a Task and Motion Planning (TAMP) problem
that includes a map, configurations, and movable objects that are used to impose
motion constraints in TAMP operators. (Note: this example does not work in Colab
because the engine uses Docker itself.)

.. image:: https://img.shields.io/badge/see-Github-579aca?logo=github
:target: https:///github.com/aiplan4eu/unified-planning/blob/master/docs/notebooks/io/14-task-and-motion-planning.ipynb
:alt: Open In GitHub


.. toctree::
:maxdepth: 2
:numbered:
Expand Down
Loading

0 comments on commit 01c4614

Please sign in to comment.