mageshms / arducopter

Automatically exported from code.google.com/p/arducopter
0 stars 0 forks source link

Restart gyro calibration during startup while gyros and accels not stable #94

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I've posted this on the ArduPirates thread. On Chris' suggestion I've added the 
request here.

The code below restarts the calibration each time the gyros or accels change 
significantly. This gives the user more time to put down the quad after 
connecting the battery, and avoids taking off with miscalibrated gyros. As a 
bonus, the leds will cycle quickly while the calibration is restarting, and 
slowly if the calibration is continuing normally. You may want to tweak the 
threshold.

Sample code for Sensors.pde; the mods are #ifdef'ed for identification.

#define WAIT_STABLE_CALIBRATION 5
void calibrateSensors(void) {
...
#ifdef WAIT_STABLE_CALIBRATION  
  float aux_float[6];
#else  
  float aux_float[3];
#endif
...
  aux_float[0] = gyro_offset_roll;
  aux_float[1] = gyro_offset_pitch;
  aux_float[2] = gyro_offset_yaw;
#ifdef WAIT_STABLE_CALIBRATION  
  aux_float[3] = acc_offset_x;
  aux_float[4] = acc_offset_y;
  aux_float[5] = acc_offset_z;
#endif

  // Take the gyro offset values
  for(i=0;i<600;i++)
  {
    Read_adc_raw();   // Read sensors
#ifdef WAIT_STABLE_CALIBRATION  
    // restart calibration while gyros or accels unstable
    for(gyro = GYROZ; gyro <= ACCELZ; gyro++)   
    {
      float delta = AN[gyro] - aux_float[gyro];
      if (delta < -WAIT_STABLE_CALIBRATION || delta > WAIT_STABLE_CALIBRATION)
        i = 0; // restart
      aux_float[gyro] += delta * 0.2;
    }
#else  
    for(gyro = GYROZ; gyro <= GYROY; gyro++)   
      aux_float[gyro] = aux_float[gyro] * 0.8 + AN[gyro] * 0.2;     // Filtering  
#endif
...
}

Original issue reported on code.google.com by patrick....@gmail.com on 19 Dec 2010 at 10:47

GoogleCodeExporter commented 8 years ago

Original comment by jphelirc on 21 Dec 2010 at 3:27

GoogleCodeExporter commented 8 years ago
Is it always necessary to run the configurator and check the PID values after 
changing batteries??? I thought that would get saved somewhere so haven't been 
checking it between battery changes.

Original comment by stevetor...@gmail.com on 5 Jan 2011 at 2:19

GoogleCodeExporter commented 8 years ago
No, all PID and other settings are saves on permanent memory after you hit 
UPDATE on Configurator. 

Only time when you _might_ need to check PID values if you change from 200gram 
battery to 600gram or bigger...

Original comment by jani.hir...@gmail.com on 5 Jan 2011 at 2:34

GoogleCodeExporter commented 8 years ago
OK I do change from 3S 5000mAh to 3000mAh so maybe that was the issue.

Original comment by stevetor...@gmail.com on 6 Jan 2011 at 10:06

GoogleCodeExporter commented 8 years ago

Original comment by jasonshort on 8 May 2011 at 7:25