Vizard 6 » Reference » Input Devices » VRPN plug-in
6.3

VRPN plug-in

This plug-in provides support for VRPN input devices. VRPN is a popular protocol for communicating with VR peripherals. It supports many devices including WorldViz PPT, ART, NaturalPoint OptiTrack, and much more. For more information visit the VRPN website.

 

Note: The VRPN 6 version of the plug-in is not supported on 64-bit versions of Vizard

Background

The Virtual Reality Peripheral Network (VRPN) is a tool set that has been made available to the public domain by Russell M. Taylor II at the University of North Carolina at Chapel Hill. It is designed to implement a network-transparent interface between application programs and the set of physical devices (tracker, etc.) used in a virtual-reality (VR) system. The idea is to have a PC or other host at each VR station that controls the peripherals (tracker, button device, haptic device, analog inputs, sound, etc). VRPN provides connections between the application and all of the devices using the appropriate class-of-service for each type of device sharing this link.

 

Vizard allows you to use VRPN in either of two configurations: 1) all your devices are connected to the same machine which is rendering your virtual scenes, or 2) some or all of your input devices are attached to other machines but are connected to the rendering machine via a network.

Initialization

The VRPN plug-in is implemented as a Vizard extension. Vizard supports both VRPN 6 & 7. To use VRPN 6 use the vrpn6.dle extension. To use VRPN 7 use the vrpn7.dle extension. The VRPN extension object has the following methods and constants:

 

Method

Description

<vrpn>.addTracker(address,sensor=0)

Returns the 6DOF tracker at the specified IP address/hostname. Can optionally specify the sensor number if it is supported by the tracker.

<vrpn>.addButton(address)

Returns the VRPN button device at the specified IP address/hostname. The device is an extension sensor which only provides button data.

<vrpn>.addAnalog(address)

Returns the VRPN analog device at the specified IP address/hostname. The device is an extension sensor which only provides raw data , <extSensor>.getData().

 

Note: The length of the analog data array is initially set to the maximum value supported by VRPN. When the analog tracker receives its first update, it will resize the data array to the value provided by the tracker.

 

The VRPN tracker, button, and analog objects all share the following methods:

 

Method

Description

<object>.getSampleNumber()

Returns the number of samples received from the server, since the script started.

<object>.getSampleTime()

Returns the time of the last update packet from the server, in seconds.

<object>.getTimestamp()

Returns the raw timestamp values from the last update packet from the server. This will return a tuple containing the seconds and microseconds of the timestamp, both as integers.

<object>.waitForSample(timeout=0.5)

Waits for a new data sample to arrive or until the number of seconds specified by timeout elapses. Returns True if a new sample arrived within the timeout, otherwise False is returned.

<object>.setVerbose(mode) Set verbosity of "no connection" messages. mode should be a True or False value. Defaults to True. Not supported under VRPN 6.
<object>.getVerbose() Get verbosity of "no connection" messages. Not supported under VRPN 6.
<object>.getConnected() Returns whether a connection to the server has been established.
<object>.waitForConnection(timeout=0.5) Waits for the connection to the server to be established or until the number of seconds specified by timeout elapses. Returns whether a connection was established.

 

The VRPN tracker object has the following additional methods:

 

Method

Description

<tracker>.swapPos(swap)

Specifies the swap indices for the position data. The indices are 1-based, so 1 refers to the X coordinate, 2 is Y, and 3 is Z. Negative indices will negate the incoming data.

<tracker>.swapQuat(swap)

Specifies the swap indices for the quaternion data. The indices are 1-based, so 1 refers to the X coordinate, 2 is Y, 3 is Z, and 4 is W. Negative indices will negate the incoming data.

<tracker>.setPositionScale(scale) Set the scale factor for position data.
<tracker>.getPositionScale() Get the scale factor for position data.
<tracker>.getSensorID() Returns the sensor ID number specified during creation of the tracker.
<tracker>.getFlag()

Returns the status flag for PPT sensors (Requires PPT 3.40.6488 or greater). Can be any combination of the following bit flags:

 

<vrpn>.PPT_POSITION_SUPPORTED Indicates the PPT sensor supports position data.
<vrpn>.PPT_ROTATION_SUPPORTED Indicates the PPT sensor supports rotation data.
<vrpn>.PPT_POSITION_FOUND Indicates the PPT sensor position was found and computed for the last frame of data.
<vrpn>.PPT_ROTATION_FOUND Indicates the PPT sensor rotation was found and computed for the last frame of data.

Example

The following example connects to a VRPN 6 tracker on the machine "remote":

 

vrpn = viz.add('vrpn6.dle')
tracker = vrpn.addTracker('Tracker0@remote)

 

The following example connects to two sensors of a VRPN 7 tracker on the local machine:

 

vrpn = viz.add('vrpn7.dle')
tracker1 = vrpn.addTracker('Tracker0@localhost') #Default sensor is 0
tracker2 = vrpn.addTracker('Tracker0@localhost',1)

 

The following example connects to a VRPN 7 button object and registers a callback to print when a button is pressed/released:

 

vrpn = viz.add('vrpn7.dle')
button = vrpn.addButton('Joystick0@hostname')

def onButtonDown(e):
    if e.object is button:
        print 'button',e.button,'down'
viz.callback(viz.SENSOR_DOWN_EVENT,onButtonDown)

def onButtonUp(e):
    if e.object is button:
        print 'button',e.button,'up'
viz.callback(viz.SENSOR_UP_EVENT,onButtonUp)

 

The following example connects to a VRPN 7 analog object using an IP address and prints out the data:

 

vrpn = viz.add('vrpn7.dle')
analog = vrpn.addAnalog('Joystick0@192.168.0.52')
print analog.getData()

A.R.T. System

The following reference is for the A.R.T. tracking system that allows manual rotation from left-handed to right-handed coordinate system.

 

The following code will do a right-to-left conversion.

 

vrpn = viz.add('vrpn6.dle')   # can be vrpn6.dle or vrpn7.dle depending on vrpn version
headTrkr = vrpn.addTracker('Tracker0@hostname')

#Negate Z value of position
headTrkr.swapPos([1,2,-3])

#Negate X,Y value of quaternion
headTrkr.swapQuat([-1,-2,3,4])

 

For more information on the A.R.T. system, please visit http://www.ar-tracking.de/