As of Fuerte, roslisp has support for persistent services through the class PERSISTENT-SERVICE. The main difference to using CALL-SERVICE is that the connection to the service server is kept open until it is explicitly shut down using CLOSE-PERSISTENT-SERVICE. This avoids unnecessary and slow calls to the ROS core but the user needs to take special care when the server is shut down. The PERSISTENT-SERVICE instance becomes invalid in that case.

Using persistent services

(defvar *persistent-add-two-ints-client* nil)

(defun call-add-two-ints (a b)
  (unless *persistent-add-two-ints-client*
    (setf *persistent-add-two-ints-client*
           (make-instance 'roslisp:persistent-service
             :service-name "add_two_ints"
             :service-type "roscpp_tutorials/TwoInts")))
    (make-service-request 'roscpp_tutorials-srv:TwoInts :a 1 :b 2)))

Note that the code above doesn't handle restarts of the server. If the connection becomes invalid, a condition (normally of type END-OF-FILE will be thrown. CALL-PERSISTENT-SERVICE provides a RECONNECT restart that tries to re-establish the connection between the server and the client. The following code snippet shows how to use the restart:

(let ((restarted nil))
  (handler-bind ((end-of-file (lambda (e)
                                (declare (ignore e))
                                (unless restarted
                                  (setf restarted t)
                                  (invoke-restart 'roslisp:reconnect)))))
      (make-service-request 'roscpp_tutorials-srv:TwoInts :a 1 :b 2))))

Wiki: roslisp/Overview/PersistentServices (last edited 2012-06-18 12:24:24 by Lorenz Mösenlechner)