Subversion Repositories FlightCtrl

Rev

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

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