OpenGL sensors

OpenGL sensors is a sample application that demonstrates sensor capabilities of a mobile device.

Currently, OpenGL sensors supports the following functions:

  • Show a pyramid that always points up, or a compass needle that always points towards the magnetic north pole, regardless of how you hold the phone.
  • It can connect to the SensorSimulator for demonstrating sensor input on the emulator.
  • Select different sensors to be tested from accelerometer, compass, orientation, or a combination of accelerometer and compass.

Try it out

  • When you start the application, you see a pyramid that is always oriented to point upwards. At least, on a real device with sensors it would do so by default. In the emulator, you will only see the tip of the pyramid. This is to be expected, because the emulator only returns the values 0,0,0 for the orientation sensor, and the mobile phone is assumed to lie flat on the table in front of you.
  • In order to see the pyramid from different perspectives, you either have to use the application on a device with real sensors, or connect to the SensorSimulator.
  • Open the "Settings..." menu to access settings to connect to the SensorSimulator (find details on the connection there).
  • Press menu "Connect".
  • Now the pyramid should follow the movements of the simulated mobile device in the SensorSimulator.
  • Try to tilt the mobile device in the SensorSimulator upside down by moving the pitch slider - the pyramid in the emulator should also point downward. (If you think of the device in the real world being upside down, then the pyramid would actually point upwards again!)
  • The sensor that is being used by default is the orientation sensor. The orientation sensor is the best sensor for three-dimensional orientation as it tells the device yaw, pitch, and roll values.
  • You can choose a different sensor from the menu "Sensor types" (see below).
  • From menu "Sensor types", select the "accelerometer".
  • Note that the accelerometer does not give any direction (bearing) information. The pyramid can still point upward (because the accelerometer indicates the direction in which gravity pulls), but it will not rotate if you use the yaw slider to rotate the mobile device in the simulator. To obtain direction information, one may use the compass.
  • Select menu "Sensor types" - "compass".
  • This will show a compass needle that always points in the direction of the magnetic north pole. Note that the magnetic north pole does not fully coincide with the geographic north pole, to which the orientation sensor is calibrated. Also note that there is a large inclination (the magnetic north pole is actually located pointing downwards). See below for some other trivia about the magnetic poles.
  • Select menu "Sensor types" - "accelerometer + compass".
  • A substitute for an orientation sensor can therefore be built from a combination of accelerometer and compass: Two directions (the direction of gravity, and the direction of the magnetic field vector) fully specify a three-dimensional orientation. Note that the pyramid does not follow the rotation when you yaw the mobile device in the simulator, but the compass needle does.
  • The OpenGL application can also deal with devices that do not have all sensors available.
  • To test this, select menu "Disconnect". Now, in the SensorSimulator desktop application, disable any of the sensors "accelerometer", "compass", or "orientation". When you "Connect" again in the OpenGL sensors application and open Menu "Sensor types", only the available sensors are displayed. Additionally, as soon as you connect, only an available sensor will be used for input.


Menu functions

Settings...: Opens the SensorSimulator settings activity.
Connect/Disconnect: Connects to the sensor simulator or disconnects from it. If the SensorSimulator is disconnected, actual mobile device sensor data are used. (On the emulator, this is currently always 0,0,0 for accelerometer, compass, and orientation sensors).
Sensor type: Opens a submenu for choosing a sensor type (see below).

Sensor type selection

You can select any of the following sensors for input: accelerometer, compass, orientation, or a combination of accelerometer + compass. (Details are explained above in the section "Try it out").


Trivia on the compass magnetic poles

(from Wikipedia: http://en.wikipedia.org/wiki/North_Magnetic_Pole )
"In physics, all magnets have two poles that are distinguished by the direction of the magnetic flux. In principle these poles could be labeled in any way; for example, as "+" and "−", or "A" and "B". However, based on the early use of magnets in compasses they were named the "north pole" ("N") and the "south pole" ("S"), with the north pole being the pole that pointed north. When it was later understood that opposite poles attract, a terminological dilemma arose: the Earth's North Magnetic Pole and the pole of the magnet that was attracted to it could not have the same polarity. By convention, the "north pole" of a magnet remained defined as the one attracted to the Earth's North Magnetic Pole, and by this definition the Earth's North Magnetic Pole is physically a magnetic south pole. Conversely, the Earth's South Magnetic Pole is physically a magnetic north pole."