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
Last revisionBoth sides next revision
tutorials:beginner:failure_handling [2022/03/15 13:38] – [Recovering from the failure] schimpftutorials:beginner:failure_handling [2022/03/15 13:42] – [Implementing failure handling for the TurtleSim] schimpf
Line 6: Line 6:
 **Next Tutorial:** [[tutorials:beginner:testing|Writing tests]] **Next Tutorial:** [[tutorials:beginner:testing|Writing tests]]
  
 +To run the code in the tutuorial the roscore and the turtlesim need to be started over the terminal. Each in their own tab.
 +<code bash>
 +$ roscore
 +</code>
 +<code bash>
 +$ rosrun turtlesim turtlesim_node
 +</code>
 +
 +And in the REPL the following commands should be executed:
 +<code lisp>
 +CL-USER>(ros-load:load-system "cram_my_beginner_tutorial" :cram-my-beginner-tutorial)
 +...
 +CL-USER>(in-package :tut)
 +...
 +TUT>(start-ros-node "turtle1")
 +</code>
 ===== Failure Handling in CRAM ===== ===== Failure Handling in CRAM =====
  
Line 251: Line 267:
 <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 263: Line 281:
     (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 283: Line 307:
              (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 298: Line 322:
         (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)