Subversion Repositories FlightCtrl

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ingob 1
/*#######################################################################################
1561 killagreg 2
Decodieren eines RC Summen Signals
1 ingob 3
#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + www.MikroKopter.com
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2050 holgerb 7
// + Software Nutzungsbedingungen (english version: see below)
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
9
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
10
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
11
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
15
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
16
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
17
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
18
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
19
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
20
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
21
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
22
// + des Mitverschuldens offen.
23
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
24
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
25
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
26
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
27
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
28
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
29
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
30
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// + Software LICENSING TERMS
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
35
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware 
36
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
37
// + The Software may only be used with the Licensor's products.
38
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
39
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
40
// + agreement shall be the property of the Licensor.
41
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
42
// + features that can be used to identify the program may not be altered or defaced by the customer.
43
// + The customer shall be responsible for taking reasonable precautions
44
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
45
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
46
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
47
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
48
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
49
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
50
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
51
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
52
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
53
// + #### END OF LICENSING TERMS ####
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 ingob 56
 
57
#include "rc.h"
58
#include "main.h"
1638 holgerb 59
// Achtung: ACT_S3D_SUMMENSIGNAL wird in der Main.h gesetzt
2341 holgerb 60
#define MAX_RC_IN  16+12+3+4 // 16ch + 12ser + 3stages + 4 reserved
61
volatile int PPM_in[MAX_RC_IN];
62
volatile int PPM_diff[MAX_RC_IN];  // das differnzierte Stick-Signal
1268 hbuss 63
volatile char Channels,tmpChannels = 0;
1 ingob 64
volatile unsigned char NewPpmData = 1;
1933 holgerb 65
unsigned int PPM_Neutral = 466;
1 ingob 66
 
67
//############################################################################
2008 holgerb 68
// Clear the values
2341 holgerb 69
void rc_sum_init(void)
1 ingob 70
//############################################################################
71
{
1377 hbuss 72
 unsigned char i;
2341 holgerb 73
 for(i=0;i<MAX_RC_IN;i++)
1377 hbuss 74
  {
2183 holgerb 75
   if(i < 5) PPM_in[i] = 0; else PPM_in[i] = -127;
1377 hbuss 76
   PPM_diff[i] = 0;
77
  }
2342 holgerb 78
        PPM_in[PPM_IN_MAX] = +127;
2341 holgerb 79
        PPM_in[PPM_IN_OFF] = -127;
80
        PPM_in[PPM_IN_MID] = 0;
1 ingob 81
    AdNeutralGier = 0;
82
    AdNeutralRoll = 0;
83
    AdNeutralNick = 0;
84
    return;
85
}
1309 hbuss 86
 
1356 hbuss 87
#ifndef ACT_S3D_SUMMENSIGNAL
1278 hbuss 88
//############################################################################
2008 holgerb 89
// Interrupt function for the PPM-Input
1561 killagreg 90
ISR(TIMER1_CAPT_vect)
1278 hbuss 91
//############################################################################
92
{
2320 holgerb 93
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1309 hbuss 94
if(!(EE_Parameter.ExtraConfig & CFG_SENSITIVE_RC))
2320 holgerb 95
#endif
1309 hbuss 96
 {
1278 hbuss 97
        static unsigned int AltICR=0;
98
    signed int signal = 0,tmp;
1561 killagreg 99
        static int index;
100
 
101
        signal = (unsigned int) ICR1 - AltICR;
102
        AltICR = ICR1;
1283 hbuss 103
    //Syncronisationspause? (3.52 ms < signal < 25.6 ms)
1561 killagreg 104
        if((signal > 1100) && (signal < 8000))
1278 hbuss 105
        {
1320 hbuss 106
        Channels = index;
1278 hbuss 107
        if(index >= 4)  NewPpmData = 0;  // Null bedeutet: Neue Daten
1561 killagreg 108
        index = 1;
109
        }
110
        else
1278 hbuss 111
        {
2340 holgerb 112
        if(index < 13+4)
1278 hbuss 113
            {
1561 killagreg 114
            if((signal > 250) && (signal < 687))
115
                {
1933 holgerb 116
                signal -= PPM_Neutral;
1278 hbuss 117
                // Stabiles Signal
2008 holgerb 118
                                  if(EE_Parameter.FailsafeChannel == 0 || PPM_in[EE_Parameter.FailsafeChannel] < 100)  // forces Failsafe if the receiver doesn't have 'signal loss' on Failsafe
119
                                  {
120
                    if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10; else SenderOkay = 200;}
121
                                  }    
1561 killagreg 122
                tmp = (3 * (PPM_in[index]) + signal) / 4;
1278 hbuss 123
                if(tmp > signal+1) tmp--; else
1561 killagreg 124
                if(tmp < signal-1) tmp++;
2486 holgerb 125
                PPM_in[index] = tmp;
1561 killagreg 126
                if(SenderOkay >= 195)  PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3;
2486 holgerb 127
                else
128
                                 {
129
                                  PPM_diff[index] = 0;
130
                                  if(SenderOkay < 50)
131
                                        {                                
132
                                                PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] = 0;
133
                                                PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] = 0;
134
                                                PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] = 0;
135
                                                PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] = 0;
136
                                        }
137
                                 }
1561 killagreg 138
                }
139
            index++;
2334 holgerb 140
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
141
#else
2426 holgerb 142
/*
1639 holgerb 143
                   if(PlatinenVersion < 20)
144
            {  
145
             if(index == 5) J3High; else J3Low;  // Servosignal an J3 anlegen
146
             if(index == 6) J4High; else J4Low;  // Servosignal an J4 anlegen
147
             if(index == 7) J5High; else J5Low;  // Servosignal an J5 anlegen
148
                        }
2426 holgerb 149
*/
2334 holgerb 150
#endif
1278 hbuss 151
        }
152
        }
1309 hbuss 153
 }
2320 holgerb 154
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1561 killagreg 155
 else
1309 hbuss 156
 {
1 ingob 157
        static unsigned int AltICR=0;
2340 holgerb 158
    static int ppm_in[13+4];
159
    static int ppm_diff[13+4];
160
    static int old_ppm_in[13+4];
161
    static int old_ppm_diff[13+4];
173 holgerb 162
    signed int signal = 0,tmp;
1561 killagreg 163
        static unsigned char index, okay_cnt = 0;
164
        signal = (unsigned int) ICR1 - AltICR;
165
        AltICR = ICR1;
1283 hbuss 166
    //Syncronisationspause? (3.52 ms < signal < 25.6 ms)
1561 killagreg 167
        if((signal > 1100) && (signal < 8000))
1 ingob 168
        {
1268 hbuss 169
        tmpChannels = index;
1561 killagreg 170
        if(tmpChannels >= 4 && Channels == tmpChannels)
1268 hbuss 171
                 {
1276 hbuss 172
          if(okay_cnt > 10)
1268 hbuss 173
                   {
174
                   NewPpmData = 0;  // Null bedeutet: Neue Daten
2340 holgerb 175
                   for(index = 0; index < 13+4; index++)
1268 hbuss 176
                    {
1561 killagreg 177
                         if(okay_cnt > 30)
1268 hbuss 178
                          {
179
                           old_ppm_in[index] = PPM_in[index];
180
                           old_ppm_diff[index] = PPM_diff[index];
1561 killagreg 181
                          }
1268 hbuss 182
                     PPM_in[index] = ppm_in[index];
183
                     PPM_diff[index] = ppm_diff[index];
184
                    }
185
                   }
186
          if(okay_cnt < 255) okay_cnt++;
187
                 }
1561 killagreg 188
         else
1278 hbuss 189
                  {
190
                   if(okay_cnt > 100) okay_cnt = 10; else okay_cnt = 0;
191
                   ROT_ON;
192
                  }
1561 killagreg 193
        index = 1;
1268 hbuss 194
        if(!MotorenEin) Channels = tmpChannels;
1561 killagreg 195
        }
196
        else
1 ingob 197
        {
2340 holgerb 198
        if(index < 13+4)
1 ingob 199
            {
1561 killagreg 200
            if((signal > 250) && (signal < 687))
201
                {
1933 holgerb 202
                signal -= PPM_Neutral;
1 ingob 203
                // Stabiles Signal
1271 hbuss 204
                if((abs(signal - ppm_in[index]) < 6))
205
                                 {
2008 holgerb 206
                                  if(EE_Parameter.FailsafeChannel == 0 || PPM_in[EE_Parameter.FailsafeChannel] < 100)  // forces Failsafe if the receiver doesn't have 'signal loss' on Failsafe
207
                                  {
208
                                   if(okay_cnt > 25)  SenderOkay += 10;
209
                                   else
210
                                   if(okay_cnt > 10)  SenderOkay += 2;
211
                                   if(SenderOkay > 200) SenderOkay = 200;
212
                                  }
1271 hbuss 213
                                 }
1561 killagreg 214
                tmp = (3 * (ppm_in[index]) + signal) / 4;
604 hbuss 215
                if(tmp > signal+1) tmp--; else
1561 killagreg 216
                if(tmp < signal-1) tmp++;
217
                if(SenderOkay >= 190)  ppm_diff[index] = ((tmp - ppm_in[index]) / 3) * 3;
1268 hbuss 218
                else ppm_diff[index] = 0;
219
                ppm_in[index] = tmp;
1561 killagreg 220
                }
1268 hbuss 221
                        else ROT_ON;
2334 holgerb 222
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
223
#else
1639 holgerb 224
                   if(PlatinenVersion < 20)
225
            {  
226
             if(index == 5) J3High; else J3Low;  // Servosignal an J3 anlegen
227
             if(index == 6) J4High; else J4Low;  // Servosignal an J4 anlegen
228
             if(index == 7) J5High; else J5Low;  // Servosignal an J5 anlegen
229
                        }
2334 holgerb 230
#endif
1268 hbuss 231
          }
1561 killagreg 232
                  if(index < 20) index++;
1276 hbuss 233
          else
1561 killagreg 234
                  if(index == 20)
1268 hbuss 235
                  {
1276 hbuss 236
            unsigned char i;
1278 hbuss 237
            ROT_ON;
1276 hbuss 238
                    index = 30;
2340 holgerb 239
            for(i=0;i<13+4;i++) // restore from older data
1268 hbuss 240
                         {
1276 hbuss 241
                      PPM_in[i] = old_ppm_in[i];
242
                      PPM_diff[i] = 0;
243
//                        okay_cnt /= 2;
1268 hbuss 244
                 }
245
                  }
246
            }
1309 hbuss 247
 }
2320 holgerb 248
#endif
249
 
1171 hbuss 250
}
251
 
1561 killagreg 252
#else
1171 hbuss 253
//############################################################################
2008 holgerb 254
// Interrupt function for the PPM-Input
1561 killagreg 255
ISR(TIMER1_CAPT_vect)
1171 hbuss 256
//############################################################################
257
 
258
{
259
        static unsigned int AltICR=0;
260
    signed int signal = 0,tmp;
1561 killagreg 261
        static int index;
262
 
263
        signal = (unsigned int) ICR1 - AltICR;
1171 hbuss 264
        signal /= 2;
1561 killagreg 265
        AltICR = ICR1;
1171 hbuss 266
    //Syncronisationspause?
1561 killagreg 267
        if((signal > 1100*2) && (signal < 8000*2))
1171 hbuss 268
        {
269
        if(index >= 4)  NewPpmData = 0;  // Null bedeutet: Neue Daten
1561 killagreg 270
        index = 1;
271
        }
272
        else
1171 hbuss 273
        {
1377 hbuss 274
        if(index < 13)
1171 hbuss 275
            {
1561 killagreg 276
            if((signal > 250) && (signal < 687*2))
277
                {
1171 hbuss 278
                signal -= 962;
279
                // Stabiles Signal
280
                if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;}
1561 killagreg 281
                tmp = (3 * (PPM_in[index]) + signal) / 4;
1171 hbuss 282
                if(tmp > signal+1) tmp--; else
1561 killagreg 283
                if(tmp < signal-1) tmp++;
284
                if(SenderOkay >= 195)  PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3;
1171 hbuss 285
                else PPM_diff[index] = 0;
286
                PPM_in[index] = tmp;
1561 killagreg 287
                }
288
            index++;
1 ingob 289
        }
290
        }
291
}
1356 hbuss 292
#endif
1 ingob 293
 
2034 holgerb 294
 
295