Purtroppo nun riesco a capire la calibrazione
Allora i chip sono calibrati in fabrica e all avvio si caricano le informazioni ?
Ma io ho questo dubbio
Il chip lo monto su una scheda , poi su un qualsiasi supporto , poi lo metto in una scatola , vuoi o non vuoi con le tolleranze il chip risulta inclinato in un lato .
Se lo accendo su un tavolo inclinato, lui cosa mi dice … la pendenza del tavolo o mi dice che è in piano ?
In teoria mi dovrebbe sommare tutti i difetti e darmi un valore preciso di come lui è inclinato
Io uso gli offset , non mi chiedo come sono le tolleranze dello strumento , lo metto su un piano vero, e lo calibro li sopra , così lo strumento è informato di come lui è inclinato nel montaggio .
Io lo sto usando in esperimenti per una bolla elettronica, per un piano autolivellante(stato embrionale ) , e ho notato che se non si fanno gli offset non ce niente di reale.
Allego il progetto e la foto del chip nello “strumento)
#include <SPI.h>
#include <Wire.h>
#include <Servo.h>
#include "I2Cdev.h"
#include "MPU6050.h"
#include <EEPROM.h>
//eeprom int ax_offset,ay_offset,az_offset,gx_offset,gy_offset,gz_offset;
// 2 celle per ogni offset inizio 00
int EEax_offset=0;
int EEay_offset=2;
int EEaz_offset=4;
int EEgx_offset=6;
int EEgy_offset=8;
int EEgz_offset=10;
#define MPU 0x68 // I2C address of the MPU-6050
MPU6050 accelgyro(0x68);
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;
//Change this 3 variables if you want to fine tune the skecth to your needs.
int buffersize=1000; //Amount of readings used to average, make it higher to get more precision but sketch will be slower (default:1000)
int acel_deadzone=8; //Acelerometer error allowed, make it lower to get more precision, but sketch may not converge (default:8)
int giro_deadzone=1; //Giro error allowed, make it lower to get more precision, but sketch may not converge (default:1)
#define LED 13 // LED collegato al pin digitale 13
#define LEDoffet 7
#define BUTTON 12 // pin di input dove è collegato il pulsante per calcolo offset
#define AvvioOff 11 // pin di input dove è collegato il pulsante per avviare routine di calibrazione
int val = 0;
float Temp ;
Servo ServoX, ServoY;
double AcX,AcY,AcZ;
double Pitch, Roll;
void setup(){
pinMode(AvvioOff, INPUT); // imposta il pin digitale come input
pinMode(LEDoffet, OUTPUT);
Serial.begin(115200);
ServoX.attach(8);
ServoY.attach(9);
init_MPU(); // Inizializzazione MPU6050
//Sensor readings with offsets: -5 -8 16371 1 1 1
//Your offsets: -3841 -2790 1430 -5 17 -43
//Data is printed as: acelX acelY acelZ giroX giroY giroZ
//Check that your sensor readings are close to 0 0 16384 0 0 0
//If calibration was succesful write down your offsets so you can set them in your projects using something similar to mpu.setXAccelOffset(youroffset)
//lettura eeprom offset
//-2781
//1480
//-186
//37
//42
accelgyro.setXAccelOffset(EEPROM.read(EEax_offset)*256+EEPROM.read(EEax_offset+1));
delay(5);
accelgyro.setYAccelOffset(EEPROM.read(EEay_offset)*256+EEPROM.read(EEay_offset+1));
delay(5);
accelgyro.setZAccelOffset(EEPROM.read(EEaz_offset)*256+EEPROM.read(EEaz_offset+1));
delay(5);
accelgyro.setXGyroOffset(EEPROM.read(EEgx_offset)*256+EEPROM.read(EEgx_offset+1));
delay(5);
accelgyro.setYGyroOffset(EEPROM.read(EEgy_offset)*256+EEPROM.read(EEgy_offset+1));
delay(5);
accelgyro.setZGyroOffset(EEPROM.read(EEgz_offset)*256+EEPROM.read(EEgz_offset+1));
delay(5);
}
void loop()
{
if (digitalRead(AvvioOff)){
Serial.println ();
Serial.println ("Iterate through each byte of the EEPROM storage.");
Serial.println (" Larger AVR processors have larger EEPROM sizes, E.g:");
Serial.println ("- Arduno Duemilanove: 512b EEPROM storage.");
Serial.println ("- Arduino Uno: 1kb EEPROM storage.");
Serial.println ("- Arduino Mega: 4kb EEPROM storage.");
Serial.println (" Rather than hard-coding the length, you should use the pre-provided length function.");
Serial.println (" This will make your code portable to all AVR processors.");
Serial.println (" put your setup code here, to run once:");
for (int i = 0 ; i < EEPROM.length() ; i++) {
EEPROM.write(i, 0); /***
Iterate through each byte of the EEPROM storage.
Larger AVR processors have larger EEPROM sizes, E.g:
- Arduno Duemilanove: 512b EEPROM storage.
- Arduino Uno: 1kb EEPROM storage.
- Arduino Mega: 4kb EEPROM storage.
Rather than hard-coding the length, you should use the pre-provided length function.
This will make your code portable to all AVR processors.
***/ // put your setup code here, to run once:
}
digitalWrite(LEDoffet, HIGH);
SetupCalCoffset();
LooPoffset();
}
digitalWrite(LEDoffet, LOW);
delay (1000);
FunctionsMPU(); // Acquisisco assi AcX, AcY, AcZ.
double Roll = FunctionsPitchRoll(AcX, AcY, AcZ); //Calcolo angolo Roll
double Pitch = FunctionsPitchRoll(AcY, AcX, AcZ); //Calcolo angolo Pitch
//controllo servomotori
//double ServoRoll = map(Roll, -90.00, 90.00, 0.00, 179.00);
//double ServoPitch = map(Pitch, -90.00, 90.00, 179.00, 0.00);
//ServoX.write(ServoRoll);
//ServoY.write(ServoPitch);
// Serial.print("Temperatura C: "); Serial.print(Temp/340 + 36.53);
Serial.print("\n");
Serial.print("\n");
Serial.println("_______________________");
Serial.print("Temperatura C: "); Serial.println(Temp/340 + 36.53);
Serial.print("Pitch: "); Serial.print(Pitch-90);
Serial.print("\n");
Serial.print("Pitch: "); Serial.print(Pitch);
Serial.print("");
Serial.print(" ");
for (double i=0; i <= Pitch*10; i++){
Serial.print("<");
}
Serial.print("*");
for (double i=0; i >= Pitch*10; i--){
Serial.print(">");
}
Serial.print("\n");
Serial.print("Roll: "); Serial.print(Roll-90);
Serial.print("\n");
Serial.print("Roll: "); Serial.print(Roll);
Serial.print(" ");
for (double i=0; i <= Roll*10; i++){
Serial.print("<");
}
Serial.print("*");
for (double i=0; i >= Roll*10; i--){
Serial.print(">");
}
}