1
1
; ; state-machine-utils.l
2
2
3
3
(defun exec-state-machine (sm &optional (mydata ' (nil ))
4
- &key (spin t ) (hz 1 ) (root-name " SM_ROOT" ) (srv-name " /server_name" ) iterate)
4
+ &key (spin t ) (hz 1 ) (root-name " SM_ROOT" ) (srv-name " /server_name" ) iterate
5
+ (before-hook-func) (after-hook-func)
6
+ )
5
7
" Execute state machine
6
8
7
9
Args:
@@ -21,28 +23,31 @@ Returns:
21
23
(apply #' send sm :arg-keys (union (send sm :arg-keys ) (mapcar #' car mydata)))
22
24
23
25
(ros ::rate hz)
24
- (while (ros ::ok)
25
- (when spin
26
- (send insp :spin-once )
27
- (if (and (boundp ' *ri*) *ri* ) (send *ri* :spin-once )))
28
- (send insp :publish-status mydata)
29
- (when (send sm :goal-reached )
30
- (return ))
31
- (when iterate
32
- (cond
33
- ((functionp iterate)
34
- (unless (funcall iterate (send sm :active-state ))
35
- (ros ::ros-warn " set abort in iteration" )
36
- (return ))
37
- (iterate
38
- (unless (y-or-n-p (format nil " Execute ~A ? "
39
- (send (send sm :active-state ) :name )))
40
- (ros ::ros-warn " aborting..." )
41
- (return ))
42
- (t (error " value of key :iterate must be t or function" ))))))
43
- (send sm :execute mydata :step -1 )
44
- (ros ::sleep))
45
- (send sm :active-state )))
26
+ (catch :exec-state-machine-loop
27
+ (while (ros ::ok)
28
+ (when spin
29
+ (send insp :spin-once )
30
+ (if (and (boundp ' *ri*) *ri* ) (send *ri* :spin-once )))
31
+ (send insp :publish-status mydata)
32
+ (when (send sm :goal-reached )
33
+ (return ))
34
+ (when iterate
35
+ (cond
36
+ ((functionp iterate)
37
+ (unless (funcall iterate (send sm :active-state ))
38
+ (ros ::ros-warn " set abort in iteration" )
39
+ (return ))
40
+ (iterate
41
+ (unless (y-or-n-p (format nil " Execute ~A ? "
42
+ (send (send sm :active-state ) :name )))
43
+ (ros ::ros-warn " aborting..." )
44
+ (return ))
45
+ (t (error " value of key :iterate must be t or function" ))))))
46
+ (if before-hook-func (funcall before-hook-func))
47
+ (send sm :execute mydata :step -1 )
48
+ (if after-hook-func (funcall after-hook-func))
49
+ (ros ::sleep))
50
+ (send sm :active-state ))))
46
51
47
52
(defun smach-exec (sm)
48
53
" Deprecated function"
0 commit comments