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