Problème Calibration MPU 6050


bonjour à tous !

j'ai un soucis pour calibrer mon mpu6050 (gy-521), et ce qu'importe les codes téléversés.
le problème est toujours le même, après le message suivant :

" send character start sketch.


mpu6050 calibration sketch

your mpu6050 should placed in horizontal position, package letters facing up.
don't touch until see finish message.

mpu6050 connection successful

reading sensors first time...

calculating offsets...
...
...
...
...
... "


et à partir d'ici, il ne se passe plus rien, même les points de suspension ne défilent plus.

voici le code utilisé, on le trouve un peu partout sur internet :

code: [select]
// arduino sketch returns calibration offsets mpu6050 //   version 1.1  (31th january 2014)
// done luis ródenas <luisrodenaslorda@gmail.com>
// based on i2cdev library , previous work jeff rowberg <jeff@rowberg.net>
// updates (of library) should (hopefully) available @ https://github.com/jrowberg/i2cdevlib

// these offsets meant calibrate mpu6050's internal dmp, can useful reading sensors.
// effect of temperature has not been taken account can't promise work if
// calibrate indoors , use outdoors. best calibrate , use @ same room temperature.

/* ==========  license  ==================================
 i2cdev device library code placed under mit license
 copyright (c) 2011 jeff rowberg
 
 permission hereby granted, free of charge, person obtaining copy
 of software , associated documentation files (the "software"), deal
 in software without restriction, including without limitation rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of software, , permit persons whom software is
 furnished so, subject following conditions:
 
 the above copyright notice , permission notice shall included in
 all copies or substantial portions of software.
 
 the software provided "as is", without warranty of kind, express or
 implied, including not limited warranties of merchantability,
 fitness particular purpose , noninfringement. in no event shall the
 authors or copyright holders liable claim, damages or other
 liability, whether in action of contract, tort or otherwise, arising from,
 out of or in connection software or use or other dealings in
 the software.
 =========================================================
 */

// i2cdev , mpu6050 must installed libraries
#include "i2cdev.h"
#include "mpu6050.h"
#include "wire.h"

///////////////////////////////////   configuration   /////////////////////////////
//change 3 variables if want fine tune skecth needs.
int buffersize=1000;     //amount of readings used average, make higher more precision sketch slower  (default:1000)
int acel_deadzone=8;     //acelerometer error allowed, make lower more precision, sketch may not converge  (default:8)
int giro_deadzone=1;     //giro error allowed, make lower more precision, sketch may not converge  (default:1)

// default i2c address 0x68
// specific i2c addresses may passed parameter here
// ad0 low = 0x68 (default invensense evaluation board)
// ad0 high = 0x69
//mpu6050 accelgyro;
mpu6050 accelgyro(0x68); // <-- use ad0 high

int16_t ax, ay, az,gx, gy, gz;

int mean_ax,mean_ay,mean_az,mean_gx,mean_gy,mean_gz,state=0;
int ax_offset,ay_offset,az_offset,gx_offset,gy_offset,gz_offset;

///////////////////////////////////   setup   ////////////////////////////////////
void setup() {
  // join i2c bus (i2cdev library doesn't automatically)
  wire.begin();
  // comment next line if using arduino due
  twbr = 24; // 400khz i2c clock (200khz if cpu 8mhz). leonardo measured 250khz.

  // initialize serial communication
  serial.begin(115200);

  // initialize device
  accelgyro.initialize();

  // wait ready
  while (serial.available() && serial.read()); // empty buffer
  while (!serial.available()){
    serial.println(f("send character start sketch.\n"));
    delay(1500);
  }               
  while (serial.available() && serial.read()); // empty buffer again

  // start message
  serial.println("\nmpu6050 calibration sketch");
  delay(2000);
  serial.println("\nyour mpu6050 should placed in horizontal position, package letters facing up. \ndon't touch until see finish message.\n");
  delay(3000);
  // verify connection
  serial.println(accelgyro.testconnection() ? "mpu6050 connection successful" : "mpu6050 connection failed");
  delay(1000);
  // reset offsets
  accelgyro.setxacceloffset(0);
  accelgyro.setyacceloffset(0);
  accelgyro.setzacceloffset(0);
  accelgyro.setxgyrooffset(0);
  accelgyro.setygyrooffset(0);
  accelgyro.setzgyrooffset(0);
}

///////////////////////////////////   loop   ////////////////////////////////////
void loop() {
  if (state==0){
    serial.println("\nreading sensors first time...");
    meansensors();
    state++;
    delay(1000);
  }

  if (state==1) {
    serial.println("\ncalculating offsets...");
    calibration();
    state++;
    delay(1000);
  }

  if (state==2) {
    meansensors();
    serial.println("\nfinished!");
    serial.print("\nsensor readings offsets:\t");
    serial.print(mean_ax);
    serial.print("\t");
    serial.print(mean_ay);
    serial.print("\t");
    serial.print(mean_az);
    serial.print("\t");
    serial.print(mean_gx);
    serial.print("\t");
    serial.print(mean_gy);
    serial.print("\t");
    serial.println(mean_gz);
    serial.print("your offsets:\t");
    serial.print(ax_offset);
    serial.print("\t");
    serial.print(ay_offset);
    serial.print("\t");
    serial.print(az_offset);
    serial.print("\t");
    serial.print(gx_offset);
    serial.print("\t");
    serial.print(gy_offset);
    serial.print("\t");
    serial.println(gz_offset);
    serial.println("\ndata printed as: acelx acely acelz girox giroy giroz");
    serial.println("check sensor readings close 0 0 16384 0 0 0");
    serial.println("if calibration succesful write down offsets can set them in projects using similar mpu.setxacceloffset(youroffset)");
    while (1);
  }
}

///////////////////////////////////   functions   ////////////////////////////////////
void meansensors(){
  long i=0,buff_ax=0,buff_ay=0,buff_az=0,buff_gx=0,buff_gy=0,buff_gz=0;

  while (i<(buffersize+101)){
    // read raw accel/gyro measurements device
    accelgyro.getmotion6(&ax, &ay, &az, &gx, &gy, &gz);
   
    if (i>100 && i<=(buffersize+100)){ //first 100 measures discarded
      buff_ax=buff_ax+ax;
      buff_ay=buff_ay+ay;
      buff_az=buff_az+az;
      buff_gx=buff_gx+gx;
      buff_gy=buff_gy+gy;
      buff_gz=buff_gz+gz;
    }
    if (i==(buffersize+100)){
      mean_ax=buff_ax/buffersize;
      mean_ay=buff_ay/buffersize;
      mean_az=buff_az/buffersize;
      mean_gx=buff_gx/buffersize;
      mean_gy=buff_gy/buffersize;
      mean_gz=buff_gz/buffersize;
    }
    i++;
    delay(2); //needed don't repeated measures
  }
}

void calibration(){
  ax_offset=-mean_ax/8;
  ay_offset=-mean_ay/8;
  az_offset=(16384-mean_az)/8;

  gx_offset=-mean_gx/4;
  gy_offset=-mean_gy/4;
  gz_offset=-mean_gz/4;
  while (1){
    int ready=0;
    accelgyro.setxacceloffset(ax_offset);
    accelgyro.setyacceloffset(ay_offset);
    accelgyro.setzacceloffset(az_offset);

    accelgyro.setxgyrooffset(gx_offset);
    accelgyro.setygyrooffset(gy_offset);
    accelgyro.setzgyrooffset(gz_offset);

    meansensors();
    serial.println("...");

    if (abs(mean_ax)<=acel_deadzone) ready++;
    else ax_offset=ax_offset-mean_ax/acel_deadzone;

    if (abs(mean_ay)<=acel_deadzone) ready++;
    else ay_offset=ay_offset-mean_ay/acel_deadzone;

    if (abs(16384-mean_az)<=acel_deadzone) ready++;
    else az_offset=az_offset+(16384-mean_az)/acel_deadzone;

    if (abs(mean_gx)<=giro_deadzone) ready++;
    else gx_offset=gx_offset-mean_gx/(giro_deadzone+1);

    if (abs(mean_gy)<=giro_deadzone) ready++;
    else gy_offset=gy_offset-mean_gy/(giro_deadzone+1);

    if (abs(mean_gz)<=giro_deadzone) ready++;
    else gz_offset=gz_offset-mean_gz/(giro_deadzone+1);

    if (ready==6) break;
  }
}


vu l'heure qu'il est je craque, j'espère que vous pourrez m'apporter un élément de réponse.

merci beaucoup à tous !   :d

bonjour,

il faut que tu rajoutes des serial.println pour savoir où ça bloque.


Arduino Forum > International > Français (Moderators: jfs, Snootlab) > Problème Calibration MPU 6050


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'