Rev 2032 | Rev 2035 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2032 | Rev 2033 | ||
---|---|---|---|
Line 95... | Line 95... | ||
95 | int16_t gyro_PID[2]; |
95 | int16_t gyro_PID[2]; |
96 | int16_t gyro_ATT[2]; |
96 | int16_t gyro_ATT[2]; |
97 | int16_t gyroD[2]; |
97 | int16_t gyroD[2]; |
98 | int16_t yawGyro; |
98 | int16_t yawGyro; |
Line -... | Line 99... | ||
- | 99 | ||
- | 100 | int32_t groundPressure; |
|
99 | 101 | ||
100 | /* |
102 | /* |
101 | * Offset values. These are the raw gyro and acc. meter sums when the copter is |
103 | * Offset values. These are the raw gyro and acc. meter sums when the copter is |
102 | * standing still. They are used for adjusting the gyro and acc. meter values |
104 | * standing still. They are used for adjusting the gyro and acc. meter values |
103 | * to be centered on zero. |
105 | * to be centered on zero. |
Line 170... | Line 172... | ||
170 | // Value of 2 samples, with range. |
172 | // Value of 2 samples, with range. |
171 | uint16_t simpleAirPressure; |
173 | uint16_t simpleAirPressure; |
Line 172... | Line 174... | ||
172 | 174 | ||
173 | // Value of AIRPRESSURE_OVERSAMPLING samples, with range, filtered. |
175 | // Value of AIRPRESSURE_OVERSAMPLING samples, with range, filtered. |
- | 176 | int32_t filteredAirPressure; |
|
Line 174... | Line 177... | ||
174 | int32_t filteredAirPressure; |
177 | int32_t lastFilteredAirPressure; |
175 | 178 | ||
176 | #define MAX_AIRPRESSURE_WINDOW_LENGTH 64 |
179 | #define MAX_AIRPRESSURE_WINDOW_LENGTH 64 |
177 | int16_t airPressureWindow[MAX_AIRPRESSURE_WINDOW_LENGTH]; |
180 | int16_t airPressureWindow[MAX_AIRPRESSURE_WINDOW_LENGTH]; |
Line 504... | Line 507... | ||
504 | } |
507 | } |
Line 505... | Line 508... | ||
505 | 508 | ||
506 | // 2 samples were added. |
509 | // 2 samples were added. |
507 | pressureMeasurementCount += 2; |
510 | pressureMeasurementCount += 2; |
- | 511 | if (pressureMeasurementCount >= AIRPRESSURE_OVERSAMPLING) { |
|
508 | if (pressureMeasurementCount >= AIRPRESSURE_OVERSAMPLING) { |
512 | lastFilteredAirPressure = filteredAirPressure; |
509 | filteredAirPressure = (filteredAirPressure * (AIRPRESSURE_FILTER - 1) |
513 | filteredAirPressure = (filteredAirPressure * (AIRPRESSURE_FILTER - 1) |
510 | + airPressureSum + AIRPRESSURE_FILTER / 2) / AIRPRESSURE_FILTER; |
514 | + airPressureSum + AIRPRESSURE_FILTER / 2) / AIRPRESSURE_FILTER; |
511 | pressureMeasurementCount = airPressureSum = 0; |
515 | pressureMeasurementCount = airPressureSum = 0; |
512 | } |
516 | } |
Line 522... | Line 526... | ||
522 | 526 | ||
523 | void analog_updateBatteryVoltage(void) { |
527 | void analog_updateBatteryVoltage(void) { |
524 | // Battery. The measured value is: (V * 1k/11k)/3v * 1024 = 31.03 counts per volt (max. measurable is 33v). |
528 | // Battery. The measured value is: (V * 1k/11k)/3v * 1024 = 31.03 counts per volt (max. measurable is 33v). |
525 | // This is divided by 3 --> 10.34 counts per volt. |
529 | // This is divided by 3 --> 10.34 counts per volt. |
526 | UBat = (3 * UBat + sensorInputs[AD_UBAT] / 3) / 4; |
- | |
527 | debugOut.analog[11] = UBat; |
530 | UBat = (3 * UBat + sensorInputs[AD_UBAT] / 3) / 4; |
Line 528... | Line 531... | ||
528 | } |
531 | } |
529 | 532 | ||
530 | void analog_update(void) { |
533 | void analog_update(void) { |
Line 631... | Line 634... | ||
631 | } |
634 | } |
Line 632... | Line 635... | ||
632 | 635 | ||
633 | accOffset_writeToEEProm(); |
636 | accOffset_writeToEEProm(); |
634 | startAnalogConversionCycle(); |
637 | startAnalogConversionCycle(); |
- | 638 | } |
|
- | 639 | ||
- | 640 | void analog_setGround() { |
|
- | 641 | groundPressure = filteredAirPressure; |
|
- | 642 | } |
|
- | 643 | ||
- | 644 | int32_t analog_getHeight(void) { |
|
- | 645 | return groundPressure - filteredAirPressure; |
|
- | 646 | } |
|
- | 647 | ||
- | 648 | int16_t analog_getDHeight(void) { |
|
- | 649 | // dHeight = -dPressure, so here it is the old pressure minus the current, not opposite. |
|
- | 650 | return lastFilteredAirPressure - filteredAirPressure; |