A system handle has associated a display-server. The methods,
(update-var (self <system-handle>) var value) (finalize-display (self <system-handle>))update the value of the variable whose name is
var
, and finished the display server associated with the system handle, respectively. Next we explain how to set up a display server. Examples 5 and 6 illustrate how to use these facilities.
The class <display-server>
3.11 has the following public names:
(name (self <display-server>)) (host (self <display-server>)) (port (self <display-server>)) (init-code (self <display-server>)) (end-code (self <display-server>)) (loop-delay (self <display-server>))As usual, a method
(start (self <display-server>))
exists which should be called to initialize a display server. Starting a display server accounts to:
loop-delay
field of the display-server. When a thread is associated with a display server, it receives messages of the form
init-code
to the display server. This way, one can provide some code that has to be run when the system-handle is created.
(finalize (self <display-server>))
ends a display server. The functions specified in the field end-code
are applied to the display server. The thread associated with the display server (if exists) is killed.
The following methods exist to add ``variables'' and ``rules'' to the system handle:
(add-var (self <display-server>) (var <display-var>)) (add-rule (self <display-server>) var rule) // var = var-name or <display-var> instance (update-var (self <display-server>) var value)A
<display-var>
instance has the public field name
which is used later to specify the variable. A rule
is a binary function whose first argument is a value (i.e. the value of the variable) and whose second argument is a display server.
Suppose we want to display the current robot drive and turn speeds, using a speedometer display as those provided by labview (see Figure 3.1). The code below defines a server to do so:3.12
(define (labview-display host port) (let ((dis (make <display-server> name: "labview display" port: port host: host) )) (start dis) (add-var dis (make <display-var> name: 'drive)) (add-var dis (make <display-var> name: 'turn)) (add-rule dis 'drive (lambda (x s) (format #t "current drive speed is ~a" x))) (add-rule dis 'drive (lambda (x s) (write-socket-lf (sock s) (format #f "drive ~a" x)))) (add-rule dis 'turn (lambda (x s) (format #t "current turn speed is ~a" x))) (add-rule dis 'turn (lambda (x s) (write-socket-lf (sock s) (format #f "turn ~a" x)))) dis ) )In order to run this example, run labview, and then run the VI
$VULCAN/examples/drive-and-turn.vi
. Once that has been done, you can send some data to the display. For example,
(set! my-display (labview-display ``glare'' 6800)) (update-var my-display 'drive 8) (update-var my-display 'turn 2)or move the drive/turn needle on the VI and see the result coming out in the Rscheme window.
Other than sending data through sockets, rules associated with display servers can send data to a file (through a pipe), or invoke system commands. For example, the file $VULCAN/examples/help.scm
defines the function (help)
which display on-line help.
The public field display-server
indicates the display server associated with a system handle.
(set! my-handle (mstart (make <system-handle> :name ``labview''))) (set-system-handle! my-handle (labview-display ``glare'' 6800)) (update-var my-handle 'drive 5)end of example
See Example A.2 for how to use a display inside a control law.