Skip to content
javierre edited this page May 20, 2019 · 12 revisions

IMU de 10 Grados de libertad

Este sensor inercial tiene incorporados un acelerómetro de 3 ejes (de +/-16g), un magnetómetro de 3 ejes (de +/-8.1 gauss), un giróscopo de 3 ejes (de +/-2000 dps) y un sensor barométrico BMP180.

IMU

El fabricante nos indica la funcionalidad de algunos pines, que es:

Vin  - 3V3  to 5V
GINT - The interrupt pin on the L3GD20 gyroscope
GRDY - The 'ready' pin on the L3GD20 gyroscope
LIN1 - Interrupt pin 1 on the LSM303DLHC
LIN2 - Interrupt pin 2 on the LSM303DLHC
LRDY- The ready pin on the LSM303DLHC

Para usarlo es necesario instalar las librerías descritas en este enlace.

IMU Wiring

Con este sensor podemos calcular la orientación RPY (Roll-Pitch-Yaw) de un robot:

IMU Wiring

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_L3GD20_U.h>
#include <Adafruit_10DOF.h>

/* Assign a unique ID to the sensors */
Adafruit_10DOF                dof   = Adafruit_10DOF();
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301);
Adafruit_LSM303_Mag_Unified   mag   = Adafruit_LSM303_Mag_Unified(30302);



/**************************************************************************/
/*!
    @brief  Initialises all the sensors used by this example
*/
/**************************************************************************/
void initSensors()
{
  if(!accel.begin())
  {
    /* There was a problem detecting the LSM303 ... check your connections */
    Serial.println(F("Ooops, no LSM303 detected ... Check your wiring!"));
    while(1);
  }
  if(!mag.begin())
  {
    /* There was a problem detecting the LSM303 ... check your connections */
    Serial.println("Ooops, no LSM303 detected ... Check your wiring!");
    while(1);
  }
}

/**************************************************************************/
/*!

*/
/**************************************************************************/
void setup(void)
{
  Serial.begin(9600);
  Serial.println(F("Adafruit 10 DOF Pitch/Roll/Heading Example")); Serial.println("");
  
  /* Initialise the sensors */
  initSensors();
}

/**************************************************************************/
/*!
    @brief  Constantly check the roll/pitch/heading/altitude/temperature
*/
/**************************************************************************/
void loop(void)
{
  sensors_event_t accel_event;
  sensors_event_t mag_event;
  sensors_vec_t   orientation;

  /* Calculate pitch and roll from the raw accelerometer data */
  accel.getEvent(&accel_event);
  if (dof.accelGetOrientation(&accel_event, &orientation))
  {
    /* 'orientation' should have valid .roll and .pitch fields */
    Serial.print(F("Roll: "));
    Serial.print(orientation.roll);
    Serial.print(F("; "));
    Serial.print(F("Pitch: "));
    Serial.print(orientation.pitch);
    Serial.print(F("; "));
  }
  
  /* Calculate the heading using the magnetometer */
  mag.getEvent(&mag_event);
  if (dof.magGetOrientation(SENSOR_AXIS_Z, &mag_event, &orientation))
  {
    /* 'orientation' should have valid .heading data now */
    Serial.print(F("Heading: "));
    Serial.print(orientation.heading);
    Serial.print(F("; "));
  }

  
  
  Serial.println(F(""));
  delay(1000);
}

IMU

Códigos para mostrar datos

Códigos para mostrar Roll, Pitch, Yaw

Clone this wiki locally