Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternate solution for one-shot-subscribe (#666 and #667) #725

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions roseus/euslisp/roseus-utils.l
Original file line number Diff line number Diff line change
Expand Up @@ -1132,10 +1132,13 @@
(unless (ros r :success) (ros::ros-warn "Call \"~A\" fails, it returns \"~A\"" srvname (send r :message)))
r)))

(defun one-shot-subscribe (topic-name mclass &key (timeout) (after-stamp) (unsubscribe t))
(defun one-shot-subscribe (topic-name mclass &key (timeout) (after-stamp))
"Subscribe message, just for once"
(let (lmsg)
(unless (ros::get-num-publishers topic-name)
(if (ros::get-topic-subscriber topic-name)
(progn
(ros::ros-error (format nil "There is already subscriber for ~A. If you want to use this function, please (ros::unsubscribe \"~A\")." topic-name topic-name))
(return-from one-shot-subscribe))
(cond
(after-stamp
(ros::subscribe topic-name mclass
Expand All @@ -1147,15 +1150,16 @@
(t
(ros::subscribe topic-name mclass
#'(lambda (msg) (setq lmsg msg))))))
(let ((finishtm (if timeout (ros::time-now))))
(when finishtm
(setq finishtm (ros::time+ finishtm (ros::time (/ timeout 1000.0)))))
(while (not (and finishtm
(< (send (ros::time- finishtm (ros::time-now)) :to-Sec) 0)))
(unix::usleep (* 50 1000))
(ros::spin-once)
(if lmsg (return))))
(if unsubscribe (ros::unsubscribe topic-name))
(unwind-protect
(let ((finishtm (if timeout (ros::time-now))))
(when finishtm
(setq finishtm (ros::time+ finishtm (ros::time (/ timeout 1000.0)))))
(while (not (and finishtm
(< (send (ros::time- finishtm (ros::time-now)) :to-Sec) 0)))
(unix::usleep (* 50 1000))
(ros::spin-once)
(if lmsg (return))))
(ros::unsubscribe topic-name))
lmsg))

(defun one-shot-publish (topic-name msg &key (wait 500) (after-stamp) (unadvertise t))
Expand Down