Skip to content

Commit 5f1ec6e

Browse files
committed
Merge remote-tracking branch 'knorth55/exec-state-machine-hook' into fetch15
2 parents 01b3f20 + c424c44 commit 5f1ec6e

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

roseus_smach/src/state-machine-utils.l

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
;; state-machine-utils.l
22

33
(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+
)
57
"Execute state machine
68
79
Args:
@@ -21,28 +23,31 @@ Returns:
2123
(apply #'send sm :arg-keys (union (send sm :arg-keys) (mapcar #'car mydata)))
2224

2325
(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))))
4651

4752
(defun smach-exec (sm)
4853
"Deprecated function"

0 commit comments

Comments
 (0)