Skip to content

Commit cc7fcc4

Browse files
committed
enable to publish info, currently we publish node's function document, or node name
1 parent 795e764 commit cc7fcc4

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

roseus_smach/sample/state-machine-sample.l

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
;; https://raw.githubusercontent.com/rhaschke/executive_smach_tutorials/indigo-devel/examples/state_machine_simple.py
1212
;;
1313
(setq count 0)
14-
(defun func-foo (&rest args)
14+
(defun func-foo (&rest args) "document foo"
1515
(format t "Execute state FOO~%")
1616
(cond ((< count 3) (incf count) :outcome1)
1717
(t :outcome2)))

roseus_smach/src/state-machine-ros.l

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
(:state-machine (&rest args) (forward-message-to sm args))
4444
;;
4545
(:publish-status
46-
(&optional (userdata nil) (machine sm) (path (format nil "/~A" root-name)))
46+
(&optional (userdata nil) (machine sm) (path (format nil "/~A" root-name)) (info))
4747
(let ((msg (instance smach_msgs::SmachContainerStatus :init))
4848
(initial (send-all (flatten (list (send machine :start-state))) :name))
4949
(active (send-all (flatten (list (send machine :active-state))) :name)))
@@ -54,6 +54,7 @@
5454
(send msg :initial_states (mapcar #'string initial))
5555
(send msg :active_states (mapcar #'string active))
5656
(send msg :local_data (pickle::dump userdata))
57+
(send msg :info info)
5758
(ros::publish (concatenate string srv-name "/smach/container_status") msg)
5859
;; recursive call for publish active sub-machines
5960
(dolist (active-state (flatten (list (send machine :active-state))))

roseus_smach/src/state-machine-utils.l

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Args:
1818
Returns:
1919
the last active state
2020
"
21-
(let ((insp (instance state-machine-inspector :init sm :root-name root-name :srv-name srv-name)))
21+
(let ((insp (instance state-machine-inspector :init sm :root-name root-name :srv-name srv-name)) acs act doc)
2222
(unix::usleep (round (* 0.5 1e6)))
2323
(send sm :reset-state)
2424
(send insp :publish-structure) ;; publish once and latch
@@ -31,7 +31,20 @@ Returns:
3131
(when spin
3232
(send insp :spin-once)
3333
(if (and (boundp '*ri*) *ri*) (send *ri* :spin-once)))
34-
(send insp :publish-status mydata)
34+
(setq acs (send sm :active-state))
35+
(if (atom acs) (setq acs (list acs)))
36+
(setq doc "")
37+
(dolist (a acs)
38+
(setq act (send a :action))
39+
(setq d
40+
(cond ((and (functionp act) (not (listp act)))
41+
(documentation act))
42+
((and (listp act) (eq (car act) 'lambda))
43+
(format nil "~A ~A..." (butlast act) (if (listp (car (last act))) (subseq (car (last act)) 0 3) act)))
44+
(t
45+
(format nil "~A" act))))
46+
(push (cond ((stringp d) d) (t (string (send (send sm :active-state) :name)))) doc))
47+
(send insp :publish-status mydata sm (format nil "/~A" root-name) (apply #'concatenate string doc))
3548
(when (send sm :goal-reached)
3649
(return))
3750
(when iterate

roseus_smach/src/state-machine.l

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@
221221
(send-super :init name))
222222
;; check if this state is state-machine, then return it
223223
(:submachine () (if (derivedp action state-machine) action nil))
224+
;; accessor to action
225+
(:action (&rest args) (forward-message-to action args))
224226
;; remap userdata names
225227
(:remap-list
226228
(&rest args)

0 commit comments

Comments
 (0)