This is an old revision of the document!
Writing Plans
with-policy
Policies can be used to define generic monitoring behavior that should run concurrently besides main functionality code. Such a policy might be monitoring
- the position of an object inside a robot gripper to see whether it is moving out of the gripper (losing the object)
- the position of an object in the real world, in order to keep the robot's head pointing towards it
- the collision of a robot joint with objects in the real world
- generic events that must definitely interrupt a certain piece of code, but are too specialized to be implemented directly in the monitored code itself
A policy consists of multiple parts:
- A name (to identify it)
- A description string (to make its purpose clear)
- A parameter list (which can be used to specialize a generic policy for a situation at hand, without generating a new policy every time the situation changes slightly)
- Code blocks that need to be evaluated during monitoring
The flow of execution is similar to this:
(define-policy my-policy (max-num match-num) (:description "This is an example policy.") (:init (format t "Initializing policy~%") t) (:check (format t "Checking if random number from 0 to ~a equals ~a~%" max-num match-num) (let ((rnd (random max-num))) (format t "Got number ~a~%" rnd) (cond ((eql rnd match-num) (format t "Match~%") t) (t (sleep 1))))) (:recover (format t "Running recovery mechanisms~%")) (:clean-up (format t "Running clean-up~%")))
(top-level (with-named-policy 'my-policy (10 5) (loop do (format t "Main loop cycle.~%") (sleep 2))))