Subversion Repositories FlightCtrl

Rev

Rev 2034 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2034 Rev 2050
1
/*#######################################################################################
1
/*#######################################################################################
2
Decodieren eines RC Summen Signals
2
Decodieren eines RC Summen Signals
3
#######################################################################################*/
3
#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) Holger Buss, Ingo Busker
-
 
6
// + only for non-profit use
-
 
7
// + www.MikroKopter.com
5
// + www.MikroKopter.com
-
 
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
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
8
// + porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
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.
9
// + see the File "License.txt" for further Informations
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.
10
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11
 
56
 
12
#include "rc.h"
57
#include "rc.h"
13
#include "main.h"
58
#include "main.h"
14
// Achtung: ACT_S3D_SUMMENSIGNAL wird in der Main.h gesetzt
59
// Achtung: ACT_S3D_SUMMENSIGNAL wird in der Main.h gesetzt
15
 
60
 
16
volatile int PPM_in[26];
61
volatile int PPM_in[26];
17
volatile int PPM_diff[26];  // das diffenzierte Stick-Signal
62
volatile int PPM_diff[26];  // das diffenzierte Stick-Signal
18
volatile char Channels,tmpChannels = 0;
63
volatile char Channels,tmpChannels = 0;
19
volatile unsigned char NewPpmData = 1;
64
volatile unsigned char NewPpmData = 1;
20
unsigned int PPM_Neutral = 466;
65
unsigned int PPM_Neutral = 466;
21
 
66
 
22
//############################################################################
67
//############################################################################
23
// Clear the values
68
// Clear the values
24
void rc_sum_init (void)
69
void rc_sum_init (void)
25
//############################################################################
70
//############################################################################
26
{
71
{
27
 unsigned char i;
72
 unsigned char i;
28
 for(i=0;i<26;i++)
73
 for(i=0;i<26;i++)
29
  {
74
  {
30
   if(i < 5) PPM_in[i] = 0; else PPM_in[i] = -126;
75
   if(i < 5) PPM_in[i] = 0; else PPM_in[i] = -126;
31
   PPM_diff[i] = 0;
76
   PPM_diff[i] = 0;
32
  }
77
  }
33
    AdNeutralGier = 0;
78
    AdNeutralGier = 0;
34
    AdNeutralRoll = 0;
79
    AdNeutralRoll = 0;
35
    AdNeutralNick = 0;
80
    AdNeutralNick = 0;
36
    return;
81
    return;
37
}
82
}
38
 
83
 
39
#ifndef ACT_S3D_SUMMENSIGNAL
84
#ifndef ACT_S3D_SUMMENSIGNAL
40
//############################################################################
85
//############################################################################
41
// Interrupt function for the PPM-Input
86
// Interrupt function for the PPM-Input
42
ISR(TIMER1_CAPT_vect)
87
ISR(TIMER1_CAPT_vect)
43
//############################################################################
88
//############################################################################
44
{
89
{
45
if(!(EE_Parameter.ExtraConfig & CFG_SENSITIVE_RC))
90
if(!(EE_Parameter.ExtraConfig & CFG_SENSITIVE_RC))
46
 {
91
 {
47
        static unsigned int AltICR=0;
92
        static unsigned int AltICR=0;
48
    signed int signal = 0,tmp;
93
    signed int signal = 0,tmp;
49
        static int index;
94
        static int index;
50
 
95
 
51
        signal = (unsigned int) ICR1 - AltICR;
96
        signal = (unsigned int) ICR1 - AltICR;
52
        AltICR = ICR1;
97
        AltICR = ICR1;
53
    //Syncronisationspause? (3.52 ms < signal < 25.6 ms)
98
    //Syncronisationspause? (3.52 ms < signal < 25.6 ms)
54
        if((signal > 1100) && (signal < 8000))
99
        if((signal > 1100) && (signal < 8000))
55
        {
100
        {
56
        Channels = index;
101
        Channels = index;
57
        if(index >= 4)  NewPpmData = 0;  // Null bedeutet: Neue Daten
102
        if(index >= 4)  NewPpmData = 0;  // Null bedeutet: Neue Daten
58
        index = 1;
103
        index = 1;
59
        }
104
        }
60
        else
105
        else
61
        {
106
        {
62
        if(index < 13)
107
        if(index < 13)
63
            {
108
            {
64
            if((signal > 250) && (signal < 687))
109
            if((signal > 250) && (signal < 687))
65
                {
110
                {
66
                signal -= PPM_Neutral;
111
                signal -= PPM_Neutral;
67
                // Stabiles Signal
112
                // Stabiles Signal
68
                                  if(EE_Parameter.FailsafeChannel == 0 || PPM_in[EE_Parameter.FailsafeChannel] < 100)  // forces Failsafe if the receiver doesn't have 'signal loss' on Failsafe
113
                                  if(EE_Parameter.FailsafeChannel == 0 || PPM_in[EE_Parameter.FailsafeChannel] < 100)  // forces Failsafe if the receiver doesn't have 'signal loss' on Failsafe
69
                                  {
114
                                  {
70
                    if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10; else SenderOkay = 200;}
115
                    if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10; else SenderOkay = 200;}
71
                                  }    
116
                                  }    
72
                tmp = (3 * (PPM_in[index]) + signal) / 4;
117
                tmp = (3 * (PPM_in[index]) + signal) / 4;
73
                if(tmp > signal+1) tmp--; else
118
                if(tmp > signal+1) tmp--; else
74
                if(tmp < signal-1) tmp++;
119
                if(tmp < signal-1) tmp++;
75
                if(SenderOkay >= 195)  PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3;
120
                if(SenderOkay >= 195)  PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3;
76
                else PPM_diff[index] = 0;
121
                else PPM_diff[index] = 0;
77
                PPM_in[index] = tmp;
122
                PPM_in[index] = tmp;
78
                }
123
                }
79
            index++;
124
            index++;
80
                   if(PlatinenVersion < 20)
125
                   if(PlatinenVersion < 20)
81
            {  
126
            {  
82
             if(index == 5) J3High; else J3Low;  // Servosignal an J3 anlegen
127
             if(index == 5) J3High; else J3Low;  // Servosignal an J3 anlegen
83
             if(index == 6) J4High; else J4Low;  // Servosignal an J4 anlegen
128
             if(index == 6) J4High; else J4Low;  // Servosignal an J4 anlegen
84
             if(index == 7) J5High; else J5Low;  // Servosignal an J5 anlegen
129
             if(index == 7) J5High; else J5Low;  // Servosignal an J5 anlegen
85
                        }
130
                        }
86
        }
131
        }
87
        }
132
        }
88
 }
133
 }
89
 else
134
 else
90
 {
135
 {
91
        static unsigned int AltICR=0;
136
        static unsigned int AltICR=0;
92
    static int ppm_in[13];
137
    static int ppm_in[13];
93
    static int ppm_diff[13];
138
    static int ppm_diff[13];
94
    static int old_ppm_in[13];
139
    static int old_ppm_in[13];
95
    static int old_ppm_diff[13];
140
    static int old_ppm_diff[13];
96
    signed int signal = 0,tmp;
141
    signed int signal = 0,tmp;
97
        static unsigned char index, okay_cnt = 0;
142
        static unsigned char index, okay_cnt = 0;
98
        signal = (unsigned int) ICR1 - AltICR;
143
        signal = (unsigned int) ICR1 - AltICR;
99
        AltICR = ICR1;
144
        AltICR = ICR1;
100
    //Syncronisationspause? (3.52 ms < signal < 25.6 ms)
145
    //Syncronisationspause? (3.52 ms < signal < 25.6 ms)
101
        if((signal > 1100) && (signal < 8000))
146
        if((signal > 1100) && (signal < 8000))
102
        {
147
        {
103
        tmpChannels = index;
148
        tmpChannels = index;
104
        if(tmpChannels >= 4 && Channels == tmpChannels)
149
        if(tmpChannels >= 4 && Channels == tmpChannels)
105
                 {
150
                 {
106
          if(okay_cnt > 10)
151
          if(okay_cnt > 10)
107
                   {
152
                   {
108
                   NewPpmData = 0;  // Null bedeutet: Neue Daten
153
                   NewPpmData = 0;  // Null bedeutet: Neue Daten
109
                   for(index = 0; index < 13; index++)
154
                   for(index = 0; index < 13; index++)
110
                    {
155
                    {
111
                         if(okay_cnt > 30)
156
                         if(okay_cnt > 30)
112
                          {
157
                          {
113
                           old_ppm_in[index] = PPM_in[index];
158
                           old_ppm_in[index] = PPM_in[index];
114
                           old_ppm_diff[index] = PPM_diff[index];
159
                           old_ppm_diff[index] = PPM_diff[index];
115
                          }
160
                          }
116
                     PPM_in[index] = ppm_in[index];
161
                     PPM_in[index] = ppm_in[index];
117
                     PPM_diff[index] = ppm_diff[index];
162
                     PPM_diff[index] = ppm_diff[index];
118
                    }
163
                    }
119
                   }
164
                   }
120
          if(okay_cnt < 255) okay_cnt++;
165
          if(okay_cnt < 255) okay_cnt++;
121
                 }
166
                 }
122
         else
167
         else
123
                  {
168
                  {
124
                   if(okay_cnt > 100) okay_cnt = 10; else okay_cnt = 0;
169
                   if(okay_cnt > 100) okay_cnt = 10; else okay_cnt = 0;
125
                   ROT_ON;
170
                   ROT_ON;
126
                  }
171
                  }
127
        index = 1;
172
        index = 1;
128
        if(!MotorenEin) Channels = tmpChannels;
173
        if(!MotorenEin) Channels = tmpChannels;
129
        }
174
        }
130
        else
175
        else
131
        {
176
        {
132
        if(index < 13)
177
        if(index < 13)
133
            {
178
            {
134
            if((signal > 250) && (signal < 687))
179
            if((signal > 250) && (signal < 687))
135
                {
180
                {
136
                signal -= PPM_Neutral;
181
                signal -= PPM_Neutral;
137
                // Stabiles Signal
182
                // Stabiles Signal
138
                if((abs(signal - ppm_in[index]) < 6))
183
                if((abs(signal - ppm_in[index]) < 6))
139
                                 {
184
                                 {
140
                                  if(EE_Parameter.FailsafeChannel == 0 || PPM_in[EE_Parameter.FailsafeChannel] < 100)  // forces Failsafe if the receiver doesn't have 'signal loss' on Failsafe
185
                                  if(EE_Parameter.FailsafeChannel == 0 || PPM_in[EE_Parameter.FailsafeChannel] < 100)  // forces Failsafe if the receiver doesn't have 'signal loss' on Failsafe
141
                                  {
186
                                  {
142
                                   if(okay_cnt > 25)  SenderOkay += 10;
187
                                   if(okay_cnt > 25)  SenderOkay += 10;
143
                                   else
188
                                   else
144
                                   if(okay_cnt > 10)  SenderOkay += 2;
189
                                   if(okay_cnt > 10)  SenderOkay += 2;
145
                                   if(SenderOkay > 200) SenderOkay = 200;
190
                                   if(SenderOkay > 200) SenderOkay = 200;
146
                                  }
191
                                  }
147
                                 }
192
                                 }
148
                tmp = (3 * (ppm_in[index]) + signal) / 4;
193
                tmp = (3 * (ppm_in[index]) + signal) / 4;
149
                if(tmp > signal+1) tmp--; else
194
                if(tmp > signal+1) tmp--; else
150
                if(tmp < signal-1) tmp++;
195
                if(tmp < signal-1) tmp++;
151
                if(SenderOkay >= 190)  ppm_diff[index] = ((tmp - ppm_in[index]) / 3) * 3;
196
                if(SenderOkay >= 190)  ppm_diff[index] = ((tmp - ppm_in[index]) / 3) * 3;
152
                else ppm_diff[index] = 0;
197
                else ppm_diff[index] = 0;
153
                ppm_in[index] = tmp;
198
                ppm_in[index] = tmp;
154
                }
199
                }
155
                        else ROT_ON;
200
                        else ROT_ON;
156
                   if(PlatinenVersion < 20)
201
                   if(PlatinenVersion < 20)
157
            {  
202
            {  
158
             if(index == 5) J3High; else J3Low;  // Servosignal an J3 anlegen
203
             if(index == 5) J3High; else J3Low;  // Servosignal an J3 anlegen
159
             if(index == 6) J4High; else J4Low;  // Servosignal an J4 anlegen
204
             if(index == 6) J4High; else J4Low;  // Servosignal an J4 anlegen
160
             if(index == 7) J5High; else J5Low;  // Servosignal an J5 anlegen
205
             if(index == 7) J5High; else J5Low;  // Servosignal an J5 anlegen
161
                        }
206
                        }
162
          }
207
          }
163
                  if(index < 20) index++;
208
                  if(index < 20) index++;
164
          else
209
          else
165
                  if(index == 20)
210
                  if(index == 20)
166
                  {
211
                  {
167
            unsigned char i;
212
            unsigned char i;
168
            ROT_ON;
213
            ROT_ON;
169
                    index = 30;
214
                    index = 30;
170
            for(i=0;i<13;i++) // restore from older data
215
            for(i=0;i<13;i++) // restore from older data
171
                         {
216
                         {
172
                      PPM_in[i] = old_ppm_in[i];
217
                      PPM_in[i] = old_ppm_in[i];
173
                      PPM_diff[i] = 0;
218
                      PPM_diff[i] = 0;
174
//                        okay_cnt /= 2;
219
//                        okay_cnt /= 2;
175
                 }
220
                 }
176
                  }
221
                  }
177
            }
222
            }
178
 }
223
 }
179
}
224
}
180
 
225
 
181
#else
226
#else
182
//############################################################################
227
//############################################################################
183
// Interrupt function for the PPM-Input
228
// Interrupt function for the PPM-Input
184
ISR(TIMER1_CAPT_vect)
229
ISR(TIMER1_CAPT_vect)
185
//############################################################################
230
//############################################################################
186
 
231
 
187
{
232
{
188
        static unsigned int AltICR=0;
233
        static unsigned int AltICR=0;
189
    signed int signal = 0,tmp;
234
    signed int signal = 0,tmp;
190
        static int index;
235
        static int index;
191
 
236
 
192
        signal = (unsigned int) ICR1 - AltICR;
237
        signal = (unsigned int) ICR1 - AltICR;
193
        signal /= 2;
238
        signal /= 2;
194
        AltICR = ICR1;
239
        AltICR = ICR1;
195
    //Syncronisationspause?
240
    //Syncronisationspause?
196
        if((signal > 1100*2) && (signal < 8000*2))
241
        if((signal > 1100*2) && (signal < 8000*2))
197
        {
242
        {
198
        if(index >= 4)  NewPpmData = 0;  // Null bedeutet: Neue Daten
243
        if(index >= 4)  NewPpmData = 0;  // Null bedeutet: Neue Daten
199
        index = 1;
244
        index = 1;
200
        }
245
        }
201
        else
246
        else
202
        {
247
        {
203
        if(index < 13)
248
        if(index < 13)
204
            {
249
            {
205
            if((signal > 250) && (signal < 687*2))
250
            if((signal > 250) && (signal < 687*2))
206
                {
251
                {
207
                signal -= 962;
252
                signal -= 962;
208
                // Stabiles Signal
253
                // Stabiles Signal
209
                if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;}
254
                if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;}
210
                tmp = (3 * (PPM_in[index]) + signal) / 4;
255
                tmp = (3 * (PPM_in[index]) + signal) / 4;
211
                if(tmp > signal+1) tmp--; else
256
                if(tmp > signal+1) tmp--; else
212
                if(tmp < signal-1) tmp++;
257
                if(tmp < signal-1) tmp++;
213
                if(SenderOkay >= 195)  PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3;
258
                if(SenderOkay >= 195)  PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3;
214
                else PPM_diff[index] = 0;
259
                else PPM_diff[index] = 0;
215
                PPM_in[index] = tmp;
260
                PPM_in[index] = tmp;
216
                }
261
                }
217
            index++;
262
            index++;
218
        }
263
        }
219
        }
264
        }
220
}
265
}
221
#endif
266
#endif
222
 
267
 
223
 
268
 
224
 
269
 
225
 
270