Kyneo MARG Attitude Sensors

Introduction

IMU are the initials for Inertial Measuring Unit, this term is used to refer to of the accelerometers and gyroscopes, which, besides the magnetometer form the MARG (Magnetic, Angular Rate and Gravity) unit. This unit will provide an accurate reading on the boards spatial orientation.
In the following examples, we will show how to extract certain data from this units.

Raw data

Kyneo merges the measurements sent from the accelerometer-gyroscope, the magnetometer and the barometer to estimate the attitude with a high precision. In the following example, we will show how to obtain the values of the orientation sensors. The units of the data are stated bellow.

– The accelerometer columns values will oscillate between 1 and -1. If no sudden movements are made are made, the acceleration movements on each one of the axes will be related to the gravity. For example, when Kyneo is placed horizontally and with the GNSS module on the upper side, the acceleration value of the third column should be -1, since in that position Kyneo has its Z axis looking to earth.

– The gyroscope columns register the angular velocities on each one of the axes. In this way, making rapid turns forward and backward with respect to an axis we’ll be able to see the value changes only in one of the columns (or, at least, the bigger change will happen in one of them).

– The magnetometer columns show the magnetic field measurement on each one of the axes. If the device is placed on a low magnetic influence environment (far from big metallic objects and electronic devices), the only thing to be measured will be the Earth magnetic field, so aligning one of Kyneo’s axes with the North-South line we’ll obtain the maximum value of the magnetic field on that axis.

Example Sketch Code – IMU raw data

/**************************************************************************************************
 * Kyneo IMU raw data example
 * 
 * This sketch prints sensors data through serial. It uses FreeIMU library (by Fabio Varesano), 
 * which has been adapted to support Kyneo board.
 * Kyneo MARG includes:
 *  - A 3-axis accelerometer + gyroscope (MPU6050): 16-bit ADC converter, auxiliary and primary I2C
 *    interfaces,
 *  - A magnetometer (HMC5883): 12-bit ADC converter, I2C interface (connected to MPU6050), 
 *  - A barometric altimeter (MS561101BA): 24-bit ADC for temperature and pressure sensors, I2C
 *    interface.
 * 
 * 
 * Created by GEKO Navsat S.L. for Kyneo V2.0 board
 * 
 * This example is free software, given under a GPL3 license
 * 
 * KYNEO is a product designed by GEKO Navsat S.L. in Europe http://www.gekonavsat.com
 * For further information, visit: http://kyneo.eu/
 * 
 *************************************************************************************************/
#include <KyneoBoard.h>                                 //GekoNavsat libraries
#include <FreeIMU.h>

FreeIMU kyneoIMU;                                       //Object definition

int LoopRate = 10;  //milliseconds                      //Variable definition
int raw[11];
int counter = 9;


void setup()
{
  Serial.begin(9600);
  
  Wire.begin();
  kyneoIMU.init();
  
  Serial.println("Setup done\n");
}

void loop()
{
  counter++;
  if(counter == 10){                                    // Prints column titles every 10 lines
    counter = 0;  
    Serial.println("acc_x\tacc_y\tacc_z\tgyr_x\tgyr_y\tgyr_z\tmag_x\tmag_y\tmag_z\tTemp\tAlt");  
  }
                                                                            
  kyneoIMU.getRawValues(raw);                                               
  Serial.print((float)raw[0]/2048, 2);                                    // acc_x
  Serial.print("\t");
  Serial.print((float)raw[1]/2048, 2);                                    // acc_y
  Serial.print("\t");
  Serial.print((float)raw[2]/2048, 2);                                    // acc_z
  Serial.print("\t");
  Serial.print((float)raw[3]/16.384, 2);                                  // gyr_x
  Serial.print("\t");
  Serial.print((float)raw[4]/16.384, 2);                                  // gyr_y
  Serial.print("\t");
  Serial.print((float)raw[5]/16.384, 2);                                  // gyr_z
  Serial.print("\t");
  Serial.print((float)raw[6]/1.707, 1);                                   // mag_x
  Serial.print("\t");
  Serial.print((float)raw[7]/1.707, 1);                                   // mag_y
  Serial.print("\t");
  Serial.print((float)raw[8]/1.707, 1);                                   // mag_z
  Serial.print("\t");
  Serial.print(kyneoIMU.baro.getTemperature(MS561101BA_OSR_4096), 1);     // temp
  Serial.print("\t");
  Serial.println(kyneoIMU.getBaroAlt(), 2);                               // pres
  
  delay(LoopRate);
}
/*********************************************************************************
// Printed measures: 
//  accelerometer xyz - in g (1 g = 9.806 m/s2), dividing by +- 16g scale factor. 
//  gyroscope xyz - in deg/s, dividing by +-2000 deg/s scale factor. 
//  magnetometer xyz - in milliGauss, dividing by +-1.2 Gauss scale factor.
//  temperature (ºC) and altitude (m) 
**********************************************************************************/

Attitude

In aeronautics, we usually talk about the Euler angles: Roll, Pitch and Yaw. Representing these the orientation of the reference axis of the aircraft. The axis distribution on any airplane are as shown in the picture at the right, the axis on the Kyneo have to be taken assuming that the Kyneo’s nose points towards on the x direction (painted on the board).

Example Sketch Code – Euler angles

/**************************************************************************************************
 * Kyneo Euler angles Example
 * 
 * This sketch shows the euler angles of the board in the serial monitor or plotter
 * Created by GEKO Navsat S.L. for Kyneo V2.0 board
 * 
 * This example is free software, given under a GPL3 license
 * 
 * KYNEO is a product designed by GEKO Navsat S.L. in Europe http://www.gekonavsat.com
 * For further information, visit: http://kyneo.eu/
 * 
 *************************************************************************************************/
#include <KyneoBoard.h>                                 //GekoNavsat libraries
#include <FreeIMU.h>

FreeIMU kyneoIMU;                                       //Object definition

int LoopRate = 10;  //milliseconds                      //Variable definition
float att[3];
 

void setup() {
  
  Serial.begin(9600);
  
  Wire.begin();
  kyneoIMU.init();
  
  Serial.print("Setup done\n");
}

void loop() {
  kyneoIMU.getYawPitchRoll(att);                          // Sensor read

  Serial.print("Yaw: ");                                // Data Print
  Serial.print(att[0]);
  Serial.print(",");
  Serial.print(" Pitch: ");
  Serial.print(att[1]);
  Serial.print(",");
  Serial.print(" Roll: ");
  Serial.println(att[2]);
  
  delay(LoopRate);
}

Quaternions

The following example shows the obtention of the orientation Quaternions. Quaternions are an alternative way to represent the spatial orientation and rotation of an object. They are more compact, more stable and may be more efficient, thus their use is widely spread in a variety of applications.

 

Example Sketch Code – Quaternions

/**************************************************************************************************
 * Kyneo Quaternion example
 * 
 * This sketch prints the quaternions used to show for orientation and rotations of the system.
 * 
 * 
 * Created by GEKO Navsat S.L. for Kyneo V2.0 board
 * 
 * This example is free software, given under a GPL3 license
 * 
 * KYNEO is a product designed by GEKO Navsat S.L. in Europe http://www.gekonavsat.com
 * For further information, visit: http://kyneo.eu/
 * 
 *************************************************************************************************/
#include <KyneoBoard.h>                                 //GekoNavsat libraries
#include <FreeIMU.h>

FreeIMU kyneoIMU;                                       //Object definition

int LoopRate = 10;  //milliseconds                      //Variable definition
float q[4];
int counter = 9;


void setup() {
  
  Serial.begin(9600);
  
  Wire.begin();
  kyneoIMU.init();
  
  Serial.println("Setup done\n");
}

void loop() 
{ 
  counter++;
  if(counter == 10){                                                        // Prints column titles every 10 lines
    counter = 0;  
    Serial.println("q0\tq1\tq2\tq3"); 
  }

  kyneoIMU.getQ(q);
  Serial.print(q[0]);
  Serial.print("\t");
  Serial.print(q[1]);
  Serial.print("\t");
  Serial.print(q[2]);
  Serial.print("\t");
  Serial.println(q[3]);
  
  delay(LoopRate);
}

Link to software repository

More information about Kyneo go to Kyneo Manual
For all the latest software visit our GitHub page GEKO Navsat Github's examples
Posted in Tutorials.