Subversion Repositories FlightCtrl

Rev

Rev 1872 | Rev 1955 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1872 Rev 1887
Line 500... Line 500...
500
 
500
 
Line 501... Line 501...
501
        gyro_calibrate();
501
        gyro_calibrate();
502
 
502
 
503
        // determine gyro bias by averaging (requires that the copter does not rotate around any axis!)
503
        // determine gyro bias by averaging (requires that the copter does not rotate around any axis!)
504
        for (i = 0; i < GYRO_OFFSET_CYCLES; i++) {
504
        for (i = 0; i < GYRO_OFFSET_CYCLES; i++) {
505
                Delay_ms_Mess(20);
505
                delay_ms_Mess(20);
506
                for (axis = PITCH; axis <= YAW; axis++) {
506
                for (axis = PITCH; axis <= YAW; axis++) {
507
                        deltaOffsets[axis] += rawGyroSum[axis];
507
                        deltaOffsets[axis] += rawGyroSum[axis];
Line 522... Line 522...
522
 
522
 
523
        // Rough estimate. Hmm no nothing happens at calibration anyway.
523
        // Rough estimate. Hmm no nothing happens at calibration anyway.
524
        // airPressureSum = simpleAirPressure * (AIRPRESSURE_SUMMATION_FACTOR/2);
524
        // airPressureSum = simpleAirPressure * (AIRPRESSURE_SUMMATION_FACTOR/2);
Line 525... Line 525...
525
        // pressureMeasurementCount = 0;
525
        // pressureMeasurementCount = 0;
526
 
526
 
Line 527... Line 527...
527
        Delay_ms_Mess(100);
527
        delay_ms_Mess(100);
528
}
528
}
529
 
529
 
Line 540... Line 540...
540
        int32_t deltaOffset[3] = { 0, 0, 0 };
540
        int32_t deltaOffset[3] = { 0, 0, 0 };
541
        int16_t filteredDelta;
541
        int16_t filteredDelta;
542
        // int16_t pressureDiff, savedRawAirPressure;
542
        // int16_t pressureDiff, savedRawAirPressure;
Line 543... Line 543...
543
 
543
 
544
        for (i = 0; i < ACC_OFFSET_CYCLES; i++) {
544
        for (i = 0; i < ACC_OFFSET_CYCLES; i++) {
545
                Delay_ms_Mess(10);
545
                delay_ms_Mess(10);
546
                for (axis = PITCH; axis <= YAW; axis++) {
546
                for (axis = PITCH; axis <= YAW; axis++) {
547
                        deltaOffset[axis] += acc[axis];
547
                        deltaOffset[axis] += acc[axis];
548
                }
548
                }
Line 563... Line 563...
563
        // changing offsets.
563
        // changing offsets.
564
        accNoisePeak[PITCH] = accNoisePeak[ROLL] = 0;
564
        accNoisePeak[PITCH] = accNoisePeak[ROLL] = 0;
Line 565... Line 565...
565
 
565
 
566
        // Setting offset values has an influence in the analog.c ISR
566
        // Setting offset values has an influence in the analog.c ISR
567
        // Therefore run measurement for 100ms to achive stable readings
567
        // Therefore run measurement for 100ms to achive stable readings
Line 568... Line 568...
568
        Delay_ms_Mess(100);
568
        delay_ms_Mess(100);
569
 
569
 
570
        // Set the feedback so that air pressure ends up in the middle of the range.
570
        // Set the feedback so that air pressure ends up in the middle of the range.
571
        // (raw pressure high --> OCR0A also high...)
571
        // (raw pressure high --> OCR0A also high...)
572
        /*
572
        /*
Line 573... Line 573...
573
         OCR0A += ((rawAirPressure - 1024) / rangewidth) - 1;
573
         OCR0A += ((rawAirPressure - 1024) / rangewidth) - 1;
574
         Delay_ms_Mess(1000);
574
         delay_ms_Mess(1000);
Line 575... Line 575...
575
 
575
 
576
         pressureDiff = 0;
576
         pressureDiff = 0;
577
         // DebugOut.Analog[16] = rawAirPressure;
577
         // DebugOut.Analog[16] = rawAirPressure;
578
 
578
 
579
         #define PRESSURE_CAL_CYCLE_COUNT 5
579
         #define PRESSURE_CAL_CYCLE_COUNT 5
580
         for (i=0; i<PRESSURE_CAL_CYCLE_COUNT; i++) {
580
         for (i=0; i<PRESSURE_CAL_CYCLE_COUNT; i++) {
581
         savedRawAirPressure = rawAirPressure;
581
         savedRawAirPressure = rawAirPressure;
582
         OCR0A+=2;
582
         OCR0A+=2;
583
         Delay_ms_Mess(500);
583
         delay_ms_Mess(500);
584
         // raw pressure will decrease.
584
         // raw pressure will decrease.
585
         pressureDiff += (savedRawAirPressure - rawAirPressure);
585
         pressureDiff += (savedRawAirPressure - rawAirPressure);
586
         savedRawAirPressure = rawAirPressure;
586
         savedRawAirPressure = rawAirPressure;
587
         OCR0A-=2;
587
         OCR0A-=2;
Line 588... Line 588...
588
         Delay_ms_Mess(500);
588
         delay_ms_Mess(500);