next up previous contents index
Next: Trackers Up: System Handles Previous: Replaying a log

   
Display Servers

A display server consists of a set of variables (fields, slots) and rules associated with these variables. Whenever the value of a variable is changed, all the associated rules are executed (fired). A rule is a function of two arguments. When the rule is invoked, the first argument is the value of the variable the rule is associated with, and the second argument is the server such variable is associated with. The name display server derives from the fact that the standard application of a display server is to display data online.

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: The method (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.

Example 5  

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


  
Figure: Lavbiew drive and turn speedometers.
5#5

(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.
end of example

  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.

Example 6  

(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.


next up previous contents index
Next: Trackers Up: System Handles Previous: Replaying a log
Emilio Remolina
2000-10-04