Rev 1967 | Rev 1970 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1967 | Rev 1969 | ||
---|---|---|---|
Line 71... | Line 71... | ||
71 | #include "output.h" |
71 | #include "output.h" |
Line 72... | Line 72... | ||
72 | 72 | ||
73 | // set ADC enable & ADC Start Conversion & ADC Interrupt Enable bit |
73 | // set ADC enable & ADC Start Conversion & ADC Interrupt Enable bit |
Line -... | Line 74... | ||
- | 74 | #define startADC() (ADCSRA |= (1<<ADEN)|(1<<ADSC)|(1<<ADIE)) |
|
- | 75 | ||
74 | #define startADC() (ADCSRA |= (1<<ADEN)|(1<<ADSC)|(1<<ADIE)) |
76 | const char* recal = ", recalibration needed."; |
75 | 77 | ||
76 | /* |
78 | /* |
77 | * For each A/D conversion cycle, each analog channel is sampled a number of times |
79 | * For each A/D conversion cycle, each analog channel is sampled a number of times |
78 | * (see array channelsForStates), and the results for each channel are summed. |
80 | * (see array channelsForStates), and the results for each channel are summed. |
Line 101... | Line 103... | ||
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. |
104 | */ |
106 | */ |
Line 105... | Line 107... | ||
105 | 107 | ||
106 | volatile sensorOffset_t gyroOffset; |
108 | sensorOffset_t gyroOffset; |
107 | volatile sensorOffset_t accOffset; |
109 | sensorOffset_t accOffset; |
Line 108... | Line 110... | ||
108 | volatile sensorOffset_t gyroAmplifierOffset; |
110 | sensorOffset_t gyroAmplifierOffset; |
109 | 111 | ||
110 | /* |
112 | /* |
111 | * This allows some experimentation with the gyro filters. |
113 | * This allows some experimentation with the gyro filters. |
Line 340... | Line 342... | ||
340 | rawGyroSum[YAW] = sensorInputs[AD_GYRO_YAW]; |
342 | rawGyroSum[YAW] = sensorInputs[AD_GYRO_YAW]; |
341 | if (GYRO_REVERSED[YAW]) |
343 | if (GYRO_REVERSED[YAW]) |
342 | yawGyro = gyroOffset.offsets[YAW] - sensorInputs[AD_GYRO_YAW]; |
344 | yawGyro = gyroOffset.offsets[YAW] - sensorInputs[AD_GYRO_YAW]; |
343 | else |
345 | else |
344 | yawGyro = sensorInputs[AD_GYRO_YAW] - gyroOffset.offsets[YAW]; |
346 | yawGyro = sensorInputs[AD_GYRO_YAW] - gyroOffset.offsets[YAW]; |
345 | - | ||
346 | debugOut.analog[3] = rawGyroSum[0]; |
- | |
347 | debugOut.analog[4] = rawGyroSum[1]; |
- | |
348 | debugOut.analog[5] = rawGyroSum[2]; |
- | |
349 | } |
347 | } |
Line 350... | Line 348... | ||
350 | 348 | ||
351 | void analog_updateAccelerometers(void) { |
349 | void analog_updateAccelerometers(void) { |
352 | // Pitch and roll axis accelerations. |
350 | // Pitch and roll axis accelerations. |
Line 471... | Line 469... | ||
471 | analog_updateBatteryVoltage(); |
469 | analog_updateBatteryVoltage(); |
472 | } |
470 | } |
Line 473... | Line 471... | ||
473 | 471 | ||
474 | void analog_setNeutral() { |
472 | void analog_setNeutral() { |
475 | if (gyroAmplifierOffset_readFromEEProm()) { |
473 | if (gyroAmplifierOffset_readFromEEProm()) { |
476 | printf("gyro amp invalid, you must recalibrate."); |
474 | printf("gyro amp invalid%s",recal); |
477 | gyro_loadOffsets(1); |
475 | gyro_loadOffsets(1); |
- | 476 | } else |
|
Line 478... | Line 477... | ||
478 | } |
477 | gyro_loadOffsets(0); |
479 | 478 | ||
480 | if (gyroOffset_readFromEEProm()) { |
479 | if (gyroOffset_readFromEEProm()) { |
481 | printf("gyro offsets invalid, you must recalibrate."); |
480 | printf("gyro offsets invalid%s",recal); |
482 | gyroOffset.offsets[PITCH] = gyroOffset.offsets[ROLL] = 512 * GYRO_SUMMATION_FACTOR_PITCHROLL; |
481 | gyroOffset.offsets[PITCH] = gyroOffset.offsets[ROLL] = 512 * GYRO_SUMMATION_FACTOR_PITCHROLL; |
Line 483... | Line 482... | ||
483 | gyroOffset.offsets[YAW] = 512 * GYRO_SUMMATION_FACTOR_YAW; |
482 | gyroOffset.offsets[YAW] = 512 * GYRO_SUMMATION_FACTOR_YAW; |
484 | } |
483 | } |
Line 485... | Line 484... | ||
485 | 484 | ||
486 | debugOut.analog[6] = gyroOffset.offsets[PITCH]; |
485 | debugOut.analog[6] = gyroOffset.offsets[PITCH]; |
487 | debugOut.analog[7] = gyroOffset.offsets[ROLL]; |
486 | debugOut.analog[7] = gyroOffset.offsets[ROLL]; |
488 | 487 | ||
489 | if (accOffset_readFromEEProm()) { |
488 | if (accOffset_readFromEEProm()) { |
Line 490... | Line 489... | ||
490 | printf("acc. meter offsets invalid, you must recalibrate."); |
489 | printf("acc. meter offsets invalid%s",recal); |