Skip to content

Commit

Permalink
Merge pull request #705 from k-okada/add_call_trigger_service_persist
Browse files Browse the repository at this point in the history
add call-trigger-service and call-set-bool-service, copied from
  • Loading branch information
k-okada committed Jul 27, 2022
2 parents d84c4d2 + af4cf48 commit bd1e2b1
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions roseus/euslisp/roseus-utils.l
Original file line number Diff line number Diff line change
Expand Up @@ -1108,12 +1108,30 @@
;; misc function
;;
(ros::roseus-add-srvs "std_srvs")
(defun call-empty-service (srvname &key (wait nil) (timeout -1)) ;; If timeout is -1 (default), waits until the node is shutdown. If timeout is 0, returns immediately.
(defun call-empty-service (srvname &key (wait nil) (timeout -1) (persistent nil)) ;; If timeout is -1 (default), waits until the node is shutdown. If timeout is 0, returns immediately.
"Call empty service and return t"
(when (ros::wait-for-service srvname (if wait timeout 0))
(ros::service-call srvname (instance std_srvs::EmptyRequest :init))
(ros::service-call srvname (instance std_srvs::EmptyRequest :init) persistent)
t))

(defun call-trigger-service (srvname &key (wait nil) (timeout -1) (persistent nil))
"Call std_srv/Trigger service. Use (setq r (call-trigger-service \"/test\" t)) (and r (send r :success)) to check if it succeed. If r is nil, it fail to find service."
(let (r)
(when (ros::wait-for-service srvname (if wait timeout 0))
(setq r (ros::service-call srvname (instance std_srvs::TriggerRequest :init) persistent))
(ros::ros-debug "Call \"~A\" returns \"~A\"" srvname (send r :message))
(unless (send r :success) (ros::ros-warn "Call \"~A\" fails, it returns \"~A\"" srvname (send r :message)))
r)))

(defun call-set-bool-service (srvname data &key (wait nil) (timeout -1) (persistent nil))
"Call std_srv/SetBoolRequest service, Use (setq r (call-set-bool-service \"/test\" t)) (and r (send r :success)) to check if it succeed. If r is nil, it fail to find service."
(let (r)
(when (ros::wait-for-service srvname (if wait timeout 0))
(setq r (ros::service-call srvname (instance std_srvs::SetBoolRequest :init :data data) persistent))
(ros::ros-debug "Call \"~A\" returns \"~A\"" srvname (send r :message))
(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))
"Subscribe message, just for once"
(let (lmsg)
Expand Down

0 comments on commit bd1e2b1

Please sign in to comment.