Subversion Repositories FlightCtrl

Rev

Rev 1880 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1880 Rev 1897
Line 55... Line 55...
55
 
55
 
56
#include "main.h"
56
#include "main.h"
57
#include "mymath.h"
57
#include "mymath.h"
Line -... Line 58...
-
 
58
#include "isqrt.h"
-
 
59
 
-
 
60
 
-
 
61
//MartinW; added vars
-
 
62
unsigned char loop1, loop2, loop3;
-
 
63
unsigned char settingdest = 5;
-
 
64
int keynumber=-7;
-
 
65
 
-
 
66
unsigned short CurrentOffset = 0;///
-
 
67
 
-
 
68
unsigned char pos1, pos2, pos3, pos4=0;
-
 
69
unsigned char Motors0,Motors1,Motors2,Motors3,Motors4,Motors5,Motors6,Motors7;
-
 
70
unsigned char Motors0max,Motors1max,Motors2max,Motors3max,Motors4max,Motors5max,Motors6max,Motors7max;
-
 
71
unsigned short MotorsTmax;
-
 
72
unsigned char updatemotors=5;
-
 
73
 
-
 
74
//Panorama Trigger;
-
 
75
int degreeold =0;
-
 
76
int degreedivold =0;
-
 
77
int degreediv =0;
-
 
78
unsigned int panograd=0;
-
 
79
unsigned char panotrigger=0;   
-
 
80
 unsigned char calibration_done = 0;
-
 
81
///MartinW; added vars END
-
 
82
 
58
#include "isqrt.h"
83
 
59
 
84
 
60
unsigned char h,m,s;
85
unsigned char h,m,s;
61
unsigned int BaroExpandActive = 0;
86
unsigned int BaroExpandActive = 0;
62
int MesswertNick,MesswertRoll,MesswertGier,MesswertGierBias, RohMesswertNick,RohMesswertRoll;
87
int MesswertNick,MesswertRoll,MesswertGier,MesswertGierBias, RohMesswertNick,RohMesswertRoll;
Line 71... Line 96...
71
long IntegralRoll = 0,IntegralRoll2 = 0;
96
long IntegralRoll = 0,IntegralRoll2 = 0;
72
long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
97
long IntegralAccNick = 0,IntegralAccRoll = 0,IntegralAccZ = 0;
73
long Integral_Gier = 0;
98
long Integral_Gier = 0;
74
long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
99
long Mess_IntegralNick = 0,Mess_IntegralNick2 = 0;
75
long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
100
long Mess_IntegralRoll = 0,Mess_IntegralRoll2 = 0;
76
long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0;
101
//long Mess_Integral_Gier = 0,Mess_Integral_Gier2 = 0; ///MartinW so war es
-
 
102
long Mess_Integral_Gier = 0; ///MartinW: Mess_Integral_Gier2 unbenutzt
-
 
103
 
77
long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
104
long MittelIntegralNick,MittelIntegralRoll,MittelIntegralNick2,MittelIntegralRoll2;
78
long SummeNick=0,SummeRoll=0;
105
long SummeNick=0,SummeRoll=0;
79
volatile long Mess_Integral_Hoch = 0;
106
volatile long Mess_Integral_Hoch = 0;
80
int  KompassValue = -1;
107
int  KompassValue = -1;
81
int  KompassSollWert = 0;
108
int  KompassSollWert = 0;
Line 190... Line 217...
190
    DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR;
217
    DebugOut.Analog[11] = ErsatzKompass / GIER_GRAD_FAKTOR;
191
    DebugOut.Analog[12] = Motor[0].SetPoint;
218
    DebugOut.Analog[12] = Motor[0].SetPoint;
192
    DebugOut.Analog[13] = Motor[1].SetPoint;
219
    DebugOut.Analog[13] = Motor[1].SetPoint;
193
    DebugOut.Analog[14] = Motor[2].SetPoint;
220
    DebugOut.Analog[14] = Motor[2].SetPoint;
194
    DebugOut.Analog[15] = Motor[3].SetPoint;
221
    DebugOut.Analog[15] = Motor[3].SetPoint;
-
 
222
       
-
 
223
///MartinW added Debug ouputs
-
 
224
        DebugOut.Analog[16] = Motor[4].SetPoint;
-
 
225
    DebugOut.Analog[17] = Motor[5].SetPoint;
-
 
226
       
-
 
227
        DebugOut.Analog[18] = FromNC_AltitudeSpeed;     ///
-
 
228
 
-
 
229
        //DebugOut.Analog[18] = Motor[6].SetPoint;      // v0.84a
-
 
230
        //DebugOut.Analog[24] = Motor[6].SetPoint;      // on v0.84a = SollHoehe/5
-
 
231
    DebugOut.Analog[25] = Motor[6].SetPoint;
-
 
232
        DebugOut.Analog[26] = Motor[7].SetPoint;    
-
 
233
        //DebugOut.Analog[27] = Motor[9].SetPoint;      // on v0.84a = KompassSollWert
-
 
234
///MartinW added Debug ouputs END
-
 
235
 
195
    DebugOut.Analog[20] = ServoNickValue;
236
    DebugOut.Analog[20] = ServoNickValue;
196
    DebugOut.Analog[22] = Capacity.ActualCurrent;
237
    DebugOut.Analog[22] = Capacity.ActualCurrent;
197
    DebugOut.Analog[23] = Capacity.UsedCapacity;
238
    DebugOut.Analog[23] = Capacity.UsedCapacity;
198
        DebugOut.Analog[24] = SollHoehe/5;     
239
        DebugOut.Analog[24] = SollHoehe/5;     
199
//    DebugOut.Analog[22] = FromNaviCtrl_Value.GpsZ;
240
//    DebugOut.Analog[22] = FromNaviCtrl_Value.GpsZ;
200
//    DebugOut.Analog[29] = FromNaviCtrl_Value.SerialDataOkay;
241
//    DebugOut.Analog[29] = FromNaviCtrl_Value.SerialDataOkay;
201
    DebugOut.Analog[27] = KompassSollWert;
242
    DebugOut.Analog[27] = KompassSollWert;
202
        DebugOut.Analog[29] = Capacity.MinOfMaxPWM;
243
        DebugOut.Analog[29] = Capacity.MinOfMaxPWM;
203
    DebugOut.Analog[30] = GPS_Nick;
244
    DebugOut.Analog[30] = GPS_Nick;
204
    DebugOut.Analog[31] = GPS_Roll;
245
    DebugOut.Analog[31] = GPS_Roll;
-
 
246
       
-
 
247
       
205
    if(VersionInfo.HardwareError[0] || VersionInfo.HardwareError[1]) DebugOut.Status[1] |= 1; else DebugOut.Status[1] &= 0xfe;
248
    if(VersionInfo.HardwareError[0] || VersionInfo.HardwareError[1]) DebugOut.Status[1] |= 1; else DebugOut.Status[1] &= 0xfe;
206
}
249
}
Line 656... Line 699...
656
     static long IntegralFehlerNick = 0;
699
     static long IntegralFehlerNick = 0;
657
     static long IntegralFehlerRoll = 0;
700
     static long IntegralFehlerRoll = 0;
658
         static unsigned int RcLostTimer;
701
         static unsigned int RcLostTimer;
659
         static unsigned char delay_neutral = 0;
702
         static unsigned char delay_neutral = 0;
660
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
703
         static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
661
         static unsigned char calibration_done = 0;
704
         //static unsigned char calibration_done = 0;// moved up
662
     static char NeueKompassRichtungMerken = 0;
705
     static char NeueKompassRichtungMerken = 0;
663
     static long ausgleichNick, ausgleichRoll;
706
     static long ausgleichNick, ausgleichRoll;
664
     int IntegralNickMalFaktor,IntegralRollMalFaktor;
707
     int IntegralNickMalFaktor,IntegralRollMalFaktor;
665
         unsigned char i;
708
         unsigned char i;
666
        Mittelwert();
709
        Mittelwert();
Line 756... Line 799...
756
                           SetNeutral(0);
799
                           SetNeutral(0);
757
                           calibration_done = 1;
800
                           calibration_done = 1;
758
                                                   ServoActive = 1;
801
                                                   ServoActive = 1;
759
                                                   DDRD  |=0x80; // enable J7 -> Servo signal
802
                                                   DDRD  |=0x80; // enable J7 -> Servo signal
760
                           Piep(GetActiveParamSet(),120);
803
                           Piep(GetActiveParamSet(),120);
-
 
804
#ifdef WITH_JETI_BEEP           ///  MartinW main.h 
-
 
805
#warning : "### with JetiBeep Delay ###"
-
 
806
                                                        JetiBeep = 101;///
-
 
807
                                                        delayjetibeepset = (GetActiveParamSet()*10);
-
 
808
#else
-
 
809
#warning : "### without JetiBeep Delay ###"     
-
 
810
#endif
761
                         }
811
                         }
762
                        }
812
                        }
763
                    }
813
                    }
764
                 else
814
                 else
765
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)  // ACC Neutralwerte speichern
815
                if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)  // ACC Neutralwerte speichern
Line 798... Line 848...
798
                                                                {
848
                                                                {
799
                                                                        modell_fliegt = 1;
849
                                                                        modell_fliegt = 1;
800
                                                                        MotorenEin = 1;
850
                                                                        MotorenEin = 1;
801
                                                                        sollGier = 0;
851
                                                                        sollGier = 0;
802
                                                                        Mess_Integral_Gier = 0;
852
                                                                        Mess_Integral_Gier = 0;
803
                                                                        Mess_Integral_Gier2 = 0;
853
                                                                        //Mess_Integral_Gier2 = 0; //MartinR: Mess_Integral_Gier2 unbenutzt
804
                                                                        Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
854
                                                                        Mess_IntegralNick = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccNick;
805
                                                                        Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
855
                                                                        Mess_IntegralRoll = EE_Parameter.GyroAccFaktor * (long)Mittelwert_AccRoll;
806
                                                                        Mess_IntegralNick2 = IntegralNick;
856
                                                                        Mess_IntegralNick2 = IntegralNick;
807
                                                                        Mess_IntegralRoll2 = IntegralRoll;
857
                                                                        Mess_IntegralRoll2 = IntegralRoll;
808
                                                                        SummeNick = 0;
858
                                                                        SummeNick = 0;
Line 883... Line 933...
883
    IntegralFaktorGier = Parameter_Gyro_Gier_I;
933
    IntegralFaktorGier = Parameter_Gyro_Gier_I;
Line 884... Line 934...
884
 
934
 
885
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
935
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
886
//+ Analoge Steuerung per Seriell
936
//+ Analoge Steuerung per Seriell
-
 
937
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
938
#ifdef WITH_ExternControl               /// MartinW memorysaving
-
 
939
#warning : "### with ExternControl ###"
887
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
940
 
888
   if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128)
941
   if(ExternControl.Config & 0x01 && Parameter_ExternalControl > 128)
889
    {
942
    {
890
         StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P;
943
         StickNick += (int) ExternControl.Nick * (int) EE_Parameter.Stick_P;
891
         StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P;
944
         StickRoll += (int) ExternControl.Roll * (int) EE_Parameter.Stick_P;
Line 908... Line 961...
908
      MaxStickRoll = abs(StickRoll)/STICK_GAIN;
961
      MaxStickRoll = abs(StickRoll)/STICK_GAIN;
909
      if(MaxStickRoll > 100) MaxStickRoll = 100;
962
      if(MaxStickRoll > 100) MaxStickRoll = 100;
910
     }
963
     }
911
     else MaxStickRoll--;
964
     else MaxStickRoll--;
912
    if(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING)  {MaxStickNick = 0; MaxStickRoll = 0;}
965
    if(FC_StatusFlags & FC_STATUS_EMERGENCY_LANDING)  {MaxStickNick = 0; MaxStickRoll = 0;}
-
 
966
       
-
 
967
        #else
-
 
968
#warning : "### without ExternControl ###"      
-
 
969
#endif
Line 913... Line 970...
913
 
970
 
914
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
971
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
915
// Looping?
972
// Looping?
916
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
973
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Line 1770... Line 1827...
1770
                        else tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L;
1827
                        else tmp_int += ((long)pd_ergebnis_roll * Mixer.Motor[i][2]) / 64L;
1771
            // Gier
1828
            // Gier
1772
                        if(Mixer.Motor[i][3] == 64) tmp_int += GierMischanteil;
1829
                        if(Mixer.Motor[i][3] == 64) tmp_int += GierMischanteil;
1773
                        else if(Mixer.Motor[i][3] == -64) tmp_int -= GierMischanteil;
1830
                        else if(Mixer.Motor[i][3] == -64) tmp_int -= GierMischanteil;
1774
                        else tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L;
1831
                        else tmp_int += ((long)GierMischanteil * Mixer.Motor[i][3]) / 64L;
-
 
1832
                       
1775
 
1833
                       
-
 
1834
#ifdef WITH_ORIGINAL_MOTORSMOOTHING     ///  MartinW main.h means no memsave
-
 
1835
#warning : "### with  WITH_ORIGINAL_MOTORSMOOTHING ###"
1776
                        if(tmp_int > tmp_motorwert[i]) tmp_int = (tmp_motorwert[i] + tmp_int) / 2;      // MotorSmoothing
1836
                if(tmp_int > tmp_motorwert[i]) tmp_int = (tmp_motorwert[i] + tmp_int) / 2;      // MotorSmoothing
1777
                        else tmp_int = 2 * tmp_int - tmp_motorwert[i];                                                              // MotorSmoothing
1837
                else tmp_int = 2 * tmp_int - tmp_motorwert[i];                                                              // MotorSmoothing
-
 
1838
#else
-
 
1839
#warning : "### without  WITH_ORIGINAL_MOTORSMOOTHING, ajustable ###"   
-
 
1840
// MartinW; variable MS START
-
 
1841
if(tmp_int > tmp_motorwert[i]) tmp_int = (tmp_motorwert[i] + tmp_int) / 2;      // MotorSmoothing
-
 
1842
//                      else tmp_int = 2 * tmp_int - tmp_motorwert[i];                                          // MotorSmoothing
-
 
1843
// Arthur P: the original code allowed the motor value to drop to 0 or negative values
-
 
1844
// straight off, i.e. could amplify an intended decrease excessively while upregulation
-
 
1845
// is dampened. The modification would still allow immediate drop below intended value 
-
 
1846
// but would dampen this. This would still allow for airbraking of the prop to have effect
-
 
1847
// but it might lead to less sudden excessive drops in rpm with only gradual recovery.
-
 
1848
// 090807 Arthur P: Due to problems with uart.c which still refers to user parameter 1 and 2 and 
-
 
1849
// possible timing issues with the shutter interval load, removed the shutter interval functions
-
 
1850
// and switched to use of userparam6 for the motor smoothing.
-
 
1851
// 091114 Inserted modification into 0.76g source code.
-
 
1852
// 20100804 Modified v.0.80d code where motorsmoothing is no longer a separate function.
-
 
1853
// Downsmoothing either uses default v.0.7x+ 150% downstep (user para 7 == 0),
-
 
1854
// 50% downstep (user para 7 == 1 or 2), or downsteps of x% (userpara7 ==):
-
 
1855
// 66.6% (3), 75% (4), 80% (5), 90% (10), 95% (20), 97.5% (40), 98% (50), 99% (100).
-
 
1856
                        else
-
 
1857
                        {
-
 
1858
                                if(Parameter_UserParam7 < 2)
-
 
1859
                                { // Original function
-
 
1860
                                        tmp_int = 2 * tmp_int - tmp_motorwert[i];
-
 
1861
                                }
-
 
1862
                                else
-
 
1863
                                {
-
 
1864
                                        // If userpara7 >= 2 then allow >= 50% of the intended step down to rapidly reach the intended value.
-
 
1865
                                        tmp_int = tmp_int + ((tmp_motorwert[i] - tmp_int)/Parameter_UserParam7);
-
 
1866
                                }
-
 
1867
                        }
-
 
1868
                       
-
 
1869
// MartinW; variable MS END
-
 
1870
#endif
-
 
1871
                       
1778
 
1872
                       
1779
                        LIMIT_MIN_MAX(tmp_int,(int) MIN_GAS * 4,(int) MAX_GAS * 4);
1873
                        LIMIT_MIN_MAX(tmp_int,(int) MIN_GAS * 4,(int) MAX_GAS * 4);
1780
                        Motor[i].SetPoint = tmp_int / 4;
1874
                        Motor[i].SetPoint = tmp_int / 4;
1781
                        Motor[i].SetPointLowerBits = (tmp_int % 4)<<1; // (3 bits total)
1875
                        Motor[i].SetPointLowerBits = (tmp_int % 4)<<1; // (3 bits total)
1782
            tmp_motorwert[i] = tmp_int;
1876
            tmp_motorwert[i] = tmp_int;
1783
                }
1877
                }