Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
tutorials:intermediate:performing_plans [2016/07/21 14:58] – created gkazhoyatutorials:intermediate:performing_plans [2022/03/30 21:26] (current) – [Plan goals] schimpf
Line 1: Line 1:
-====== Performing Activities ======+====== Performing Actions ====== 
 + 
 +===== Basic functionality =====
  
 This is a short tutorial to showcase how to call plans through performing action designators. 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:+Let's first load the CRAM plan library system:
  
 <code lisp> <code lisp>
-CL-USER> (ros-load:load-system "cram_plan_library" :cram-plan-library+CL-USER> (ros-load:load-system "cram_executive" :cram-executive
-;; or ,r-l-s RET cram_plan_library RET RET +;; or ,r-l-s RET cram_executive RET RET
-CL-USER> (in-package :cram-plan-library)+
 </code> </code>
  
Line 14: Line 15:
  
 <code lisp> <code lisp>
-PLAN-LIB> (cpl:def-cram-function eat (stuff+CL-USER> (cpl:def-cram-function eat (&key ((:yummy ?yummy)) &allow-other-keys) 
-            (format t "hmmm... nomnomnom... ~a~%" stuff))+           (declare (type (or string null) ?yummy)
 +           (format t "hmmm... nomnomnom... ~a~%" ?yummy))
 </code> </code>
  
Line 21: Line 23:
  
 <code lisp> <code lisp>
-PLAN-LIB> (prolog:def-fact-group eating-plans (desig:action-desig+CL-USER> (prolog:def-fact-group eating-plans (desig:action-grounding
-            (prolog:<- (desig:action-desig ?action-designator (eat ?object)) +             (prolog:<- (desig:action-grounding ?action-designator (eat ?action-designator)) 
-              (desig:desig-prop ?action-designator (:to :eat)) +                        (desig:desig-prop ?action-designator (:to :eat)) 
-              (desig:desig-prop ?action-designator (:yummy ?object))))+                        (desig:desig-prop ?action-designator (:yummy ?object))))
 </code> </code>
  
 Now let's try to perform the designator we just defined. Now let's try to perform the designator we just defined.
  
-Pay attention that `performcalls can only be done within a task tree.+Pay attention that ''perform'' calls can only be done within a task tree.
  
 <code lisp> <code lisp>
-PLAN-LIB> (cpl:top-level +CL-USER> (cpl:top-level 
-            (cpl:perform (desig:an action (to eat) (yummy pizza))))+           (exe:perform (desig:an action (to eat) (yummy pizza)))) 
 +hmmm... nomnomnom... PIZZA 
 +NIL 
 +#<A ACTION 
 +    (TO EAT) 
 +    (YUMMY PIZZA)> 
 +</code>
  
 +===== Plan goals =====
 +
 +Now, let's assume that our action has an explicit effect we would like to follow:
 +
 +<code lisp>
 +CL-USER> (cpl:top-level
 +           (exe: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 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}>.
 </code> </code>
  
 +We get an error that the goal of the action was not achieved by the end of performing this action.
 +
 +Let's add that:
 +
 +<code lisp>
 +CL-USER> (defparameter *pizza-eaten-p* nil)
 +*PIZZA-EATEN-P*
 +CL-USER> (cpl:def-cram-function eat (&key ((:yummy ?yummy)) &allow-other-keys)
 +           (declare (type (or string null) ?yummy))
 +           (format t "hmmm... nomnomnom... ~a~%" ?yummy)
 +           (setf *pizza-eaten-p* t))
 +; in: CRAM-LANGUAGE-IMPLEMENTATION:DEF-CRAM-FUNCTION EAT
 +;     (TYPE (OR STRING NULL) ?YUMMY)
 +
 +; caught WARNING:
 +;   undefined variable: COMMON-LISP-USER::?YUMMY
 +
 +; compilation unit finished
 +;   Undefined variable:
 +;     ?YUMMY
 +;   caught 1 WARNING condition
 +WARNING: redefining COMMON-LISP-USER::EAT in DEFUN
 +EAT
 +CL-USER> (prolog:def-fact-group eating-occasions ()
 +           (prolog:<- (:object-eaten ?object)
 +             (prolog:symbol-value *pizza-eaten-p* ?eaten)
 +             (prolog:lisp-pred identity ?eaten)))
 +</code>
 +
 +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:
 +
 +<code lisp>
 +PLAN-LIB> (cpl:top-level
 +            (exe:perform (desig:an action (to eat) (yummy pizza) (goal (object-eaten pizza)))))
 +hmmm... nomnomnom... PIZZA
 +NIL
 +</code>
 +
 +===== Restrictions =====
 +
 +Please keep in mind that if there are multiple solutions to a particular action designator, i.e. it resolves to different plans, the first one that is defined will be executed. Ordering is not yet implemented and should probably be taken care of explicitly in the plans anyway.
 +Summary: **make sure an action designator you use for plans can only be resolved to one unique CRAM plan.**