Velocímetro Con MPU6050
Velocímetro Con MPU6050
Velocímetro Con MPU6050
Ingeniera mecatrnica
Sistemas micro electro mecnicos (MEMS)
Matas Combs Roberto
Centro de Enseanza Tcnica Industrial
Plantel: Colomos
Turno: Vespertino
Fecha: 03/05/16
Contenido
Introduccin ........................................................................................................................................ 3
Objetivos ............................................................................................................................................. 3
Marco terico ...................................................................................................................................... 4
Sistemas de referencia y coordenadas ........................................................................................... 4
Acelermetro .................................................................................................................................. 6
El MPU 6050 .................................................................................................................................... 7
Especificaciones .......................................................................................................................... 8
Conversin de aceleracin a velocidad: .......................................................................................... 8
Materiales ........................................................................................................................................... 9
Desarrollo .......................................................................................................................................... 10
Diagrama esquemtico ................................................................................................................. 10
Programa utilizado ........................................................................................................................ 10
Fotos de la prctica ....................................................................................................................... 24
Conclusiones ..................................................................................................................................... 25
Introduccin
La prctica consiste en utilizar algn dispositivo MEMS para realizar una
aplicacin de nuestra eleccin. Decidimos utilizar un acelermetro, el MPU-6050,
acelermetro de uso general en los ejes X, Y y Z, as como tambin cuenta con
giroscopio de 3 ejes.
Nuestra aplicacin es utilizar el acelermetro para poder medir la velocidad
aproximada de un cuerpo en desplazamiento, ya sea en el eje X o Y. El
acelermetro est posicionado sobre el cuerpo en movimiento, y la salida de
velocidad puede observarse en un arreglo de 3 display de 7 segmentos nodo
comn. La salida est en metros sobre segundo cuadrado.
El control de variables y procesos matemticos para la conversin de los datos del
acelermetro, as como la conversin de aceleracin a velocidad, al igual que el
control de los displays se realiz en el ARDUINO MEGA.
Objetivos
Marco terico
Sistemas de referencia y coordenadas
Para localizar un punto en un sistema de coordenadas, lo primero es definir un
sistema de referencia claro y a ser posible comn entre los diferentes
observadores. El ms habitual en nuestra cultura es el llamado sistema
cartesiano de referencia.
Por eso para definir la posicin de un avin necesitamos tres coordenadas para
fijar la posicin y 3 ngulos que definan la orientacin del avin con respecto a los
ejes del sistema de referencia. Esta forma de referenciar la posicin mediante
ngulos en lugar de distancias cartesianas se llaman coordenadas
angulares o polares.
Para controlar esas fuerzas se requieren sensores que nos den informacin
temprana de cualquier fuerza que acte sobre nuestra nave, para corregirla si se
puede y estabilizarla. Y hay dos tipos de sensores que se usan para
esto: Acelermetros y Girscopos.
El principio de funcionamiento de girscopos y acelermetros se funda en la
primera ley de Newton o ley de la inercia. Establece que todo objeto en
movimiento tiene a mantener su estado (Inercia) hasta que una fuerza externa lo
perturbe.
Acelermetro
Un acelermetro detecta las fuerzas de inercia que empujan al sensor y las
descomponen en las tres direcciones principales de referencia.
El MPU 6050
El circuito integrado contiene un acelermetro y giroscopio MEMS en un solo
empaque. Cuenta con una resolucin de 16 bits, lo cual significa que divide el
rango dinmico en 65536 fracciones, estos aplican para cada eje al igual que en la
velocidad angular.
Rango De Escala
Rango
De
Escala Sensibilidad del
Sensibilidad del
Completa
Completa Giroscopio
Giroscopio
Acelermetro
Acelermetro
250
131
16384
500
65.5
8192
1000
32.8
4096
2000
16.4
16
2048
Especificaciones
Interrupciones programables.
Materiales
Desarrollo
Diagrama esquemtico
Programa utilizado
#include <Event.h>
#include <Timer.h>
#include <TimerOne.h>
// I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class using DMP
(MotionApps v2.0)
// 6/21/2012 by Jeff Rowberg <[email protected]>
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
//
// Changelog:
// 2013-05-08 - added seamless Fastwire support
//
- added note about gyro calibration
//
//
//
//
//
//
//
//
//
//
//
/* ============================================
I2Cdev device library code is placed under the MIT license
Copyright (c) 2012 Jeff Rowberg
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
===============================================
*/
// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
//#include "MPU6050.h" // not necessary if using MotionApps include file
// http://en.wikipedia.org/wiki/Gimbal_lock)
//#define OUTPUT_READABLE_EULER
// uncomment "OUTPUT_READABLE_YAWPITCHROLL" if you want to see the yaw/
// pitch/roll angles (in degrees) calculated from the quaternions coming
// from the FIFO. Note this also requires gravity vector calculations.
// Also note that yaw/pitch/roll angles suffer from gimbal lock (for
// more info, see: http://en.wikipedia.org/wiki/Gimbal_lock)
//#define OUTPUT_READABLE_YAWPITCHROLL
// uncomment "OUTPUT_READABLE_REALACCEL" if you want to see acceleration
// components with gravity removed. This acceleration reference frame is
// not compensated for orientation, so +X is always +X according to the
// sensor, just without the effects of gravity. If you want acceleration
// compensated for orientation, us OUTPUT_READABLE_WORLDACCEL instead.
//#define OUTPUT_READABLE_REALACCEL
// uncomment "OUTPUT_READABLE_WORLDACCEL" if you want to see acceleration
// components with gravity removed and adjusted for the world frame of
// reference (yaw is relative to initial orientation, since no magnetometer
// is present in this case). Could be quite handy in some cases.
#define OUTPUT_READABLE_WORLDACCEL
// uncomment "OUTPUT_TEAPOT" if you want output that matches the
// format used for the InvenSense teapot demo
//#define OUTPUT_TEAPOT
quaternion container
VectorInt16 aa;
// [x, y, z]
accel sensor measurements
VectorInt16 aaReal; // [x, y, z]
gravity-free accel sensor measurements
VectorInt16 aaWorld; // [x, y, z]
world-frame accel sensor measurements
VectorFloat gravity; // [x, y, z]
gravity vector
float euler[3];
// [psi, theta, phi] Euler angle container
float ypr[3];
// [yaw, pitch, roll] yaw/pitch/roll container and gravity vector
float vReal[3]={0}; //[x, y, z]
float aReal[3]={0};
float aRealT[3]={0};
float aInterX[3]={0};
float aInterY[3]={0};
float aInterZ[3]={0};
int cont=0;
int cont2=0;
float Vel=0;
long T0=0;
Timer t;
// 0
// 1
// 2
// 3
// 4
// 5
// 6
// 7
// 8
// 9
// ================================================================
// ===
INTERRUPT DETECTION ROUTINE
===
// ================================================================
volatile bool mpuInterrupt = false;
void dmpDataReady() {
mpuInterrupt = true;
}
// ================================================================
// ===
INITIAL SETUP
===
// ================================================================
void setup() {
//
//
//
//
//
// ================================================================
// ===
MAIN PROGRAM LOOP
===
// ================================================================
void loop() {
// if programming failed, don't try to do anything
if (!dmpReady) return;
// wait for MPU interrupt or extra packet(s) available
while (!mpuInterrupt && fifoCount < packetSize) {
// other program behavior stuff here
// .
// .
// .
// if you are really paranoid you can frequently test in between other
// stuff to see if mpuInterrupt is true, and if so, "break;" from the
// while() loop to immediately process the MPU data
// .
// .
// .
}
Serial.print("euler\t");
Serial.print(euler[0] * 180/M_PI);
Serial.print("\t");
Serial.print(euler[1] * 180/M_PI);
Serial.print("\t");
Serial.println(euler[2] * 180/M_PI);
#endif
#ifdef OUTPUT_READABLE_YAWPITCHROLL
// display Euler angles in degrees
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
Serial.print("ypr\t");
Serial.print(ypr[0] * 180/M_PI);
Serial.print("\t");
Serial.print(ypr[1] * 180/M_PI);
Serial.print("\t");
Serial.println(ypr[2] * 180/M_PI);
#endif
//
//
//
//
//
//
#ifdef OUTPUT_READABLE_REALACCEL
// display real acceleration, adjusted to remove gravity
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetAccel(&aa, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
Serial.print("areal\t");
Serial.print(aaReal.x);
Serial.print("\t");
Serial.print(aaReal.y);
Serial.print("\t");
Serial.println(aaReal.z);
#endif
#ifdef OUTPUT_READABLE_WORLDACCEL
// display initial world-frame acceleration, adjusted to remove gravity
// and rotated based on known orientation from quaternion
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetAccel(&aa, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
//
//
//
//
//
//
#ifdef OUTPUT_TEAPOT
// display quaternion values in InvenSense Teapot demo format:
teapotPacket[2] = fifoBuffer[0];
teapotPacket[3] = fifoBuffer[1];
teapotPacket[4] = fifoBuffer[4];
teapotPacket[5] = fifoBuffer[5];
teapotPacket[6] = fifoBuffer[8];
teapotPacket[7] = fifoBuffer[9];
teapotPacket[8] = fifoBuffer[12];
teapotPacket[9] = fifoBuffer[13];
Serial.write(teapotPacket, 14);
teapotPacket[11]++; // packetCount, loops at 0xFF on purpose
#endif
//
//
//
}
}
void CalculoVel()
{
if(cont >= 2000)//tiempo de estabilizacin del acelermetro
{
if(cont2>2)
{
aRealT[0]=(aInterX[0]+aInterX[2])/2;
aRealT[1]=(aInterY[0]+aInterY[2])/2;
aRealT[2]=(aInterZ[0]+aInterZ[2])/2;
for(int i=1;i<=2;i++)
{
aInterX[i-1]=aInterX[i];
aInterY[i-1]=aInterY[i];
aInterZ[i-1]=aInterZ[i];
}
noInterrupts();
// aRealT[0]=aaWorld.x;
// aRealT[1]=aaWorld.y;
// aRealT[2]=aaWorld.z;
aInterX[2]=aaWorld.x;
aInterY[2]=aaWorld.y;
aInterZ[2]=aaWorld.z;
interrupts();
for(int i=0;i<3;i++)
{
if(aRealT[i]<=50 && aRealT[i]>=-50)
{
aRealT[i]=0;
}
else if(aRealT[i]<=0)
{
aRealT[i]+=50;
}
else
{
aRealT[i]-=50;
}
}
aReal[0]=aRealT[0]*9.81/8192;//para que est en "g" y pasarlo a m/s^2
aReal[1]=aRealT[1]*9.81/8192;
aReal[2]=aRealT[2]*9.81/8192;
vReal[0]=vReal[0]+(aReal[0]*0.01);
vReal[1]=vReal[1]+(aReal[1]*0.01);
vReal[2]=vReal[2]+(aReal[2]*0.01);
Vel= sqrt (pow(vReal[0],2)+pow(vReal[1],2));
// Serial.println(Vel,4);
Vel=Vel*100;
}
else
{
noInterrupts();
aInterX[cont2]=aaWorld.x;
aInterY[cont2]=aaWorld.y;
aInterZ[cont2]=aaWorld.y;
interrupts();
cont2++;
}
}
else
{
cont++;
}
}
void Display(int pos, int N)
{
digitalWrite(42,LOW);
digitalWrite(38,LOW);
digitalWrite(40,LOW);
int Digit1;
int Digit2;
if(Num <= 99)
{
Digit0= Num % 10;
Digit1= Num/10;
Digit2= 0;
}
else
{
Digit0 = Num %10 ;
Digit1 = (Num % 100) / 10 ;
Digit2 = Num / 100 ;
}
Display(42 , Digit2);
delay(4);
Display(38 , Digit1);
delay(4);
Display(40 , Digit0);
}
void Temp()
{
if(cont>=2000)
{
CalculaDigitos((int)Vel);
}
}
void RESET()
{
if ( millis() > T0 + 250)
{
vReal[0]=0;
vReal[1]=0;
vReal[2]=0;
T0 = millis();
}
}
Fotos de la prctica
Conclusiones