Technical reference > Sensors > How to use


General description of sensors

Sensors are peripheral devices connected to your computer that relay information about the physical world.
Regarding tracking, a sensor is a device used to track the location or orientation of the observer’s head (or
body).  See the tutorial here for examples of tracking devices and/or follow the discussion below.

Automatic attachments to eyepoint

When a sensor is added to the environment, there is a simple method already established which will use the data from the device to automatically control the observer.  Sensor devices can control any one or more of the following observer parameters:
Head position
Head orientation
Body orientation
After adding one or more sensors to the environment, the command to activate automatic observer tracking is tracker().  This command will scan through the list of trackers that have been added and use the data in a hopefully intelligent manner.  If more than one sensor has been added to the environment, then it is important that not more than one sensor has as its default type the same parameters (eg., if two added sensors are both "Head position" devices then a parameter collision error will result).  In the event that you want to add another sensor to the environment but do not want it used by the automatic tracking mode, then you simply add the additional sensors after the tracker() command in the script.

It is worth remembering that almost all sensors have a default method called reset() which will do the appropriate resetting or zero'ing of the device.  For a position tracker, it will offset the data so that it now appears as though the observer is standing at the origin.  For an orientation tracker, it will point the orientation to virtual North (yaw = 0), and depending on the device may or may not reset pitch and roll also to zero.

ADVANCED USERS:  There is an experiment command that can allow you to change the sensor type.  For instance, if you have a sensor that has been created as a HEAD_POS and HEAD_ORI device and you want to substitute another device in for orientation tracking, you can override the default type using the sensor type() command.  This example shows how to use the "shootingstar" tracker (which by default provides HEAD_POS and  HEAD_ORI) with an "intersense" tracker that only provides HEAD_ORI.
 

tracker1 = vrut.addsensor('shootingstar')
tracker1.type(vrut.HEAD_ORI)

tracker2 = vrut.addsensor('intersense')

vrut.tracker()

Automatic attachments to objects

When a sensor is added to the environment, there is a simple method already established which will use the data from the device to automatically control the observer.  Sensor devices can control any one or more of the following object parameters:
Object position
Object orientation
To attach a sensor to an object, you simple issue the sensor() child method and pass it the sensor object you want to use.  For instance, to use a "shootingstar" tracker to control the position and orientation of an object, you might try something like the following:
 
hand = vrut.addchild('disembodied_hand.wrl')
tracker = vrut.addsensor('shootingstar')

hand.sensor(tracker)

Manually using sensors to control eyepoint or objects

When the automatic methods do not produce the results you're looking for, you can always access the data from the sensor and directly transform the observer or objects in the environment using VRUT commands.  As a simple example, say you want to increase the position gain on the "shootingstar" tracker by a factor of 3.  The following is used to access the (X, Y, Z) data from the sensor and then use VRUT translate command to move the eye point around in realtime with the appropriate gain factor.  Note that the eyepoint is being "manually" controlled and that the tracker() command is never issued.
import vrut
vrut.go()

vrut.addchild('tut_ground.wrl')
tracker = vrut.sensor('shootingstar')

def mytimer(num):
    data = tracker.get()
    x = data[0]
    y = data[1]
    z = data[2]
    vrut.translate(vrut.HEAD_POS, x, y, z)
    vrut.starttimer(0)

vrut.callback(vrut.TIMER_EVENT, 'mytimer')
vrut.starttimer(0, .5)

The same method can be used to control the orientation of the observer.  Likewise, the same method can be used to control the position and orientation of objects in the environment.