Are these Gyroscope readings correct?
hi, trying calibrate mpu-6050 , gy-271 (magnetometer) use in ahrs.
here code used find offsets mpu-6050:
i uploaded code , gave me offsets accelerometer , gyroscope, used in own code here:
here offset gyroscope readings:
do these correct? know offset gyro readings should 0 in instances readings going way +-0.6. normal? or did wrong?
i have attached graph plots of offset gyroscope readings along non-offset gyroscope readings.
here code used find offsets mpu-6050:
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.
// code website: http://wired.chillibasket.com/2015/01/calibrating-mpu6050/
/* ========== ====== ==================================
note: in addition connection 3.3v, gnd, sda, , scl, for
connect pin labelled sda on mpu 6050
to arduino's (a4) analog pin 4 (sda). , pin labelled scl on mpu
6050 arduino's (a5) analog pin 5 (scl).
=========================================================
*/
// 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();
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;
}
}
i uploaded code , gave me offsets accelerometer , gyroscope, used in own code here:
code: [select]
mpu.setxacceloffset(-2333);
mpu.setyacceloffset(371);
mpu.setzacceloffset(5050);
mpu.setxgyrooffset(114);
mpu.setygyrooffset(-30);
mpu.setzgyrooffset(-5);
here offset gyroscope readings:
code: [select]
gyro: x,y,z -0.02, -0.15, -0.24
gyro: x,y,z 0.09, -0.11, -0.37
gyro: x,y,z -0.01, -0.02, -0.21
gyro: x,y,z 0.02, 0.02, -0.14
gyro: x,y,z 0.18, 0.08, -0.18
gyro: x,y,z 0.06, -0.08, -0.44
gyro: x,y,z 0.17, 0.02, -0.28
gyro: x,y,z 0.07, -0.05, -0.25
gyro: x,y,z -0.16, 0.11, -0.31
gyro: x,y,z 0.00, 0.08, -0.41
gyro: x,y,z -0.12, 0.01, -0.29
gyro: x,y,z 0.20, -0.02, -0.43
gyro: x,y,z 0.28, 0.07, -0.25
gyro: x,y,z 0.00, -0.13, -0.37
gyro: x,y,z 0.05, 0.04, -0.29
gyro: x,y,z -0.06, 0.01, -0.58
gyro: x,y,z -0.09, -0.08, -0.40
gyro: x,y,z -0.15, -0.18, -0.30
gyro: x,y,z -0.04, -0.01, -0.28
gyro: x,y,z -0.10, -0.15, -0.42
gyro: x,y,z -0.02, -0.02, -0.41
gyro: x,y,z -0.02, 0.15, -0.44
gyro: x,y,z 0.05, 0.18, -0.25
gyro: x,y,z -0.07, -0.04, -0.23
gyro: x,y,z -0.09, -0.10, -0.33
gyro: x,y,z 0.01, -0.06, -0.42
gyro: x,y,z -0.10, 0.08, -0.43
gyro: x,y,z 0.01, -0.14, -0.43
gyro: x,y,z 0.06, 0.00, -0.34
gyro: x,y,z 0.08, -0.16, -0.51
gyro: x,y,z 0.01, 0.05, -0.62
gyro: x,y,z 0.01, -0.06, -0.49
gyro: x,y,z -0.02, 0.15, -0.41
do these correct? know offset gyro readings should 0 in instances readings going way +-0.6. normal? or did wrong?
i have attached graph plots of offset gyroscope readings along non-offset gyroscope readings.
well looks z miscalibrated - units?
what rms noise spec in units? variability higher expect
from noise specs?
[ why not calculate mean , standard deviation , print out ]
what rms noise spec in units? variability higher expect
from noise specs?
[ why not calculate mean , standard deviation , print out ]
Arduino Forum > Using Arduino > Sensors > Are these Gyroscope readings correct?
arduino
Comments
Post a Comment