This is an old revision of the document!


Performing Activities

Basic functionality

This is a short tutorial to showcase how to call plans through performing action designators.

Let's first load the plan library system and switch to its corresponding Lisp package:

CL-USER> (ros-load:load-system "cram_plan_library" :cram-plan-library)
;; or ,r-l-s RET cram_plan_library RET RET
CL-USER> (in-package :cram-plan-library)

Next, let's define the actual plan we want to execute:

PLAN-LIB> (cpl:def-cram-function eat (stuff)
            (format t "hmmm... nomnomnom... ~a~%" stuff))

Because we want to trigger this plan via an action designator, let's define that as well:

PLAN-LIB> (prolog:def-fact-group eating-plans (desig:action-desig)
            (prolog:<- (desig:action-desig ?action-designator (eat ?object))
              (desig:desig-prop ?action-designator (:to :eat))
              (desig:desig-prop ?action-designator (:yummy ?object))))

Now let's try to perform the designator we just defined.

Pay attention that perform calls can only be done within a task tree.

PLAN-LIB> (cpl:top-level
            (plan-lib:perform (desig:an action (to eat) (yummy pizza))))
 
hmmm... nomnomnom... PIZZA

Plan goals

Now, let's assume that our action has an explicit effect we would like to follow:

PLAN-LIB> (cpl:top-level
            (plan-lib:perform (desig:an action (to eat) (yummy pizza) (goal (object-eaten pizza)))))
WARNING:
   Trying to prove goal (OBJECT-EATEN
                         PIZZA) with undefined functor CRAM-PLAN-OCCASIONS-EVENTS::OBJECT-EATEN.
hmmm... nomnomnom... PIZZA
WARNING:
   Trying to prove goal (OBJECT-EATEN
                         PIZZA) with undefined functor CRAM-PLAN-OCCASIONS-EVENTS::OBJECT-EATEN.
; Evaluation aborted on #<CRAM-LANGUAGE-IMPLEMENTATION:SIMPLE-PLAN-FAILURE "Goal `~a' of action `~a' was not achieved." {1002CAAD53}>.

We get an error that the goal of the action was not achieved by the end of performing this action.

Let's add that:

PLAN-LIB> (defparameter *pizza-eaten-p* nil)
*PIZZA-EATEN-P*
PLAN-LIB> (cpl:def-cram-function eat (stuff)
            (format t "hmmm... nomnomnom... ~a~%" stuff)
            (setf *pizza-eaten-p* t))
STYLE-WARNING: redefining CRAM-PLAN-LIBRARY::EAT in DEFUN
PLAN-LIB> (prolog:def-fact-group eating-occasions ()
            (prolog:<- (cram-plan-occasions-events::object-eaten ?object)
              (prolog:lisp-pred identity *pizza-eaten-p*)))

We defined a new world state *pizza-eaten-p* and an occasion object-eaten that is calculated from that state variable.

Let's now call the perform action again:

PLAN-LIB> (cpl:top-level
            (plan-lib:perform (desig:an action (to eat) (yummy pizza) (goal (object-eaten pizza)))))
hmmm... nomnomnom... PIZZA