Vizard 8 » Reference » Input Devices » Sensor basics
8.1

Sensor Basics

Sensors are plug-ins that interface between Vizard and hardware. Sensors make the functions and data provided by the hardware manufacturers' APIs available to Vizard. One of Vizard's strengths is the variety of hardware connections it supports as standard features. You will want to work directly with sensor objects if you need access to the raw sensor data (e.g., you are performing a special function with the data or perhaps saving the data to disk).

 

To access a sensor's data:

  1. Include "viz.add(sensorPlugin)" in your script.
  2. Replace sensorPlugin with the sensor filename.
  3. Use one of the <sensor>.get methods to access the sensor's data.

Example:

myTracker = viz.add('sensor.dls')   # Connect to a sensor
print(myTracker.getPosition() )# Print sensor position
print(myTracker.getEuler() )# Print sensor euler rotation
data = myTracker.getData()  # Access the raw data from the sensor
print(data  )# Print the array of data

Most sensors represent a 3DOF or 6DOF device. In this case you should use the following methods to get position/rotation data from the sensor.

Sensor method

Description

<sensor>.getPosition(flag=0)

Get the [x,y,z] position.

<sensor>.getEuler(flag=0)

Get the [yaw,pitch,roll] euler rotation.

<sensor>.getAxisAngle(flag=0)

Get the [x,y,z,deg] axis-angle rotation.

<sensor>.getQuat(flag=0)

Get the [x,y,z,w] quaternion rotation.

<sensor>.getMatrix(flag=0)

Get the 4x4 transform matrix.

The flag parameter is optional. Some sensors provide multiple position/rotations values, in which case the flag parameter specifies which value to retrieve.

 

There are special sensors which don't contain any position/rotation data (e.g. 5DT, Cyberglove), or regular sensors which contain extra information. In these cases you can use the following method to retrieve the raw data:

Sensor method

Description

<sensor>.getData()

Returns a list of floating point values. The size of the list depends on the sensor.

You can also retrieve the name of a sensor using the following method:

Sensor method

Description

<sensor>.getName()

Returns the name of the sensor.

Extension sensors

Extension sensors are a newer form of sensors that support more advanced behaviors. The interface for extension sensors is similar to regular sensors. Extension sensors can also support button data, which can be accessed through the following methods:

Sensor method

Description

<extSensor>.getButtonState()

Get the state of the buttons as a bit flag.

<extSensor>.getButtonCount()

Get the number of buttons on sensor.

<extSensor>.isButtonDown(button)

Returns whether the specified button is currently down.

Extension sensors can also trigger the following button related events:

Sensor event

Description

viz.SENSOR_DOWN_EVENT

Called when a sensor button is pressed.

viz.SENSOR_UP_EVENT

Called when a sensor button is released.

See also

In this section:

Input devices introduction

Native device support