Subversion Repositories FlightCtrl

Rev

Rev 2129 | Rev 2133 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2129 Rev 2132
Line 39... Line 39...
39
uint8_t gyroDWindowIdx = 0;
39
uint8_t gyroDWindowIdx = 0;
Line 40... Line 40...
40
 
40
 
41
/*
41
/*
42
 * Airspeed
42
 * Airspeed
43
 */
43
 */
44
int16_t airpressure;
44
//int16_t airpressure;
45
uint16_t airspeedVelocity = 0;
45
//uint16_t airspeedVelocity = 0;
46
//int16_t airpressureWindow[AIRPRESSURE_WINDOW_LENGTH];
46
//int16_t airpressureWindow[AIRPRESSURE_WINDOW_LENGTH];
Line 47... Line 47...
47
//uint8_t airpressureWindowIdx = 0;
47
//uint8_t airpressureWindowIdx = 0;
48
 
48
 
Line 129... Line 129...
129
volatile uint8_t adState;
129
volatile uint8_t adState;
130
volatile uint8_t adChannel;
130
volatile uint8_t adChannel;
Line 131... Line 131...
131
 
131
 
132
// ADC channels
132
// ADC channels
133
#define AD_UBAT           6
133
#define AD_UBAT           6
Line 134... Line 134...
134
#define AD_AIRPRESSURE    7
134
//#define AD_AIRPRESSURE    7
135
 
135
 
136
/*
136
/*
137
 * Table of AD converter inputs for each state.
137
 * Table of AD converter inputs for each state.
Line 144... Line 144...
144
 * The acc. sensor is sampled even if not used - or installed
144
 * The acc. sensor is sampled even if not used - or installed
145
 * at all. The cost is not significant.
145
 * at all. The cost is not significant.
146
 */
146
 */
Line 147... Line 147...
147
 
147
 
148
const uint8_t channelsForStates[] PROGMEM = {
148
const uint8_t channelsForStates[] PROGMEM = {
149
  AD_AIRPRESSURE,
149
  //AD_AIRPRESSURE,
150
  AD_UBAT,
150
  AD_UBAT
151
  AD_AIRPRESSURE,
151
  //AD_AIRPRESSURE,
152
  AD_AIRPRESSURE,
152
  //AD_AIRPRESSURE,
153
  AD_AIRPRESSURE,
153
  //AD_AIRPRESSURE,
Line 154... Line 154...
154
};
154
};
155
 
155
 
Line 216... Line 216...
216
  for (uint8_t i = 0; i<8; i++) {
216
  for (uint8_t i = 0; i<8; i++) {
217
    ADSensorInputs[i] = 0;
217
    ADSensorInputs[i] = 0;
218
  }
218
  }
Line 219... Line 219...
219
 
219
 
220
  adState = 0;
220
  adState = 0;
221
  adChannel = AD_AIRPRESSURE;
221
  adChannel = AD_UBAT;
222
  ADMUX = (ADMUX & 0xE0) | adChannel;
222
  ADMUX = (ADMUX & 0xE0) | adChannel;
223
  startADC();
223
  startADC();
224
  sensorDataReady = 0;
224
  sensorDataReady = 0;
Line 298... Line 298...
298
  if (++gyroDWindowIdx >= IMUConfig.gyroDWindowLength) {
298
  if (++gyroDWindowIdx >= IMUConfig.gyroDWindowLength) {
299
      gyroDWindowIdx = 0;
299
      gyroDWindowIdx = 0;
300
  }
300
  }
301
}
301
}
Line -... Line 302...
-
 
302
 
302
 
303
/*
303
// probably wanna aim at 1/10 m/s/unit.
304
// probably wanna aim at 1/10 m/s/unit.
Line 304... Line 305...
304
#define LOG_AIRSPEED_FACTOR 0
305
#define LOG_AIRSPEED_FACTOR 0
305
 
306
 
306
void analog_updateAirspeed(void) {
307
void analog_updateAirspeed(void) {
307
  uint16_t rawAirpressure = ADSensorInputs[AD_AIRPRESSURE];
308
  uint16_t rawAirpressure = ADSensorInputs[AD_AIRPRESSURE];
308
  int16_t temp = rawAirpressure - airpressureOffset;
309
  int16_t temp = airpressureOffset - rawAirPressure;
309
//   airpressure -= airpressureWindow[airpressureWindowIdx];
310
//   airpressure -= airpressureWindow[airpressureWindowIdx];
310
//  airpressure += temp;
311
//  airpressure += temp;
311
//  airpressureWindow[airpressureWindowIdx] = temp;
312
//  airpressureWindow[airpressureWindowIdx] = temp;
Line 324... Line 325...
324
  debugOut.analog[18] = airpressureOffset;
325
  debugOut.analog[18] = airpressureOffset;
325
  debugOut.analog[19] = airspeedVelocity;
326
  debugOut.analog[19] = airspeedVelocity;
Line 326... Line 327...
326
 
327
 
327
  isFlying = 0; //(airspeedVelocity >= staticParams.isFlyingThreshold);
328
  isFlying = 0; //(airspeedVelocity >= staticParams.isFlyingThreshold);
-
 
329
}
Line 328... Line 330...
328
}
330
*/
329
 
331
 
330
void analog_updateBatteryVoltage(void) {
332
void analog_updateBatteryVoltage(void) {
331
  // Battery. The measured value is: (V * 1k/11k)/3v * 1024 = 31.03 counts per volt (max. measurable is 33v).
333
  // Battery. The measured value is: (V * 1k/11k)/3v * 1024 = 31.03 counts per volt (max. measurable is 33v).
332
  // This is divided by 3 --> 10.34 counts per volt.
334
  // This is divided by 3 --> 10.34 counts per volt.
Line 333... Line 335...
333
  UBat = (3 * UBat + ADSensorInputs[AD_UBAT] / 3) / 4;
335
  UBat = (3 * UBat + ADSensorInputs[AD_UBAT] / 3) / 4;
334
}
336
}
335
 
337
 
336
void analog_update(void) {
338
void analog_update(void) {
337
  analog_updateGyros();
339
  analog_updateGyros();
338
  // analog_updateAccelerometers();
340
  // analog_updateAccelerometers();
339
  analog_updateAirspeed();
341
  // analog_updateAirspeed();
340
  analog_updateBatteryVoltage();
342
  analog_updateBatteryVoltage();
341
#ifdef USE_MK3MAG
343
#ifdef USE_MK3MAG
Line 377... Line 379...
377
  for (i = 0; i < OFFSET_CYCLES; i++) {
379
  for (i = 0; i < OFFSET_CYCLES; i++) {
378
    delay_ms_with_adc_measurement(10, 1);
380
    delay_ms_with_adc_measurement(10, 1);
379
    for (axis = PITCH; axis <= YAW; axis++) {
381
    for (axis = PITCH; axis <= YAW; axis++) {
380
      offsets[axis] += rawGyroValue(axis);
382
      offsets[axis] += rawGyroValue(axis);
381
    }
383
    }
382
    offsets[3] += ADSensorInputs[AD_AIRPRESSURE];
384
    // offsets[3] += ADSensorInputs[AD_AIRPRESSURE];
383
  }
385
  }
Line 384... Line 386...
384
 
386
 
385
  for (axis = PITCH; axis <= YAW; axis++) {
387
  for (axis = PITCH; axis <= YAW; axis++) {
386
    gyroOffset.offsets[axis] = (offsets[axis] + OFFSET_CYCLES / 2) / OFFSET_CYCLES;
388
    gyroOffset.offsets[axis] = (offsets[axis] + OFFSET_CYCLES / 2) / OFFSET_CYCLES;
Line -... Line 389...
-
 
389
  }
387
  }
390
 
388
 
391
  /*
389
  airpressureOffset = (offsets[3] + OFFSET_CYCLES / 2) / OFFSET_CYCLES;
392
  airpressureOffset = (offsets[3] + OFFSET_CYCLES / 2) / OFFSET_CYCLES;
Line 390... Line 393...
390
  int16_t min = 200;
393
  int16_t min = 200;
391
  int16_t max = 1024-200;
394
  int16_t max = 1024-200;
-
 
395
 
Line 392... Line 396...
392
 
396
  if(airpressureOffset < min || airpressureOffset > max)
-
 
397
    versionInfo.hardwareErrors[0] |= FC_ERROR0_PRESSURE;
Line 393... Line 398...
393
  if(airpressureOffset < min || airpressureOffset > max)
398
  */
394
    versionInfo.hardwareErrors[0] |= FC_ERROR0_PRESSURE;
399