Skip to content

Commit

Permalink
enable to publish info, currently we publish node's function document…
Browse files Browse the repository at this point in the history
…, or node name
  • Loading branch information
k-okada committed Jan 31, 2023
1 parent 795e764 commit a84e026
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion roseus_smach/sample/state-machine-sample.l
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
;; https://raw.githubusercontent.com/rhaschke/executive_smach_tutorials/indigo-devel/examples/state_machine_simple.py
;;
(setq count 0)
(defun func-foo (&rest args)
(defun func-foo (&rest args) "document foo"
(format t "Execute state FOO~%")
(cond ((< count 3) (incf count) :outcome1)
(t :outcome2)))
Expand Down
3 changes: 2 additions & 1 deletion roseus_smach/src/state-machine-ros.l
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
(:state-machine (&rest args) (forward-message-to sm args))
;;
(:publish-status
(&optional (userdata nil) (machine sm) (path (format nil "/~A" root-name)))
(&optional (userdata nil) (machine sm) (path (format nil "/~A" root-name)) (info))
(let ((msg (instance smach_msgs::SmachContainerStatus :init))
(initial (send-all (flatten (list (send machine :start-state))) :name))
(active (send-all (flatten (list (send machine :active-state))) :name)))
Expand All @@ -54,6 +54,7 @@
(send msg :initial_states (mapcar #'string initial))
(send msg :active_states (mapcar #'string active))
(send msg :local_data (pickle::dump userdata))
(send msg :info info)
(ros::publish (concatenate string srv-name "/smach/container_status") msg)
;; recursive call for publish active sub-machines
(dolist (active-state (flatten (list (send machine :active-state))))
Expand Down
17 changes: 15 additions & 2 deletions roseus_smach/src/state-machine-utils.l
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Args:
Returns:
the last active state
"
(let ((insp (instance state-machine-inspector :init sm :root-name root-name :srv-name srv-name)))
(let ((insp (instance state-machine-inspector :init sm :root-name root-name :srv-name srv-name)) acs act doc)
(unix::usleep (round (* 0.5 1e6)))
(send sm :reset-state)
(send insp :publish-structure) ;; publish once and latch
Expand All @@ -31,7 +31,20 @@ Returns:
(when spin
(send insp :spin-once)
(if (and (boundp '*ri*) *ri*) (send *ri* :spin-once)))
(send insp :publish-status mydata)
(setq acs (send sm :active-state))
(if (atom acs) (setq acs (list acs)))
(setq doc "")
(dolist (a acs)
(setq act (send a :action))
(setq d
(cond ((and (functionp act) (not (listp act)))
(documentation act))
((and (listp act) (eq (car act) 'lambda))
(format nil "~A ~A..." (butlast act) (subseq (car (last act)) 0 3)))
(t
(format nil "~A" act))))
(push (cond ((stringp d) d) (t (string (send (send sm :active-state) :name)))) doc))
(send insp :publish-status mydata sm (format nil "/~A" root-name) (apply #'concatenate string doc))
(when (send sm :goal-reached)
(return))
(when iterate
Expand Down
2 changes: 2 additions & 0 deletions roseus_smach/src/state-machine.l
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@
(send-super :init name))
;; check if this state is state-machine, then return it
(:submachine () (if (derivedp action state-machine) action nil))
;; accessor to action
(:action (&rest args) (forward-message-to action args))
;; remap userdata names
(:remap-list
(&rest args)
Expand Down

0 comments on commit a84e026

Please sign in to comment.