Azimuth, pitch, and roll

The azimuth, pitch, and roll values provide the following positioning information about the device:
  • azimuth: the heading of the device, which is the angle between the device's y-axis and magnetic north.
  • pitch: the rotation around the device's x-axis.
  • roll: the rotation around the device's y-axis.

Azimuth, pitch, and roll values are reported in degrees.

A BPS event with the code SENSOR_AZIMUTH_PITCH_ROLL_READING is generated when new azimuth, pitch, and roll values are available. You can call the function sensor_event_get_apr() to retrieve the azimuth, pitch, and roll values from the event.

The code sample below demonstrates how you can use the azimuth, pitch, and roll sensor in your app:

#include <stddef.h>
#include <bps/bps.h>
#include <bps/sensor.h>

int main(void)
{
  int event_domain;
  unsigned int event_code;

  // Create variables to store the current 
  // azimuth, pitch, and roll values.
  float azimuth, pitch, roll;

  bps_initialize();

  if (sensor_is_supported(SENSOR_TYPE_AZIMUTH_PITCH_ROLL))
  {
    sensor_request_events(SENSOR_TYPE_AZIMUTH_PITCH_ROLL);
  }

  while (1)
  {
    bps_event_t *current_event = NULL;
    bps_get_event(&current_event, -1);

    event_domain = bps_event_get_domain(current_event);
    event_code = bps_event_get_code(current_event);

    if (event_domain == sensor_get_domain())
    {
      switch (event_code)
      {
        case SENSOR_AZIMUTH_PITCH_ROLL_READING:
          // Get current azimuth, pitch, and roll values.
          sensor_event_get_apr(current_event, 
                               &azimuth, 
                               &pitch, 
                               &roll);
          // Adjust application based on the azimuth, 
          // pitch, and roll values.
          break;

        default:
          break;
      }
    }
  }

  // Program cleanup
  sensor_stop_events(SENSOR_TYPE_GYROSCOPE);
  bps_shutdown();

  return 0;
}                
            

Last modified: 2013-12-21



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus