Subversion Repositories FlightCtrl

Rev

Rev 987 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 987 Rev 1040
1
/*
1
/*
2
Copyright 2008, by Michael Walter
2
Copyright 2008, by Michael Walter
3
 
3
 
4
All functions written by Michael Walter are free software and can be redistributed and/or modified under the terms of the GNU Lesser
4
All functions written by Michael Walter are free software and can be redistributed and/or modified under the terms of the GNU Lesser
5
General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but
5
General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but
6
WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
6
WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7
See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public
7
See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public
8
License along with this program. If not, see <http://www.gnu.org/licenses/>.
8
License along with this program. If not, see <http://www.gnu.org/licenses/>.
9
 
9
 
10
Please note: The software is based on the framework provided by H. Buss and I. Busker in their Mikrokopter projekt. All functions that
10
Please note: The software is based on the framework provided by H. Buss and I. Busker in their Mikrokopter projekt. All functions that
11
are not written by Michael Walter are under the license by H. Buss and I. Busker (license_buss.txt) published by www.mikrokopter.de
11
are not written by Michael Walter are under the license by H. Buss and I. Busker (license_buss.txt) published by www.mikrokopter.de
12
unless it is stated otherwise.
12
unless it is stated otherwise.
13
*/
13
*/
14
 
14
 
15
 
15
 
16
/*****************************************************************************
16
/*****************************************************************************
17
  INCLUDES
17
  INCLUDES
18
**************************************************************************** */
18
**************************************************************************** */
19
#include "kafi.h"
19
#include "kafi.h"
20
#include "FlightControl.h"
20
#include "FlightControl.h"
21
#include "main.h"
21
#include "main.h"
22
#include "mm3.h"
22
#include "mm3.h"
23
#include "main.h"
23
#include "main.h"
24
#include "eeprom.c"
24
#include "eeprom.c"
25
 
25
 
26
/*****************************************************************************
26
/*****************************************************************************
27
(SYMBOLIC) CONSTANTS
27
(SYMBOLIC) CONSTANTS
28
*****************************************************************************/
28
*****************************************************************************/
29
#define MAX_GAS 250
29
#define MAX_GAS 250
30
#define MIN_GAS    15
30
#define MIN_GAS    15
31
 
31
 
32
#define sin45 sin(45.F / 180.F * PI) 
32
#define sin45 sin(45.F / 180.F * PI) 
33
#define cos45 cos(45.F / 180.F * PI)
33
#define cos45 cos(45.F / 180.F * PI)
34
 
34
 
35
/*****************************************************************************
35
/*****************************************************************************
36
  VARIABLES
36
  VARIABLES
37
*****************************************************************************/
37
*****************************************************************************/
38
 
38
 
39
extern void GPSupdate(void);
39
extern void GPSupdate(void);
40
 
40
 
41
f32_t AdNeutralNick = 0.0F, AdNeutralRoll = 0.0F, AdNeutralGier = 0.0F;
41
f32_t AdNeutralNick = 0.0F, AdNeutralRoll = 0.0F, AdNeutralGier = 0.0F;
42
int NeutralAccX = 0, NeutralAccY = 0, NeutralAccZ = 0;
42
int NeutralAccX = 0, NeutralAccY = 0, NeutralAccZ = 0;
43
int AverageRoll = 0, AverageNick = 0, AverageGier = 0;
43
int AverageRoll = 0, AverageNick = 0, AverageGier = 0;
44
int AveragerACC_X = 0, AveragerACC_Y = 0, AveragerACC_Z = 0;
44
int AveragerACC_X = 0, AveragerACC_Y = 0, AveragerACC_Z = 0;
45
 
45
 
46
f32_t Roll_X_Offset = 0.F, Roll_Y_Offset = 0.F, Roll_Z_Offset = 0.F;
46
f32_t Roll_X_Offset = 0.F, Roll_Y_Offset = 0.F, Roll_Z_Offset = 0.F;
47
f32_t ACC_X_Offset = 0.F, ACC_Y_Offset = 0.F,  ACC_Z_Offset = 0.F;
47
f32_t ACC_X_Offset = 0.F, ACC_Y_Offset = 0.F,  ACC_Z_Offset = 0.F;
48
 
48
 
49
int DeltaAltitude = 0, CurrentAltitude = 0, LastAltitude = 0, InitialAltitude = 0;
49
int DeltaAltitude = 0, CurrentAltitude = 0, LastAltitude = 0, InitialAltitude = 0;
50
int SummeNick=0,SummeRoll=0, StickNick = 0,StickRoll = 0,StickGier = 0, sollGier = 0;
50
int SummeNick=0,SummeRoll=0, StickNick = 0,StickRoll = 0,StickGier = 0, sollGier = 0;
51
int GierMischanteil, GasMischanteil;
51
int GierMischanteil, GasMischanteil;
52
 
52
 
53
unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
53
unsigned char Motor_Vorne,Motor_Hinten,Motor_Rechts,Motor_Links, Count;
54
unsigned char MotorWert[5];
54
unsigned char MotorWert[5];
55
unsigned char SenderOkay = 0;
55
unsigned char SenderOkay = 0;
56
unsigned int I2CTimeout = 100;
56
unsigned int I2CTimeout = 100;
57
char MotorenEin = 0;
57
char MotorenEin = 0;
58
unsigned int  modell_fliegt = 0;
58
unsigned int  modell_fliegt = 0;
59
 
59
 
60
extern unsigned long maxDistance;
60
extern unsigned long maxDistance;
61
extern signed int GPS_Nick,  GPS_Roll;
61
extern signed int GPS_Nick,  GPS_Roll;
62
extern int RemoteLinkLost;
62
extern int RemoteLinkLost;
63
extern int InvalidAttitude;
63
extern int InvalidAttitude;
64
struct mk_param_struct EE_Parameter;
64
struct mk_param_struct EE_Parameter;
65
 
65
 
66
/* ****************************************************************************
66
/* ****************************************************************************
67
Functionname:     SetNeutral                      */ /*!
67
Functionname:     SetNeutral                      */ /*!
68
Description:    
68
Description:    
69
 
69
 
70
@param[in]        
70
@param[in]        
71
 
71
 
72
  @return           void
72
  @return           void
73
  @pre              -
73
  @pre              -
74
  @post             -
74
  @post             -
75
  @author         Michael Walter  
75
  @author         Michael Walter  
76
**************************************************************************** */
76
**************************************************************************** */
77
void SetNeutral(void)
77
void SetNeutral(void)
78
{
78
{
79
  beeptime = 2000;
79
  beeptime = 2000;
80
  Delay_ms(1000);
80
  Delay_ms(1000);
81
  if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
81
  if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
82
  {    
82
  {    
83
    if((AdWertAirPressure_Raw > 950) || (AdWertAirPressure_Raw < 750))
83
    if((AdWertAirPressure_Raw > 950) || (AdWertAirPressure_Raw < 750))
84
    {
84
    {
85
      SucheLuftruckOffset();
85
      SucheLuftruckOffset();
86
    }
86
    }
87
  }
87
  }
88
 
88
 
89
  LastAltitude = CurrentAltitude;
89
  LastAltitude = CurrentAltitude;
90
  Delay_ms_Mess(300);
90
  Delay_ms_Mess(300);
91
 
91
 
92
  ANALOG_OFF;
92
  ANALOG_OFF;
93
  AdNeutralNick = (f32_t) AdWertNick_Raw;
93
  AdNeutralNick = (f32_t) AdWertNick_Raw;
94
  AdNeutralRoll = (f32_t) AdWertRoll_Raw;
94
  AdNeutralRoll = (f32_t) AdWertRoll_Raw;
95
  AdNeutralGier = (f32_t) AdWertGier_Raw;
95
  AdNeutralGier = (f32_t) AdWertGier_Raw;
96
  NeutralAccY = AdWertAccRoll_Raw;
96
  NeutralAccY = AdWertAccRoll_Raw;
97
  NeutralAccX = AdWertAccNick_Raw;
97
  NeutralAccX = AdWertAccNick_Raw;
98
  NeutralAccZ = AdWertAccHoch_Raw;
98
  NeutralAccZ = AdWertAccHoch_Raw;
99
 
99
 
100
  Roll_X_Offset = 0.F;
100
  Roll_X_Offset = 0.F;
101
  Roll_Y_Offset = 0.F;
101
  Roll_Y_Offset = 0.F;
102
  Roll_Z_Offset = 0.F;
102
  Roll_Z_Offset = 0.F;
103
  ACC_X_Offset = 0.F;
103
  ACC_X_Offset = 0.F;
104
  ACC_Y_Offset = 0.F;
104
  ACC_Y_Offset = 0.F;
105
  ACC_Z_Offset = 0.F;
105
  ACC_Z_Offset = 0.F;
106
 
106
 
107
  AccumulatedACC_X = 0;
107
  AccumulatedACC_X = 0;
108
  AccumulatedACC_X_cnt = 0;
108
  AccumulatedACC_X_cnt = 0;
109
  AccumulatedACC_Y = 0;
109
  AccumulatedACC_Y = 0;
110
  AccumulatedACC_Y_cnt = 0;
110
  AccumulatedACC_Y_cnt = 0;
111
  AccumulatedACC_Z = 0;
111
  AccumulatedACC_Z = 0;
112
  AccumulatedACC_Z_cnt = 0;
112
  AccumulatedACC_Z_cnt = 0;
113
 
113
 
114
  AccumulatedRoll = 0;
114
  AccumulatedRoll = 0;
115
  AccumulatedRoll_cnt = 0;
115
  AccumulatedRoll_cnt = 0;
116
  AccumulatedNick = 0;
116
  AccumulatedNick = 0;
117
  AccumulatedNick_cnt = 0;
117
  AccumulatedNick_cnt = 0;
118
  AccumulatedGier = 0;
118
  AccumulatedGier = 0;
119
  AccumulatedGier_cnt = 0;
119
  AccumulatedGier_cnt = 0;
120
 
120
 
121
  AveragerACC_X = 0;
121
  AveragerACC_X = 0;
122
  AveragerACC_Y = 0;
122
  AveragerACC_Y = 0;
123
  AveragerACC_Z = 0;
123
  AveragerACC_Z = 0;
124
 
124
 
125
  AccumulatedACC_X = 0;
125
  AccumulatedACC_X = 0;
126
  AccumulatedACC_X_cnt = 0;
126
  AccumulatedACC_X_cnt = 0;
127
  AccumulatedACC_Y = 0;
127
  AccumulatedACC_Y = 0;
128
  AccumulatedACC_Y_cnt = 0;
128
  AccumulatedACC_Y_cnt = 0;
129
  AccumulatedACC_Z = 0;
129
  AccumulatedACC_Z = 0;
130
  AccumulatedACC_Z_cnt = 0;
130
  AccumulatedACC_Z_cnt = 0;
131
  ANALOG_ON;
131
  ANALOG_ON;
132
 
132
 
133
  SummeRoll = 0;
133
  SummeRoll = 0;
134
  SummeNick = 0;
134
  SummeNick = 0;
135
 
135
 
136
  sollGier = status.iPsi10;
136
  sollGier = status.iPsi10;
137
  InitialAltitude = AdWertAirPressure_Raw;
137
  InitialAltitude = AdWertAirPressure_Raw;
138
 
138
 
139
  InvalidAttitude = 0;
139
  InvalidAttitude = 0;
140
  beeptime = 2000;
140
  beeptime = 2000;
141
}
141
}
142
 
142
 
143
 
143
 
144
/* ****************************************************************************
144
/* ****************************************************************************
145
Functionname:    GetMeasurements                      */ /*!
145
Functionname:    GetMeasurements                      */ /*!
146
Description:    CalculateAverage
146
Description:    CalculateAverage
147
 
147
 
148
@param[in]        
148
@param[in]        
149
 
149
 
150
  @return           void
150
  @return           void
151
  @pre              -
151
  @pre              -
152
  @post             -
152
  @post             -
153
  @author         Michael Walter  
153
  @author         Michael Walter  
154
**************************************************************************** */
154
**************************************************************************** */
155
void GetMeasurements(void)
155
void GetMeasurements(void)
156
{
156
{
-
 
157
  static int LongTermAccumulatedRoll = 0;
-
 
158
  static int LongTermAccumulatedNick = 0;
-
 
159
  static int LongTermAccumulatedRoll_Cnt = 0;
-
 
160
  static int LongTermAccumulatedNick_Cnt = 0;
-
 
161
   
157
  ANALOG_OFF;
162
  ANALOG_OFF;
158
  AverageRoll = AccumulatedRoll / AccumulatedRoll_cnt;
163
  AverageRoll = AccumulatedRoll / AccumulatedRoll_cnt;
159
  AverageNick = AccumulatedNick / AccumulatedNick_cnt;
164
  AverageNick = AccumulatedNick / AccumulatedNick_cnt;
160
  AverageGier = AccumulatedGier / AccumulatedGier_cnt;
165
  AverageGier = AccumulatedGier / AccumulatedGier_cnt;
161
 
166
 
162
  /* Get Pressure Differenz */
167
  /* Get Pressure Differenz */
163
  CurrentAltitude = InitialAltitude - AccumulatedAirPressure / AccumulatedAirPressure_cnt;
168
  CurrentAltitude = InitialAltitude - AccumulatedAirPressure / AccumulatedAirPressure_cnt;
164
  AccumulatedAirPressure_cnt = 0;
169
  AccumulatedAirPressure_cnt = 0;
165
  AccumulatedAirPressure = 0;
170
  AccumulatedAirPressure = 0;
166
 
171
 
167
  static char AirPressureCnt = 0;
172
  static char AirPressureCnt = 0;
168
  if (AirPressureCnt % 25 == 1)
173
  if (AirPressureCnt % 25 == 1)
169
  {
174
  {
170
    DeltaAltitude = CurrentAltitude - LastAltitude;
175
    DeltaAltitude = CurrentAltitude - LastAltitude;
171
    LastAltitude = CurrentAltitude;
176
    LastAltitude = CurrentAltitude;
172
  }
177
  }
173
  AirPressureCnt++;
178
  AirPressureCnt++;
-
 
179
 
-
 
180
  if (LongTermAccumulatedRoll_Cnt < 500)
-
 
181
  {
-
 
182
    if (abs(LongTermAccumulatedRoll) < 10000)
-
 
183
    {
-
 
184
        LongTermAccumulatedRoll += AverageRoll;
-
 
185
    }
-
 
186
    LongTermAccumulatedRoll_Cnt++;
-
 
187
   
-
 
188
    if(abs(LongTermAccumulatedNick) < 10000)
-
 
189
    {
-
 
190
        LongTermAccumulatedNick += AverageNick;
-
 
191
    }
-
 
192
    LongTermAccumulatedNick_Cnt++;
-
 
193
  }
-
 
194
  else
-
 
195
  {
-
 
196
   static float fPreviousPsi =0.0F;
-
 
197
   static float fPreviousTheta =0.0F;
-
 
198
 
-
 
199
    //DebugOut.Analog[8] = (int) (((status.Phi - fPreviousPsi) / (0.00001F * fCycleTime)) / LongTermAccumulatedRoll_Cnt );
-
 
200
    //DebugOut.Analog[9] = (int) ((LongTermAccumulatedRoll / LongTermAccumulatedRoll_Cnt));
-
 
201
 
-
 
202
    AdNeutralRoll += (int) ((LongTermAccumulatedRoll + (status.Phi - fPreviousPsi) / (0.00001F * fCycleTime)) / LongTermAccumulatedRoll_Cnt );
-
 
203
    AdNeutralNick += (int) ((LongTermAccumulatedNick + (status.Theta - fPreviousTheta) / (0.00001F * fCycleTime)) / LongTermAccumulatedNick_Cnt );
-
 
204
 
-
 
205
    fPreviousPsi = status.Phi;
-
 
206
    fPreviousTheta =  status.Theta;
-
 
207
   
-
 
208
    //AdNeutralRoll += (MAX(-20, MIN(20,LongTermAccumulatedRoll / LongTermAccumulatedRoll_Cnt)));
-
 
209
    //AdNeutralNick += (MAX(-20, MIN(20,LongTermAccumulatedNick / LongTermAccumulatedNick_Cnt)));
-
 
210
       
-
 
211
    LongTermAccumulatedRoll_Cnt = 0;
-
 
212
    LongTermAccumulatedNick_Cnt = 0;
-
 
213
    LongTermAccumulatedRoll = 0;
-
 
214
    LongTermAccumulatedNick = 0;
-
 
215
  }
-
 
216
 
-
 
217
#if 0
-
 
218
  DebugOut.Analog[3] = fSumNick;
-
 
219
  DebugOut.Analog[4] = fSumRoll;
-
 
220
  DebugOut.Analog[5] = fSumGier;
-
 
221
#endif  
-
 
222
 
174
 
223
 
175
  if(modell_fliegt < 0x250)
224
  if((modell_fliegt < 0x250) && 0)
176
  {
225
  {
177
    //if ((GPS_Roll == 0 && GPS_Nick == 0) || (maxDistance / 10 > 10))
226
    //if ((GPS_Roll == 0 && GPS_Nick == 0) || (maxDistance / 10 > 10))
178
    AdNeutralNick = 0.998F * AdNeutralNick + 0.002F * AdWertNick_Raw;
227
    AdNeutralNick = 0.998F * AdNeutralNick + 0.002F * AdWertNick_Raw;
179
    AdNeutralRoll = 0.998F * AdNeutralRoll + 0.002F * AdWertRoll_Raw;
228
    AdNeutralRoll = 0.998F * AdNeutralRoll + 0.002F * AdWertRoll_Raw;
180
    if (abs(StickGier) < 15 || MotorenEin == 0)
229
    if (abs(StickGier) < 15 || MotorenEin == 0)
181
    {
230
    {
182
      AdNeutralGier = 0.998F * AdNeutralGier + 0.002F * AdWertGier_Raw;
231
      AdNeutralGier = 0.998F * AdNeutralGier + 0.002F * AdWertGier_Raw;
183
    }
232
    }
184
  }
233
  }
185
  else if(modell_fliegt < 0x2000)
234
  else if(modell_fliegt < 0x2000&& 0)
186
  {
235
  {
187
    //if ((GPS_Roll == 0 && GPS_Nick == 0) || (maxDistance / 10 > 10))
236
    //if ((GPS_Roll == 0 && GPS_Nick == 0) || (maxDistance / 10 > 10))
188
    AdNeutralNick = 0.999F * AdNeutralNick + 0.001F * AdWertNick_Raw;
237
    AdNeutralNick = 0.999F * AdNeutralNick + 0.001F * AdWertNick_Raw;
189
    AdNeutralRoll = 0.999F * AdNeutralRoll + 0.001F * AdWertRoll_Raw;
238
    AdNeutralRoll = 0.999F * AdNeutralRoll + 0.001F * AdWertRoll_Raw;
190
    if (abs(StickGier) < 15 || MotorenEin == 0)
239
    if (abs(StickGier) < 15 || MotorenEin == 0)
191
    {
240
    {
192
      AdNeutralGier = 0.999F * AdNeutralGier + 0.001F * AdWertGier_Raw;
241
      AdNeutralGier = 0.999F * AdNeutralGier + 0.001F * AdWertGier_Raw;
193
    }
242
    }
194
  }
243
  }
195
  else
244
  else
196
  {
245
  {
197
    AdNeutralNick = 0.9995F * AdNeutralNick + 0.0005F * AdWertNick_Raw;
246
    AdNeutralNick = 0.9995F * AdNeutralNick + 0.0005F * AdWertNick_Raw;
198
    AdNeutralRoll = 0.9995F * AdNeutralRoll + 0.0005F * AdWertRoll_Raw;
247
    AdNeutralRoll = 0.9995F * AdNeutralRoll + 0.0005F * AdWertRoll_Raw;
199
    if (abs(StickGier) < 15 || MotorenEin == 0)
248
    if (abs(StickGier) < 15 || MotorenEin == 0)
200
    {
249
    {
201
      AdNeutralGier = 0.9995F * AdNeutralGier + 0.0005F * AdWertGier_Raw;
250
      AdNeutralGier = 0.9995F * AdNeutralGier + 0.0005F * AdWertGier_Raw;
202
    }
251
    }
203
  }
252
  }
204
 
253
 
205
#if 1
254
#if 1
206
  DebugOut.Analog[6] = AdWertNick_Raw;
255
  DebugOut.Analog[6] = AdWertNick_Raw;
207
  DebugOut.Analog[7] = AdWertRoll_Raw;
256
  DebugOut.Analog[7] = AdWertRoll_Raw;
208
  DebugOut.Analog[8] = AdWertGier_Raw;
257
  DebugOut.Analog[8] = AdWertGier_Raw;
209
 
258
 
210
  DebugOut.Analog[9] = AdNeutralNick;
259
  DebugOut.Analog[9] = AdNeutralNick;
211
  DebugOut.Analog[10] = AdNeutralRoll;
260
  DebugOut.Analog[10] = AdNeutralRoll;
212
  DebugOut.Analog[11] = AdNeutralGier;
261
  DebugOut.Analog[11] = AdNeutralGier;
213
#endif
262
#endif
214
 
263
 
215
  AccumulatedRoll = 0;
264
  AccumulatedRoll = 0;
216
  AccumulatedRoll_cnt = 0;
265
  AccumulatedRoll_cnt = 0;
217
  AccumulatedNick = 0;
266
  AccumulatedNick = 0;
218
  AccumulatedNick_cnt = 0;
267
  AccumulatedNick_cnt = 0;
219
  AccumulatedGier = 0;
268
  AccumulatedGier = 0;
220
  AccumulatedGier_cnt = 0;
269
  AccumulatedGier_cnt = 0;
221
 
270
 
222
#if 0
271
#if 0
223
  ACC_X_Offset = 0.9999F * ACC_X_Offset + 0.0001F * ((float) AccumulatedACC_X / (float) AccumulatedACC_X_cnt);
272
  ACC_X_Offset = 0.9999F * ACC_X_Offset + 0.0001F * ((float) AccumulatedACC_X / (float) AccumulatedACC_X_cnt);
224
  ACC_Y_Offset = 0.9999F * ACC_Y_Offset + 0.0001F * ((float) AccumulatedACC_Y / (float) AccumulatedACC_Y_cnt);
273
  ACC_Y_Offset = 0.9999F * ACC_Y_Offset + 0.0001F * ((float) AccumulatedACC_Y / (float) AccumulatedACC_Y_cnt);
225
  ACC_Z_Offset = 0.9999F * ACC_Z_Offset + 0.0001F * ((float) AccumulatedACC_Z / (float) AccumulatedACC_Z_cnt);
274
  ACC_Z_Offset = 0.9999F * ACC_Z_Offset + 0.0001F * ((float) AccumulatedACC_Z / (float) AccumulatedACC_Z_cnt);
226
#endif
275
#endif
227
 
276
 
228
  AveragerACC_X =  AccumulatedACC_X / AccumulatedACC_X_cnt;
277
  AveragerACC_X =  AccumulatedACC_X / AccumulatedACC_X_cnt;
229
  AveragerACC_Y =  AccumulatedACC_Y / AccumulatedACC_Y_cnt;
278
  AveragerACC_Y =  AccumulatedACC_Y / AccumulatedACC_Y_cnt;
230
  AveragerACC_Z =  AccumulatedACC_Z / AccumulatedACC_Z_cnt;
279
  AveragerACC_Z =  AccumulatedACC_Z / AccumulatedACC_Z_cnt;
231
 
280
 
232
  AccumulatedACC_X = 0;
281
  AccumulatedACC_X = 0;
233
  AccumulatedACC_X_cnt = 0;
282
  AccumulatedACC_X_cnt = 0;
234
  AccumulatedACC_Y = 0;
283
  AccumulatedACC_Y = 0;
235
  AccumulatedACC_Y_cnt = 0;
284
  AccumulatedACC_Y_cnt = 0;
236
  AccumulatedACC_Z = 0;
285
  AccumulatedACC_Z = 0;
237
  AccumulatedACC_Z_cnt = 0;
286
  AccumulatedACC_Z_cnt = 0;
238
 
287
 
239
  ANALOG_ON;
288
  ANALOG_ON;
240
}
289
}
241
 
290
 
242
/* ****************************************************************************
291
/* ****************************************************************************
243
Functionname:     SendMotorData                      */ /*!
292
Functionname:     SendMotorData                      */ /*!
244
Description:          Senden der Motorwerte per I2C-Bus
293
Description:          Senden der Motorwerte per I2C-Bus
245
 
294
 
246
  @return           void
295
  @return           void
247
  @pre              -
296
  @pre              -
248
  @post             -
297
  @post             -
249
  @author           H. Buss / I. Busker
298
  @author           H. Buss / I. Busker
250
**************************************************************************** */
299
**************************************************************************** */
251
void SendMotorData(void)
300
void SendMotorData(void)
252
{
301
{
253
  if(!MotorenEin)
302
  if(!MotorenEin)
254
  {
303
  {
255
    Motor_Hinten = 0;
304
    Motor_Hinten = 0;
256
    Motor_Vorne = 0;
305
    Motor_Vorne = 0;
257
    Motor_Rechts = 0;
306
    Motor_Rechts = 0;
258
    Motor_Links = 0;
307
    Motor_Links = 0;
259
    if(MotorTest[0]) Motor_Vorne = MotorTest[0];
308
    if(MotorTest[0]) Motor_Vorne = MotorTest[0];
260
    if(MotorTest[1]) Motor_Hinten = MotorTest[1];
309
    if(MotorTest[1]) Motor_Hinten = MotorTest[1];
261
    if(MotorTest[2]) Motor_Links = MotorTest[2];
310
    if(MotorTest[2]) Motor_Links = MotorTest[2];
262
    if(MotorTest[3]) Motor_Rechts = MotorTest[3];
311
    if(MotorTest[3]) Motor_Rechts = MotorTest[3];
263
  }
312
  }
264
 
313
 
265
  //Start I2C Interrupt Mode
314
  //Start I2C Interrupt Mode
266
  twi_state = 0;
315
  twi_state = 0;
267
  motor = 0;
316
  motor = 0;
268
  i2c_start();
317
  i2c_start();
269
}
318
}
270
 
319
 
271
 
320
 
272
/* ****************************************************************************
321
/* ****************************************************************************
273
Functionname:     RemoteControl                      */ /*!
322
Functionname:     RemoteControl                      */ /*!
274
Description:      
323
Description:      
275
 
324
 
276
  @return           void
325
  @return           void
277
  @pre              -
326
  @pre              -
278
  @post             -
327
  @post             -
279
  @author           H. Buss / I. Busker
328
  @author           H. Buss / I. Busker
280
**************************************************************************** */
329
**************************************************************************** */
281
void RemoteControl(void)
330
void RemoteControl(void)
282
{
331
{
283
  static unsigned char delay_neutral = 0;
332
  static unsigned char delay_neutral = 0;
284
  static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
333
  static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
285
 
334
 
286
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
335
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
287
  // Gaswert ermitteln
336
  // Gaswert ermitteln
288
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
337
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
289
  GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
338
  GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
290
  if(GasMischanteil < 0)
339
  if(GasMischanteil < 0)
291
  {
340
  {
292
    GasMischanteil = 0;
341
    GasMischanteil = 0;
293
  }
342
  }
294
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
343
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
295
  // Emfang schlecht
344
  // Emfang schlecht
296
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
345
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
297
  if(SenderOkay < 100)
346
  if(SenderOkay < 100)
298
  {
347
  {
299
    if(!PcZugriff)
348
    if(!PcZugriff)
300
    {
349
    {
301
      if(BeepMuster == 0xffff)
350
      if(BeepMuster == 0xffff)
302
      {
351
      {
303
        beeptime = 15000;
352
        beeptime = 15000;
304
        BeepMuster = 0x0c00;
353
        BeepMuster = 0x0c00;
305
      }
354
      }
306
    }
355
    }
307
  }
356
  }
308
  else
357
  else
309
  {
358
  {
310
    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
359
    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
311
    // Emfang gut
360
    // Emfang gut
312
    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
361
    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
313
    if(SenderOkay > 140)
362
    if(SenderOkay > 140)
314
    {
363
    {
315
      if(GasMischanteil > 40)
364
      if(GasMischanteil > 40)
316
      {
365
      {
317
        if(modell_fliegt < 0xffff)
366
        if(modell_fliegt < 0xffff)
318
        {
367
        {
319
          modell_fliegt++;
368
          modell_fliegt++;
320
        }
369
        }
321
      }
370
      }
322
     
371
     
323
     
372
     
324
      if((GasMischanteil > 200) &&
373
      if((GasMischanteil > 200) &&
325
        (MotorenEin == 0))
374
        (MotorenEin == 0))
326
      {
375
      {
327
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
376
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
328
        // auf Nullwerte kalibrieren
377
        // auf Nullwerte kalibrieren
329
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
378
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
330
        if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
379
        if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
331
        {
380
        {
332
          if(++delay_neutral > 50)  // nicht sofort
381
          if(++delay_neutral > 50)  // nicht sofort
333
          {
382
          {
334
            MotorenEin = 0;
383
            MotorenEin = 0;
335
            delay_neutral = 0;
384
            delay_neutral = 0;
336
            modell_fliegt = 0;
385
            modell_fliegt = 0;
337
            if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
386
            if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
338
            {
387
            {
339
              if((AdWertAirPressure_Raw > 950) || (AdWertAirPressure_Raw < 750))
388
              if((AdWertAirPressure_Raw > 950) || (AdWertAirPressure_Raw < 750))
340
              {
389
              {
341
                SucheLuftruckOffset();
390
                SucheLuftruckOffset();
342
              }
391
              }
343
            }  
392
            }  
344
            ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
393
            ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
345
            SetNeutral();
394
            SetNeutral();
346
          }
395
          }
347
        }
396
        }
348
        else
397
        else
349
        {
398
        {
350
          delay_neutral = 0;
399
          delay_neutral = 0;
351
        }
400
        }
352
      }
401
      }
353
      // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
402
      // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
354
      // Gas ist unten
403
      // Gas ist unten
355
      // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
404
      // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
356
      if(GasMischanteil < 35)
405
      if(GasMischanteil < 35)
357
      {
406
      {
358
        // Starten
407
        // Starten
359
        if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
408
        if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
360
        {
409
        {
361
          // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
410
          // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
362
          // Einschalten
411
          // Einschalten
363
          // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
412
          // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
364
          if(++delay_einschalten > 100)
413
          if(++delay_einschalten > 100)
365
          {
414
          {
366
            MotorenEin = 1;
415
            MotorenEin = 1;
367
            modell_fliegt = 1;
416
            modell_fliegt = 1;
368
            delay_einschalten = 100;
417
            delay_einschalten = 100;
369
          }          
418
          }          
370
        }  
419
        }  
371
        else
420
        else
372
        {
421
        {
373
          delay_einschalten = 0;
422
          delay_einschalten = 0;
374
        }
423
        }
375
        //Auf Neutralwerte setzen
424
        //Auf Neutralwerte setzen
376
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
425
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
377
        // Auschalten
426
        // Auschalten
378
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
427
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
379
        if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
428
        if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
380
        {
429
        {
381
          if(++delay_ausschalten > 50)  // nicht sofort
430
          if(++delay_ausschalten > 50)  // nicht sofort
382
          {
431
          {
383
            MotorenEin = 0;
432
            MotorenEin = 0;
384
            modell_fliegt = 0;
433
            modell_fliegt = 0;
385
            delay_ausschalten = 50;
434
            delay_ausschalten = 50;
386
          }
435
          }
387
        }
436
        }
388
        else
437
        else
389
        {
438
        {
390
          delay_ausschalten = 0;
439
          delay_ausschalten = 0;
391
        }
440
        }
392
      }
441
      }
393
    }
442
    }
394
  }
443
  }
395
}
444
}
396
 
445
 
397
 
446
 
398
 
447
 
399
 
448
 
400
/* ****************************************************************************
449
/* ****************************************************************************
401
Functionname:     PD_Regler                      */ /*!
450
Functionname:     PD_Regler                      */ /*!
402
Description:
451
Description:
403
 
452
 
404
  @return           void
453
  @return           void
405
  @pre              -
454
  @pre              -
406
  @post             -
455
  @post             -
407
  @author           Michael Walter
456
  @author           Michael Walter
408
**************************************************************************** */
457
**************************************************************************** */
409
void PD_Regler(void)
458
void PD_Regler(void)
410
{
459
{
411
  int StickNick45,StickRoll45;
460
  int StickNick45,StickRoll45;
412
  int DiffNick,DiffRoll, DiffGier;    
461
  int DiffNick,DiffRoll, DiffGier;    
413
  int motorwert = 0;
462
  int motorwert = 0;
414
  int pd_ergebnis;
463
  int pd_ergebnis;
415
 
464
 
416
  /*****************************************************************************
465
  /*****************************************************************************
417
  Update noimial attitude
466
  Update noimial attitude
418
  **************************************************************************** */
467
  **************************************************************************** */
419
  if(!NewPpmData--)  
468
  if(!NewPpmData--)  
420
  {
469
  {
421
    StickNick = (StickNick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4;
470
    StickNick = (StickNick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4;
422
    StickRoll = (StickRoll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
471
    StickRoll = (StickRoll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
423
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
472
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
424
  } // Ende neue Funken-Werte
473
  } // Ende neue Funken-Werte
425
 
474
 
426
#ifdef USE_GPS
475
#ifdef USE_GPS
427
 /* G P S   U p d a t e */
476
 /* G P S   U p d a t e */
428
  GPSupdate();
477
  GPSupdate();
429
#endif
478
#endif
430
 
479
 
431
  static float AverageGasMischanteil = 50.F;
480
  static float AverageGasMischanteil = 50.F;
432
  if((GasMischanteil > 30) &&
481
  if((GasMischanteil > 30) &&
433
    (MotorenEin == 1) &&
482
    (MotorenEin == 1) &&
434
    (RemoteLinkLost == 0) )
483
    (RemoteLinkLost == 0) )
435
  {  /* Average the average throttle to find the hover setting */
484
  {  /* Average the average throttle to find the hover setting */
436
    AverageGasMischanteil = 0.999F * AverageGasMischanteil + 0.001F * GasMischanteil;
485
    AverageGasMischanteil = 0.999F * AverageGasMischanteil + 0.001F * GasMischanteil;
437
  }
486
  }
438
  /* Overide GasMischanteil */
487
  /* Overide GasMischanteil */
439
  static unsigned int DescentCnt = 32000;
488
  static unsigned int DescentCnt = 32000;
440
  if ((RemoteLinkLost == 1) &&
489
  if ((RemoteLinkLost == 1) &&
441
    (MotorenEin == 1))
490
    (MotorenEin == 1))
442
  {
491
  {
443
    if ((UBat < 100) || /* Start to descent in case of low loltage or in case*/
492
    if ((UBat < 100) || /* Start to descent in case of low loltage or in case*/
444
    (maxDistance / 10 < 12)) /* we reached our target position */
493
    (maxDistance / 10 < 12)) /* we reached our target position */
445
    {
494
    {
446
      if (DescentCnt > 0)
495
      if (DescentCnt > 0)
447
      {
496
      {
448
        DescentCnt--;
497
        DescentCnt--;
449
      }
498
      }
450
      else
499
      else
451
      {  /* We reached our target (hopefully) */
500
      {  /* We reached our target (hopefully) */
452
        MotorenEin = 0;
501
        MotorenEin = 0;
453
        RemoteLinkLost = 0;
502
        RemoteLinkLost = 0;
454
      }
503
      }
455
    }
504
    }
456
    else
505
    else
457
    {
506
    {
458
      DescentCnt = 32000;
507
      DescentCnt = 32000;
459
    }
508
    }
460
    /* Bias the throttle for a slow descent */
509
    /* Bias the throttle for a slow descent */
461
    GasMischanteil = (int) ((AverageGasMischanteil + 5.0F) * (DescentCnt / 32000.F));
510
    GasMischanteil = (int) ((AverageGasMischanteil + 5.0F) * (DescentCnt / 32000.F));
462
  }
511
  }
463
  else
512
  else
464
  {
513
  {
465
    DescentCnt = 32000;
514
    DescentCnt = 32000;
466
  }
515
  }
467
 
516
 
468
  //DebugOut.Analog[13] = (int) GasMischanteil;
517
  //DebugOut.Analog[13] = (int) GasMischanteil;
469
 
518
 
470
#ifdef X_FORMATION
519
#ifdef X_FORMATION
471
  /* Overide in case the remote link got lost */
520
  /* Overide in case the remote link got lost */
472
  if (RemoteLinkLost == 0)
521
  if (RemoteLinkLost == 0)
473
  { /* We are flying in X-Formation */
522
  { /* We are flying in X-Formation */
474
    StickRoll45 = (int) (0.707F *  (float)(StickRoll - GPS_Roll) - 0.707F * (float)(StickNick - GPS_Nick));
523
    StickRoll45 = (int) (0.707F *  (float)(StickRoll - GPS_Roll) - 0.707F * (float)(StickNick - GPS_Nick));
475
    StickNick45 = (int) (0.707F *  (float)(StickRoll - GPS_Roll) + 0.707F * (float)(StickNick - GPS_Nick));
524
    StickNick45 = (int) (0.707F *  (float)(StickRoll - GPS_Roll) + 0.707F * (float)(StickNick - GPS_Nick));
476
  }
525
  }
477
  else
526
  else
478
  {  /* GPS overide is aktive */
527
  {  /* GPS overide is aktive */
479
    StickRoll45 = (int) (0.707F *  (float)(-GPS_Roll) - 0.707F * (float)(-GPS_Nick));
528
    StickRoll45 = (int) (0.707F *  (float)(-GPS_Roll) - 0.707F * (float)(-GPS_Nick));
480
    StickNick45 = (int) (0.707F *  (float)(-GPS_Roll) + 0.707F * (float)(-GPS_Nick));
529
    StickNick45 = (int) (0.707F *  (float)(-GPS_Roll) + 0.707F * (float)(-GPS_Nick));
481
    StickGier = 0;
530
    StickGier = 0;
482
  }
531
  }
483
#else
532
#else
484
  /* Overide in case the remote link got lost */
533
  /* Overide in case the remote link got lost */
485
  if (RemoteLinkLost == 0)
534
  if (RemoteLinkLost == 0)
486
  { /* We are flying in X-Formation */
535
  { /* We are flying in X-Formation */
487
    StickRoll45 = StickRoll - GPS_Roll;
536
    StickRoll45 = StickRoll - GPS_Roll;
488
    StickNick45 = StickNick - GPS_Nick;
537
    StickNick45 = StickNick - GPS_Nick;
489
  }
538
  }
490
  else
539
  else
491
  {  /* GPS overide is aktive */
540
  {  /* GPS overide is aktive */
492
    StickRoll45 = -GPS_Roll;
541
    StickRoll45 = -GPS_Roll;
493
    StickNick45 = -GPS_Nick;
542
    StickNick45 = -GPS_Nick;
494
    StickGier = 0;
543
    StickGier = 0;
495
  }
544
  }
496
#endif
545
#endif
497
 
546
 
498
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
547
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
499
  //  Yaw
548
  //  Yaw
500
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
549
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
501
 
550
 
502
  if(GasMischanteil < 20)
551
  if(GasMischanteil < 20)
503
  {
552
  {
504
    sollGier = status.iPsi10;
553
    sollGier = status.iPsi10;
505
    SummeRoll = 0;
554
    SummeRoll = 0;
506
    SummeNick = 0;
555
    SummeNick = 0;
507
  }
556
  }
508
 
557
 
509
  /* Gier-Anteil */
558
  /* Gier-Anteil */
510
  if (abs(StickGier) > 4)
559
  if (abs(StickGier) > 4)
511
  {
560
  {
512
    sollGier = status.iPsi10 + 4 * StickGier;  
561
    sollGier = status.iPsi10 + 4 * StickGier;  
513
  }
562
  }
514
  DiffGier = (sollGier - status.iPsi10);
563
  DiffGier = (sollGier - status.iPsi10);
515
  GierMischanteil = (int) (-4 *  DiffGier - 4* (AdWertGier_Raw - (int) AdNeutralGier)) / 10;
564
  GierMischanteil = (int) (-4 *  DiffGier - 4* (AdWertGier_Raw - (int) AdNeutralGier)) / 10;
516
 
565
 
517
#define MUL_G  0.8
566
#define MUL_G  0.8
518
  if(GierMischanteil > MUL_G * GasMischanteil)
567
  if(GierMischanteil > MUL_G * GasMischanteil)
519
  {
568
  {
520
    GierMischanteil = MUL_G * GasMischanteil;
569
    GierMischanteil = MUL_G * GasMischanteil;
521
  }
570
  }
522
  if(GierMischanteil < -MUL_G * GasMischanteil)
571
  if(GierMischanteil < -MUL_G * GasMischanteil)
523
  {
572
  {
524
    GierMischanteil = -MUL_G * GasMischanteil;
573
    GierMischanteil = -MUL_G * GasMischanteil;
525
  }
574
  }
526
  if(GierMischanteil > 50)
575
  if(GierMischanteil > 50)
527
  {
576
  {
528
    GierMischanteil = 50;
577
    GierMischanteil = 50;
529
  }
578
  }
530
  if(GierMischanteil < -50)
579
  if(GierMischanteil < -50)
531
  {
580
  {
532
    GierMischanteil = -50;
581
    GierMischanteil = -50;
533
  }
582
  }
534
 
583
 
535
  /*****************************************************************************
584
  /*****************************************************************************
536
  PD-Control
585
  PD-Control
537
  **************************************************************************** */
586
  **************************************************************************** */
538
  int scale_p;
587
  int scale_p;
539
  int scale_d;
588
  int scale_d;
540
 
589
 
541
  scale_p = (MAX(0, (PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 170)) / 20);
590
  scale_p = (MAX(0, (PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 170)) / 20);
542
  scale_d = (MAX(0, (PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 170)) / 20);  
591
  scale_d = (MAX(0, (PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 170)) / 20);  
543
 
592
 
544
  scale_p = 6;
593
  scale_p = 6;
545
  scale_d = 7;
594
  scale_d = 7;
546
 
595
 
547
  //DebugOut.Analog[14] =  scale_p;
596
  //DebugOut.Analog[14] =  scale_p;
548
  //DebugOut.Analog[15] =  scale_d;
597
  //DebugOut.Analog[15] =  scale_d;
549
 
598
 
550
  /* Pitch */
599
  /* Pitch */
551
  DiffNick = -(status.iTheta10 + StickNick45);
600
  DiffNick = -(status.iTheta10 + StickNick45);
552
  /* R o l l */
601
  /* R o l l */
553
  DiffRoll = -(status.iPhi10 + StickRoll45);
602
  DiffRoll = -(status.iPhi10 + StickRoll45);
554
 
603
 
555
  SummeNick += DiffNick;
604
  SummeNick += DiffNick;
556
  if(SummeNick >  10000)
605
  if(SummeNick >  10000)
557
  {
606
  {
558
    SummeNick =  10000;
607
    SummeNick =  10000;
559
  }
608
  }
560
  if(SummeNick < -10000)
609
  if(SummeNick < -10000)
561
  {
610
  {
562
    SummeNick = -10000;
611
    SummeNick = -10000;
563
  }
612
  }
564
 
613
 
565
  SummeRoll += DiffRoll;  
614
  SummeRoll += DiffRoll;  
566
  if(SummeRoll >  10000)
615
  if(SummeRoll >  10000)
567
  {
616
  {
568
    SummeRoll =  10000;
617
    SummeRoll =  10000;
569
  }
618
  }
570
  if(SummeRoll < -10000)
619
  if(SummeRoll < -10000)
571
  {
620
  {
572
    SummeRoll = -10000;
621
    SummeRoll = -10000;
573
  }
622
  }
574
 
623
 
575
  pd_ergebnis = ((scale_p *DiffNick + scale_d * (AdWertNick_Raw - (int) AdNeutralNick)) / 10) ; // + (int)(SummeNick / 2000); 
624
  pd_ergebnis = ((scale_p *DiffNick + scale_d * (AdWertNick_Raw - (int) AdNeutralNick)) / 10) ; // + (int)(SummeNick / 2000); 
576
  if(pd_ergebnis >  (GasMischanteil + abs(GierMischanteil)))
625
  if(pd_ergebnis >  (GasMischanteil + abs(GierMischanteil)))
577
  {
626
  {
578
    pd_ergebnis =  (GasMischanteil + abs(GierMischanteil));
627
    pd_ergebnis =  (GasMischanteil + abs(GierMischanteil));
579
  }
628
  }
580
  if(pd_ergebnis < -(GasMischanteil + abs(GierMischanteil)))
629
  if(pd_ergebnis < -(GasMischanteil + abs(GierMischanteil)))
581
  {
630
  {
582
    pd_ergebnis = -(GasMischanteil + abs(GierMischanteil));
631
    pd_ergebnis = -(GasMischanteil + abs(GierMischanteil));
583
  }
632
  }
584
 
633
 
585
  /* M o t o r   V o r n */
634
  /* M o t o r   V o r n */
586
  motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;
635
  motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;
587
  if ((motorwert < 0))
636
  if ((motorwert < 0))
588
  {
637
  {
589
    motorwert = 0;
638
    motorwert = 0;
590
  }
639
  }
591
  else if(motorwert > MAX_GAS)
640
  else if(motorwert > MAX_GAS)
592
  {
641
  {
593
    motorwert = MAX_GAS;
642
    motorwert = MAX_GAS;
594
  }
643
  }
595
  if (motorwert < MIN_GAS)
644
  if (motorwert < MIN_GAS)
596
  {
645
  {
597
    motorwert = MIN_GAS;
646
    motorwert = MIN_GAS;
598
  }
647
  }
599
  Motor_Vorne = motorwert;  
648
  Motor_Vorne = motorwert;  
600
 
649
 
601
  /* M o t o r   H e c k */
650
  /* M o t o r   H e c k */
602
  motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
651
  motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
603
  if ((motorwert < 0))
652
  if ((motorwert < 0))
604
  {
653
  {
605
    motorwert = 0;
654
    motorwert = 0;
606
  }
655
  }
607
  else if(motorwert > MAX_GAS)
656
  else if(motorwert > MAX_GAS)
608
  {
657
  {
609
    motorwert = MAX_GAS;
658
    motorwert = MAX_GAS;
610
  }
659
  }
611
  if (motorwert < MIN_GAS)
660
  if (motorwert < MIN_GAS)
612
  {
661
  {
613
    motorwert = MIN_GAS;
662
    motorwert = MIN_GAS;
614
  }
663
  }
615
  Motor_Hinten = motorwert;
664
  Motor_Hinten = motorwert;
616
 
665
 
617
  pd_ergebnis =  ((scale_p * DiffRoll + scale_d * (AdWertRoll_Raw - (int) AdNeutralRoll)) / 10) ; //+ (int)(SummeRoll / 2000);
666
  pd_ergebnis =  ((scale_p * DiffRoll + scale_d * (AdWertRoll_Raw - (int) AdNeutralRoll)) / 10) ; //+ (int)(SummeRoll / 2000);
618
  if(pd_ergebnis >  (GasMischanteil + abs(GierMischanteil)))
667
  if(pd_ergebnis >  (GasMischanteil + abs(GierMischanteil)))
619
  {
668
  {
620
    pd_ergebnis =  (GasMischanteil + abs(GierMischanteil));
669
    pd_ergebnis =  (GasMischanteil + abs(GierMischanteil));
621
  }
670
  }
622
  if(pd_ergebnis < -(GasMischanteil + abs(GierMischanteil)))
671
  if(pd_ergebnis < -(GasMischanteil + abs(GierMischanteil)))
623
  {
672
  {
624
    pd_ergebnis = -(GasMischanteil + abs(GierMischanteil));
673
    pd_ergebnis = -(GasMischanteil + abs(GierMischanteil));
625
  }
674
  }
626
 
675
 
627
  /* M o t o r   L i n k s */
676
  /* M o t o r   L i n k s */
628
  motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
677
  motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
629
  if(motorwert > MAX_GAS)
678
  if(motorwert > MAX_GAS)
630
  {
679
  {
631
    motorwert = MAX_GAS;
680
    motorwert = MAX_GAS;
632
  }
681
  }
633
  if (motorwert < MIN_GAS)
682
  if (motorwert < MIN_GAS)
634
  {
683
  {
635
    motorwert = MIN_GAS;
684
    motorwert = MIN_GAS;
636
  }
685
  }
637
  Motor_Links = motorwert;
686
  Motor_Links = motorwert;
638
 
687
 
639
  /* M o t o r   R e c h t s */
688
  /* M o t o r   R e c h t s */
640
  motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
689
  motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
641
  if(motorwert > MAX_GAS)
690
  if(motorwert > MAX_GAS)
642
  {
691
  {
643
    motorwert = MAX_GAS;
692
    motorwert = MAX_GAS;
644
  }
693
  }
645
  if (motorwert < MIN_GAS)
694
  if (motorwert < MIN_GAS)
646
  {
695
  {
647
    motorwert = MIN_GAS;
696
    motorwert = MIN_GAS;
648
  }
697
  }
649
  Motor_Rechts = motorwert;
698
  Motor_Rechts = motorwert;
650
 
699
 
651
#if 1
700
#if 1
652
  DebugOut.Analog[0] = status.iTheta10;
701
  DebugOut.Analog[0] = status.iTheta10;
653
  DebugOut.Analog[1] = status.iPhi10;
702
  DebugOut.Analog[1] = status.iPhi10;
654
  DebugOut.Analog[2] = status.iPsi10 / 10;
703
  DebugOut.Analog[2] = status.iPsi10 / 10;
655
#endif
704
#endif
656
}
705
}
657
 
706