Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
tutorials:beginner:failure_handling [2019/07/16 11:34] cpotutorials:beginner:failure_handling [2022/03/15 13:41] – [Recovering from the failure] schimpf
Line 107: Line 107:
 (defparameter *max-bound* 10.5) (defparameter *max-bound* 10.5)
  
-(defun navigate (?v)+(defun navigate (&key ((:target ?target)) 
 +                 &allow-other-keys) 
 +  (declare (type (or list null) ?target))
   (flet ((out-of-bounds (pose)   (flet ((out-of-bounds (pose)
            (with-fields (x y)            (with-fields (x y)
Line 116: Line 118:
       (whenever ((fl-funcall #'out-of-bounds *turtle-pose*))       (whenever ((fl-funcall #'out-of-bounds *turtle-pose*))
         (error 'out-of-bounds-error))         (error 'out-of-bounds-error))
-      (exe:perform (a motion (type moving) (goal ?v))))))+      (exe:perform (a motion (type moving) (goal ?target))))))
 </code> </code>
  
Line 191: Line 193:
 (defparameter *max-bound* 10.5) (defparameter *max-bound* 10.5)
  
-(defun navigate (?v)+(defun navigate (&key ((:target ?target)) 
 +                 &allow-other-keys) 
 +  (declare (type (or list null) ?target))
   (flet ((out-of-bounds (pose)   (flet ((out-of-bounds (pose)
            (with-fields (x y)            (with-fields (x y)
Line 197: Line 201:
              (not (and (< *min-bound* x *max-bound*)              (not (and (< *min-bound* x *max-bound*)
                        (< *min-bound* y *max-bound*))))))                        (< *min-bound* y *max-bound*))))))
-    (with-failure-handling+        (with-failure-handling
         ((out-of-bounds-error (e)         ((out-of-bounds-error (e)
            (ros-warn (draw-simple-simple) "Moving went-wrong: ~a" e)            (ros-warn (draw-simple-simple) "Moving went-wrong: ~a" e)
            (exe:perform (a motion (type setting-pen) (r 204) (g 0) (b 0) (width 2)))            (exe:perform (a motion (type setting-pen) (r 204) (g 0) (b 0) (width 2)))
            (let ((?corr-v (list            (let ((?corr-v (list
-                           (max 0.6 (min 10.4 (car ?v))) +                           (max 0.6 (min 10.4 (car ?target))) 
-                           (max 0.6 (min 10.4 (cadr ?v)))+                           (max 0.6 (min 10.4 (cadr ?target)))
                            0)))                            0)))
              (recover-from-oob ?corr-v)              (recover-from-oob ?corr-v)
Line 212: Line 216:
         (whenever ((fl-funcall #'out-of-bounds *turtle-pose*))         (whenever ((fl-funcall #'out-of-bounds *turtle-pose*))
           (error 'out-of-bounds-error))           (error 'out-of-bounds-error))
-        (exe:perform (a motion (type moving) (goal ?v)))))))+        (exe:perform (a motion (type moving) (goal ?target)))))))
  
 (defun recover-from-oob (&optional goal) (defun recover-from-oob (&optional goal)
Line 247: Line 251:
 <code lisp> <code lisp>
 (in-package :tut) (in-package :tut)
- +  
-(defun draw-house ()+(defun draw-house (&key ((:shape ?shape)) 
 +                   &allow-other-keys) 
 +  (declare (type (or keyword) ?shape))
   (with-fields (x y)   (with-fields (x y)
       (value *turtle-pose*)       (value *turtle-pose*)
Line 259: Line 265:
     (exe:perform (an action (type drawing) (shape triangle) (base-width 5) (height 4)))))     (exe:perform (an action (type drawing) (shape triangle) (base-width 5) (height 4)))))
  
-(defun draw-simple-shape (vertices)+(defun draw-simple-shape (&key 
 +                            ((:vertices ?vertices)) 
 +                          &allow-other-keys) 
 +  (declare (type (or list null) ?vertices)
   (mapcar   (mapcar
    (lambda (?v)    (lambda (?v)
      (exe:perform (an action (type navigating) (target ?v))))      (exe:perform (an action (type navigating) (target ?v))))
-   vertices)) +   ?vertices)) 
 + 
 (defun navigate-without-pen (?target) (defun navigate-without-pen (?target)
   (exe:perform (a motion (type setting-pen) (off 1)))   (exe:perform (a motion (type setting-pen) (off 1)))
   (exe:perform (an action (type navigating) (target ?target)))   (exe:perform (an action (type navigating) (target ?target)))
   (exe:perform (a motion (type setting-pen) (off 0))))   (exe:perform (a motion (type setting-pen) (off 0))))
 + 
  
 (defparameter *min-bound* 0.5) (defparameter *min-bound* 0.5)
 (defparameter *max-bound* 10.5) (defparameter *max-bound* 10.5)
- +  
-(defun navigate (?v)+(defun navigate (&key ((:target ?target)) 
 +                 &allow-other-keys) 
 +  (declare (type (or list null) ?target))
   (flet ((out-of-bounds (pose)   (flet ((out-of-bounds (pose)
            (with-fields (x y)            (with-fields (x y)
Line 279: Line 291:
              (not (and (< *min-bound* x *max-bound*)              (not (and (< *min-bound* x *max-bound*)
                        (< *min-bound* y *max-bound*))))))                        (< *min-bound* y *max-bound*))))))
-    (with-failure-handling+        (with-failure-handling
         ((out-of-bounds-error (e)         ((out-of-bounds-error (e)
            (ros-warn (draw-simple-simple) "Moving went-wrong: ~a" e)            (ros-warn (draw-simple-simple) "Moving went-wrong: ~a" e)
            (exe:perform (a motion (type setting-pen) (r 204) (g 0) (b 0) (width 2)))            (exe:perform (a motion (type setting-pen) (r 204) (g 0) (b 0) (width 2)))
            (let ((?corr-v (list            (let ((?corr-v (list
-                           (max 0.6 (min 10.4 (car ?v))) +                           (max 0.6 (min 10.4 (car ?target))) 
-                           (max 0.6 (min 10.4 (cadr ?v)))+                           (max 0.6 (min 10.4 (cadr ?target)))
                            0)))                            0)))
              (recover-from-oob ?corr-v)              (recover-from-oob ?corr-v)
Line 294: Line 306:
         (whenever ((fl-funcall #'out-of-bounds *turtle-pose*))         (whenever ((fl-funcall #'out-of-bounds *turtle-pose*))
           (error 'out-of-bounds-error))           (error 'out-of-bounds-error))
-        (exe:perform (a motion (type moving) (goal ?v)))))))+        (exe:perform (a motion (type moving) (goal ?target)))))))
  
 (defun recover-from-oob (&optional goal) (defun recover-from-oob (&optional goal)