Subversion Repositories FlightCtrl

Rev

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

Rev 983 Rev 987
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
 
-
 
-
 
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
 
-
 
139
  InvalidAttitude = 0;
138
  beeptime = 2000;
140
  beeptime = 2000;
139
}
141
}
140
 
142
 
141
 
143
 
142
/* ****************************************************************************
144
/* ****************************************************************************
143
Functionname:    GetMeasurements                      */ /*!
145
Functionname:    GetMeasurements                      */ /*!
144
Description:    CalculateAverage
146
Description:    CalculateAverage
145
 
147
 
146
@param[in]        
148
@param[in]        
147
 
149
 
148
  @return           void
150
  @return           void
149
  @pre              -
151
  @pre              -
150
  @post             -
152
  @post             -
151
  @author         Michael Walter  
153
  @author         Michael Walter  
152
**************************************************************************** */
154
**************************************************************************** */
153
void GetMeasurements(void)
155
void GetMeasurements(void)
154
{
156
{
155
  ANALOG_OFF;
157
  ANALOG_OFF;
156
  AverageRoll = AccumulatedRoll / AccumulatedRoll_cnt;
158
  AverageRoll = AccumulatedRoll / AccumulatedRoll_cnt;
157
  AverageNick = AccumulatedNick / AccumulatedNick_cnt;
159
  AverageNick = AccumulatedNick / AccumulatedNick_cnt;
158
  AverageGier = AccumulatedGier / AccumulatedGier_cnt;
160
  AverageGier = AccumulatedGier / AccumulatedGier_cnt;
159
 
161
 
160
  /* Get Pressure Differenz */
162
  /* Get Pressure Differenz */
161
  CurrentAltitude = InitialAltitude - AccumulatedAirPressure / AccumulatedAirPressure_cnt;
163
  CurrentAltitude = InitialAltitude - AccumulatedAirPressure / AccumulatedAirPressure_cnt;
162
  AccumulatedAirPressure_cnt = 0;
164
  AccumulatedAirPressure_cnt = 0;
163
  AccumulatedAirPressure = 0;
165
  AccumulatedAirPressure = 0;
164
 
166
 
165
  static char AirPressureCnt = 0;
167
  static char AirPressureCnt = 0;
166
  if (AirPressureCnt % 25 == 1)
168
  if (AirPressureCnt % 25 == 1)
167
  {
169
  {
168
    DeltaAltitude = CurrentAltitude - LastAltitude;
170
    DeltaAltitude = CurrentAltitude - LastAltitude;
169
    LastAltitude = CurrentAltitude;
171
    LastAltitude = CurrentAltitude;
170
  }
172
  }
171
  AirPressureCnt++;
173
  AirPressureCnt++;
172
 
174
 
173
  if(modell_fliegt < 0x250)
175
  if(modell_fliegt < 0x250)
174
  {
176
  {
175
    //if ((GPS_Roll == 0 && GPS_Nick == 0) || (maxDistance / 10 > 10))
177
    //if ((GPS_Roll == 0 && GPS_Nick == 0) || (maxDistance / 10 > 10))
176
    AdNeutralNick = 0.998F * AdNeutralNick + 0.002F * AdWertNick_Raw;
178
    AdNeutralNick = 0.998F * AdNeutralNick + 0.002F * AdWertNick_Raw;
177
    AdNeutralRoll = 0.998F * AdNeutralRoll + 0.002F * AdWertRoll_Raw;
179
    AdNeutralRoll = 0.998F * AdNeutralRoll + 0.002F * AdWertRoll_Raw;
178
    if (abs(StickGier) < 15 || MotorenEin == 0)
180
    if (abs(StickGier) < 15 || MotorenEin == 0)
179
    {
181
    {
180
      AdNeutralGier = 0.998F * AdNeutralGier + 0.002F * AdWertGier_Raw;
182
      AdNeutralGier = 0.998F * AdNeutralGier + 0.002F * AdWertGier_Raw;
181
    }
183
    }
182
  }
184
  }
183
  else if(modell_fliegt < 0x2000)
185
  else if(modell_fliegt < 0x2000)
184
  {
186
  {
185
    //if ((GPS_Roll == 0 && GPS_Nick == 0) || (maxDistance / 10 > 10))
187
    //if ((GPS_Roll == 0 && GPS_Nick == 0) || (maxDistance / 10 > 10))
186
    AdNeutralNick = 0.999F * AdNeutralNick + 0.001F * AdWertNick_Raw;
188
    AdNeutralNick = 0.999F * AdNeutralNick + 0.001F * AdWertNick_Raw;
187
    AdNeutralRoll = 0.999F * AdNeutralRoll + 0.001F * AdWertRoll_Raw;
189
    AdNeutralRoll = 0.999F * AdNeutralRoll + 0.001F * AdWertRoll_Raw;
188
    if (abs(StickGier) < 15 || MotorenEin == 0)
190
    if (abs(StickGier) < 15 || MotorenEin == 0)
189
    {
191
    {
190
      AdNeutralGier = 0.999F * AdNeutralGier + 0.001F * AdWertGier_Raw;
192
      AdNeutralGier = 0.999F * AdNeutralGier + 0.001F * AdWertGier_Raw;
191
    }
193
    }
192
  }
194
  }
193
  else
195
  else
194
  {
196
  {
195
    AdNeutralNick = 0.9995F * AdNeutralNick + 0.0005F * AdWertNick_Raw;
197
    AdNeutralNick = 0.9995F * AdNeutralNick + 0.0005F * AdWertNick_Raw;
196
    AdNeutralRoll = 0.9995F * AdNeutralRoll + 0.0005F * AdWertRoll_Raw;
198
    AdNeutralRoll = 0.9995F * AdNeutralRoll + 0.0005F * AdWertRoll_Raw;
197
    if (abs(StickGier) < 15 || MotorenEin == 0)
199
    if (abs(StickGier) < 15 || MotorenEin == 0)
198
    {
200
    {
199
      AdNeutralGier = 0.9995F * AdNeutralGier + 0.0005F * AdWertGier_Raw;
201
      AdNeutralGier = 0.9995F * AdNeutralGier + 0.0005F * AdWertGier_Raw;
200
    }
202
    }
201
  }
203
  }
202
 
204
 
203
#if 1
205
#if 1
204
  DebugOut.Analog[6] = AdWertNick_Raw;
206
  DebugOut.Analog[6] = AdWertNick_Raw;
205
  DebugOut.Analog[7] = AdWertRoll_Raw;
207
  DebugOut.Analog[7] = AdWertRoll_Raw;
206
  DebugOut.Analog[8] = AdWertGier_Raw;
208
  DebugOut.Analog[8] = AdWertGier_Raw;
207
 
209
 
208
  DebugOut.Analog[9] = AdNeutralNick;
210
  DebugOut.Analog[9] = AdNeutralNick;
209
  DebugOut.Analog[10] = AdNeutralRoll;
211
  DebugOut.Analog[10] = AdNeutralRoll;
210
  DebugOut.Analog[11] = AdNeutralGier;
212
  DebugOut.Analog[11] = AdNeutralGier;
211
#endif
213
#endif
212
 
214
 
213
  AccumulatedRoll = 0;
215
  AccumulatedRoll = 0;
214
  AccumulatedRoll_cnt = 0;
216
  AccumulatedRoll_cnt = 0;
215
  AccumulatedNick = 0;
217
  AccumulatedNick = 0;
216
  AccumulatedNick_cnt = 0;
218
  AccumulatedNick_cnt = 0;
217
  AccumulatedGier = 0;
219
  AccumulatedGier = 0;
218
  AccumulatedGier_cnt = 0;
220
  AccumulatedGier_cnt = 0;
219
 
221
 
220
#if 0
222
#if 0
221
  ACC_X_Offset = 0.9999F * ACC_X_Offset + 0.0001F * ((float) AccumulatedACC_X / (float) AccumulatedACC_X_cnt);
223
  ACC_X_Offset = 0.9999F * ACC_X_Offset + 0.0001F * ((float) AccumulatedACC_X / (float) AccumulatedACC_X_cnt);
222
  ACC_Y_Offset = 0.9999F * ACC_Y_Offset + 0.0001F * ((float) AccumulatedACC_Y / (float) AccumulatedACC_Y_cnt);
224
  ACC_Y_Offset = 0.9999F * ACC_Y_Offset + 0.0001F * ((float) AccumulatedACC_Y / (float) AccumulatedACC_Y_cnt);
223
  ACC_Z_Offset = 0.9999F * ACC_Z_Offset + 0.0001F * ((float) AccumulatedACC_Z / (float) AccumulatedACC_Z_cnt);
225
  ACC_Z_Offset = 0.9999F * ACC_Z_Offset + 0.0001F * ((float) AccumulatedACC_Z / (float) AccumulatedACC_Z_cnt);
224
#endif
226
#endif
225
 
227
 
226
  AveragerACC_X =  AccumulatedACC_X / AccumulatedACC_X_cnt;
228
  AveragerACC_X =  AccumulatedACC_X / AccumulatedACC_X_cnt;
227
  AveragerACC_Y =  AccumulatedACC_Y / AccumulatedACC_Y_cnt;
229
  AveragerACC_Y =  AccumulatedACC_Y / AccumulatedACC_Y_cnt;
228
  AveragerACC_Z =  AccumulatedACC_Z / AccumulatedACC_Z_cnt;
230
  AveragerACC_Z =  AccumulatedACC_Z / AccumulatedACC_Z_cnt;
229
 
231
 
230
  AccumulatedACC_X = 0;
232
  AccumulatedACC_X = 0;
231
  AccumulatedACC_X_cnt = 0;
233
  AccumulatedACC_X_cnt = 0;
232
  AccumulatedACC_Y = 0;
234
  AccumulatedACC_Y = 0;
233
  AccumulatedACC_Y_cnt = 0;
235
  AccumulatedACC_Y_cnt = 0;
234
  AccumulatedACC_Z = 0;
236
  AccumulatedACC_Z = 0;
235
  AccumulatedACC_Z_cnt = 0;
237
  AccumulatedACC_Z_cnt = 0;
236
 
238
 
237
  ANALOG_ON;
239
  ANALOG_ON;
238
}
240
}
239
 
241
 
240
/* ****************************************************************************
242
/* ****************************************************************************
241
Functionname:     SendMotorData                      */ /*!
243
Functionname:     SendMotorData                      */ /*!
242
Description:          Senden der Motorwerte per I2C-Bus
244
Description:          Senden der Motorwerte per I2C-Bus
243
 
245
 
244
  @return           void
246
  @return           void
245
  @pre              -
247
  @pre              -
246
  @post             -
248
  @post             -
247
  @author           H. Buss / I. Busker
249
  @author           H. Buss / I. Busker
248
**************************************************************************** */
250
**************************************************************************** */
249
void SendMotorData(void)
251
void SendMotorData(void)
250
{
252
{
251
  if(!MotorenEin)
253
  if(!MotorenEin)
252
  {
254
  {
253
    Motor_Hinten = 0;
255
    Motor_Hinten = 0;
254
    Motor_Vorne = 0;
256
    Motor_Vorne = 0;
255
    Motor_Rechts = 0;
257
    Motor_Rechts = 0;
256
    Motor_Links = 0;
258
    Motor_Links = 0;
257
    if(MotorTest[0]) Motor_Vorne = MotorTest[0];
259
    if(MotorTest[0]) Motor_Vorne = MotorTest[0];
258
    if(MotorTest[1]) Motor_Hinten = MotorTest[1];
260
    if(MotorTest[1]) Motor_Hinten = MotorTest[1];
259
    if(MotorTest[2]) Motor_Links = MotorTest[2];
261
    if(MotorTest[2]) Motor_Links = MotorTest[2];
260
    if(MotorTest[3]) Motor_Rechts = MotorTest[3];
262
    if(MotorTest[3]) Motor_Rechts = MotorTest[3];
261
  }
263
  }
262
 
264
 
263
  //Start I2C Interrupt Mode
265
  //Start I2C Interrupt Mode
264
  twi_state = 0;
266
  twi_state = 0;
265
  motor = 0;
267
  motor = 0;
266
  i2c_start();
268
  i2c_start();
267
}
269
}
268
 
270
 
269
 
271
 
270
/* ****************************************************************************
272
/* ****************************************************************************
271
Functionname:     RemoteControl                      */ /*!
273
Functionname:     RemoteControl                      */ /*!
272
Description:      
274
Description:      
273
 
275
 
274
  @return           void
276
  @return           void
275
  @pre              -
277
  @pre              -
276
  @post             -
278
  @post             -
277
  @author           H. Buss / I. Busker
279
  @author           H. Buss / I. Busker
278
**************************************************************************** */
280
**************************************************************************** */
279
void RemoteControl(void)
281
void RemoteControl(void)
280
{
282
{
281
  static unsigned char delay_neutral = 0;
283
  static unsigned char delay_neutral = 0;
282
  static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
284
  static unsigned char delay_einschalten = 0,delay_ausschalten = 0;
283
 
285
 
284
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
286
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
285
  // Gaswert ermitteln
287
  // Gaswert ermitteln
286
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
288
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
287
  GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
289
  GasMischanteil = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]] + 120;
288
  if(GasMischanteil < 0)
290
  if(GasMischanteil < 0)
289
  {
291
  {
290
    GasMischanteil = 0;
292
    GasMischanteil = 0;
291
  }
293
  }
292
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
294
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
293
  // Emfang schlecht
295
  // Emfang schlecht
294
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
296
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
295
  if(SenderOkay < 100)
297
  if(SenderOkay < 100)
296
  {
298
  {
297
    if(!PcZugriff)
299
    if(!PcZugriff)
298
    {
300
    {
299
      if(BeepMuster == 0xffff)
301
      if(BeepMuster == 0xffff)
300
      {
302
      {
301
        beeptime = 15000;
303
        beeptime = 15000;
302
        BeepMuster = 0x0c00;
304
        BeepMuster = 0x0c00;
303
      }
305
      }
304
    }
306
    }
305
  }
307
  }
306
  else
308
  else
307
  {
309
  {
308
    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
310
    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
309
    // Emfang gut
311
    // Emfang gut
310
    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
312
    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
311
    if(SenderOkay > 140)
313
    if(SenderOkay > 140)
312
    {
314
    {
313
      if(GasMischanteil > 40)
315
      if(GasMischanteil > 40)
314
      {
316
      {
315
        if(modell_fliegt < 0xffff)
317
        if(modell_fliegt < 0xffff)
316
        {
318
        {
317
          modell_fliegt++;
319
          modell_fliegt++;
318
        }
320
        }
319
      }
321
      }
320
     
322
     
321
     
323
     
322
      if((GasMischanteil > 200) &&
324
      if((GasMischanteil > 200) &&
323
        (MotorenEin == 0))
325
        (MotorenEin == 0))
324
      {
326
      {
325
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
327
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
326
        // auf Nullwerte kalibrieren
328
        // auf Nullwerte kalibrieren
327
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
329
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
328
        if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
330
        if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)  // Neutralwerte
329
        {
331
        {
330
          if(++delay_neutral > 50)  // nicht sofort
332
          if(++delay_neutral > 50)  // nicht sofort
331
          {
333
          {
332
            MotorenEin = 0;
334
            MotorenEin = 0;
333
            delay_neutral = 0;
335
            delay_neutral = 0;
334
            modell_fliegt = 0;
336
            modell_fliegt = 0;
335
            if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
337
            if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG))  // Höhenregelung aktiviert?
336
            {
338
            {
337
              if((AdWertAirPressure_Raw > 950) || (AdWertAirPressure_Raw < 750))
339
              if((AdWertAirPressure_Raw > 950) || (AdWertAirPressure_Raw < 750))
338
              {
340
              {
339
                SucheLuftruckOffset();
341
                SucheLuftruckOffset();
340
              }
342
              }
341
            }  
343
            }  
342
            ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
344
            ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
343
            SetNeutral();
345
            SetNeutral();
344
          }
346
          }
345
        }
347
        }
346
        else
348
        else
347
        {
349
        {
348
          delay_neutral = 0;
350
          delay_neutral = 0;
349
        }
351
        }
350
      }
352
      }
351
      // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
353
      // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
352
      // Gas ist unten
354
      // Gas ist unten
353
      // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
355
      // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
354
      if(GasMischanteil < 35)
356
      if(GasMischanteil < 35)
355
      {
357
      {
356
        // Starten
358
        // Starten
357
        if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
359
        if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] < -75)
358
        {
360
        {
359
          // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
361
          // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
360
          // Einschalten
362
          // Einschalten
361
          // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
363
          // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
362
          if(++delay_einschalten > 100)
364
          if(++delay_einschalten > 100)
363
          {
365
          {
364
            MotorenEin = 1;
366
            MotorenEin = 1;
365
            modell_fliegt = 1;
367
            modell_fliegt = 1;
366
            delay_einschalten = 100;
368
            delay_einschalten = 100;
367
          }          
369
          }          
368
        }  
370
        }  
369
        else
371
        else
370
        {
372
        {
371
          delay_einschalten = 0;
373
          delay_einschalten = 0;
372
        }
374
        }
373
        //Auf Neutralwerte setzen
375
        //Auf Neutralwerte setzen
374
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
376
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
375
        // Auschalten
377
        // Auschalten
376
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
378
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
377
        if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
379
        if(PPM_in[EE_Parameter.Kanalbelegung[K_GIER]] > 75)
378
        {
380
        {
379
          if(++delay_ausschalten > 50)  // nicht sofort
381
          if(++delay_ausschalten > 50)  // nicht sofort
380
          {
382
          {
381
            MotorenEin = 0;
383
            MotorenEin = 0;
382
            modell_fliegt = 0;
384
            modell_fliegt = 0;
383
            delay_ausschalten = 50;
385
            delay_ausschalten = 50;
384
          }
386
          }
385
        }
387
        }
386
        else
388
        else
387
        {
389
        {
388
          delay_ausschalten = 0;
390
          delay_ausschalten = 0;
389
        }
391
        }
390
      }
392
      }
391
    }
393
    }
392
  }
394
  }
393
}
395
}
394
 
396
 
395
 
397
 
396
 
398
 
397
 
399
 
398
/* ****************************************************************************
400
/* ****************************************************************************
399
Functionname:     PD_Regler                      */ /*!
401
Functionname:     PD_Regler                      */ /*!
400
Description:
402
Description:
401
 
403
 
402
  @return           void
404
  @return           void
403
  @pre              -
405
  @pre              -
404
  @post             -
406
  @post             -
405
  @author           Michael Walter
407
  @author           Michael Walter
406
**************************************************************************** */
408
**************************************************************************** */
407
void PD_Regler(void)
409
void PD_Regler(void)
408
{
410
{
409
  int StickNick45,StickRoll45;
411
  int StickNick45,StickRoll45;
410
  int DiffNick,DiffRoll, DiffGier;    
412
  int DiffNick,DiffRoll, DiffGier;    
411
  int motorwert = 0;
413
  int motorwert = 0;
412
  int pd_ergebnis;
414
  int pd_ergebnis;
413
 
415
 
414
  /*****************************************************************************
416
  /*****************************************************************************
415
  Update noimial attitude
417
  Update noimial attitude
416
  **************************************************************************** */
418
  **************************************************************************** */
417
  if(!NewPpmData--)  
419
  if(!NewPpmData--)  
418
  {
420
  {
419
    StickNick = (StickNick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4;
421
    StickNick = (StickNick * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] * EE_Parameter.Stick_P) / 4;
420
    StickRoll = (StickRoll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
422
    StickRoll = (StickRoll * 3 + PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]] * EE_Parameter.Stick_P) / 4;
421
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
423
    StickGier = -PPM_in[EE_Parameter.Kanalbelegung[K_GIER]];
422
  } // Ende neue Funken-Werte
424
  } // Ende neue Funken-Werte
423
 
425
 
424
#ifdef USE_GPS
426
#ifdef USE_GPS
425
 /* G P S   U p d a t e */
427
 /* G P S   U p d a t e */
426
  GPSupdate();
428
  GPSupdate();
427
#endif
429
#endif
428
 
430
 
429
  static float AverageGasMischanteil = 50.F;
431
  static float AverageGasMischanteil = 50.F;
430
  if((GasMischanteil > 30) &&
432
  if((GasMischanteil > 30) &&
431
    (MotorenEin == 1) &&
433
    (MotorenEin == 1) &&
432
    (RemoteLinkLost == 0) )
434
    (RemoteLinkLost == 0) )
433
  {  /* Average the average throttle to find the hover setting */
435
  {  /* Average the average throttle to find the hover setting */
434
    AverageGasMischanteil = 0.999F * AverageGasMischanteil + 0.001F * GasMischanteil;
436
    AverageGasMischanteil = 0.999F * AverageGasMischanteil + 0.001F * GasMischanteil;
435
  }
437
  }
436
  /* Overide GasMischanteil */
438
  /* Overide GasMischanteil */
437
  static unsigned int DescentCnt = 32000;
439
  static unsigned int DescentCnt = 32000;
438
  if ((RemoteLinkLost == 1) &&
440
  if ((RemoteLinkLost == 1) &&
439
    (MotorenEin == 1))
441
    (MotorenEin == 1))
440
  {
442
  {
441
    if ((UBat < 100) || /* Start to descent in case of low loltage or in case*/
443
    if ((UBat < 100) || /* Start to descent in case of low loltage or in case*/
442
    (maxDistance / 10 < 12)) /* we reached our target position */
444
    (maxDistance / 10 < 12)) /* we reached our target position */
443
    {
445
    {
444
      if (DescentCnt > 0)
446
      if (DescentCnt > 0)
445
      {
447
      {
446
        DescentCnt--;
448
        DescentCnt--;
447
      }
449
      }
448
      else
450
      else
449
      {  /* We reached our target (hopefully) */
451
      {  /* We reached our target (hopefully) */
450
        MotorenEin = 0;
452
        MotorenEin = 0;
451
        RemoteLinkLost = 0;
453
        RemoteLinkLost = 0;
452
      }
454
      }
453
    }
455
    }
454
    else
456
    else
455
    {
457
    {
456
      DescentCnt = 32000;
458
      DescentCnt = 32000;
457
    }
459
    }
458
    /* Bias the throttle for a slow descent */
460
    /* Bias the throttle for a slow descent */
459
    GasMischanteil = (int) ((AverageGasMischanteil + 5.0F) * (DescentCnt / 32000.F));
461
    GasMischanteil = (int) ((AverageGasMischanteil + 5.0F) * (DescentCnt / 32000.F));
460
  }
462
  }
461
  else
463
  else
462
  {
464
  {
463
    DescentCnt = 32000;
465
    DescentCnt = 32000;
464
  }
466
  }
465
 
467
 
466
  //DebugOut.Analog[13] = (int) GasMischanteil;
468
  //DebugOut.Analog[13] = (int) GasMischanteil;
467
 
469
 
468
#ifdef X_FORMATION
470
#ifdef X_FORMATION
469
  /* Overide in case the remote link got lost */
471
  /* Overide in case the remote link got lost */
470
  if (RemoteLinkLost == 0)
472
  if (RemoteLinkLost == 0)
471
  { /* We are flying in X-Formation */
473
  { /* We are flying in X-Formation */
472
    StickRoll45 = (int) (0.707F *  (float)(StickRoll - GPS_Roll) - 0.707F * (float)(StickNick - GPS_Nick));
474
    StickRoll45 = (int) (0.707F *  (float)(StickRoll - GPS_Roll) - 0.707F * (float)(StickNick - GPS_Nick));
473
    StickNick45 = (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));
474
  }
476
  }
475
  else
477
  else
476
  {  /* GPS overide is aktive */
478
  {  /* GPS overide is aktive */
477
    StickRoll45 = (int) (0.707F *  (float)(-GPS_Roll) - 0.707F * (float)(-GPS_Nick));
479
    StickRoll45 = (int) (0.707F *  (float)(-GPS_Roll) - 0.707F * (float)(-GPS_Nick));
478
    StickNick45 = (int) (0.707F *  (float)(-GPS_Roll) + 0.707F * (float)(-GPS_Nick));
480
    StickNick45 = (int) (0.707F *  (float)(-GPS_Roll) + 0.707F * (float)(-GPS_Nick));
479
    StickGier = 0;
481
    StickGier = 0;
480
  }
482
  }
481
#else
483
#else
482
  /* Overide in case the remote link got lost */
484
  /* Overide in case the remote link got lost */
483
  if (RemoteLinkLost == 0)
485
  if (RemoteLinkLost == 0)
484
  { /* We are flying in X-Formation */
486
  { /* We are flying in X-Formation */
485
    StickRoll45 = StickRoll - GPS_Roll;
487
    StickRoll45 = StickRoll - GPS_Roll;
486
    StickNick45 = StickNick - GPS_Nick;
488
    StickNick45 = StickNick - GPS_Nick;
487
  }
489
  }
488
  else
490
  else
489
  {  /* GPS overide is aktive */
491
  {  /* GPS overide is aktive */
490
    StickRoll45 = -GPS_Roll;
492
    StickRoll45 = -GPS_Roll;
491
    StickNick45 = -GPS_Nick;
493
    StickNick45 = -GPS_Nick;
492
    StickGier = 0;
494
    StickGier = 0;
493
  }
495
  }
494
#endif
496
#endif
495
 
497
 
496
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
498
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
497
  //  Yaw
499
  //  Yaw
498
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
500
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
499
 
501
 
500
  if(GasMischanteil < 20)
502
  if(GasMischanteil < 20)
501
  {
503
  {
502
    sollGier = status.iPsi10;
504
    sollGier = status.iPsi10;
503
    SummeRoll = 0;
505
    SummeRoll = 0;
504
    SummeNick = 0;
506
    SummeNick = 0;
505
  }
507
  }
506
 
508
 
507
  /* Gier-Anteil */
509
  /* Gier-Anteil */
508
  if (abs(StickGier) > 4)
510
  if (abs(StickGier) > 4)
509
  {
511
  {
510
    sollGier = status.iPsi10 + 4 * StickGier;  
512
    sollGier = status.iPsi10 + 4 * StickGier;  
511
  }
513
  }
512
  DiffGier = (sollGier - status.iPsi10);
514
  DiffGier = (sollGier - status.iPsi10);
513
  GierMischanteil = (int) (-4 *  DiffGier - 4* (AdWertGier_Raw - (int) AdNeutralGier)) / 10;
515
  GierMischanteil = (int) (-4 *  DiffGier - 4* (AdWertGier_Raw - (int) AdNeutralGier)) / 10;
514
 
516
 
515
#define MUL_G  0.8
517
#define MUL_G  0.8
516
  if(GierMischanteil > MUL_G * GasMischanteil)
518
  if(GierMischanteil > MUL_G * GasMischanteil)
517
  {
519
  {
518
    GierMischanteil = MUL_G * GasMischanteil;
520
    GierMischanteil = MUL_G * GasMischanteil;
519
  }
521
  }
520
  if(GierMischanteil < -MUL_G * GasMischanteil)
522
  if(GierMischanteil < -MUL_G * GasMischanteil)
521
  {
523
  {
522
    GierMischanteil = -MUL_G * GasMischanteil;
524
    GierMischanteil = -MUL_G * GasMischanteil;
523
  }
525
  }
524
  if(GierMischanteil > 50)
526
  if(GierMischanteil > 50)
525
  {
527
  {
526
    GierMischanteil = 50;
528
    GierMischanteil = 50;
527
  }
529
  }
528
  if(GierMischanteil < -50)
530
  if(GierMischanteil < -50)
529
  {
531
  {
530
    GierMischanteil = -50;
532
    GierMischanteil = -50;
531
  }
533
  }
532
 
534
 
533
  /*****************************************************************************
535
  /*****************************************************************************
534
  PD-Control
536
  PD-Control
535
  **************************************************************************** */
537
  **************************************************************************** */
536
  int scale_p;
538
  int scale_p;
537
  int scale_d;
539
  int scale_d;
538
 
540
 
539
  scale_p = (MAX(0, (PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 170)) / 20);
541
  scale_p = (MAX(0, (PPM_in[EE_Parameter.Kanalbelegung[K_POTI1]] + 170)) / 20);
540
  scale_d = (MAX(0, (PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 170)) / 20);  
542
  scale_d = (MAX(0, (PPM_in[EE_Parameter.Kanalbelegung[K_POTI2]] + 170)) / 20);  
541
 
543
 
542
  scale_p = 6;
544
  scale_p = 6;
543
  scale_d = 7;
545
  scale_d = 7;
544
 
546
 
545
  //DebugOut.Analog[14] =  scale_p;
547
  //DebugOut.Analog[14] =  scale_p;
546
  //DebugOut.Analog[15] =  scale_d;
548
  //DebugOut.Analog[15] =  scale_d;
547
 
549
 
548
  /* Pitch */
550
  /* Pitch */
549
  DiffNick = -(status.iTheta10 + StickNick45);
551
  DiffNick = -(status.iTheta10 + StickNick45);
550
  /* R o l l */
552
  /* R o l l */
551
  DiffRoll = -(status.iPhi10 + StickRoll45);
553
  DiffRoll = -(status.iPhi10 + StickRoll45);
552
 
554
 
553
  SummeNick += DiffNick;
555
  SummeNick += DiffNick;
554
  if(SummeNick >  10000)
556
  if(SummeNick >  10000)
555
  {
557
  {
556
    SummeNick =  10000;
558
    SummeNick =  10000;
557
  }
559
  }
558
  if(SummeNick < -10000)
560
  if(SummeNick < -10000)
559
  {
561
  {
560
    SummeNick = -10000;
562
    SummeNick = -10000;
561
  }
563
  }
562
 
564
 
563
  SummeRoll += DiffRoll;  
565
  SummeRoll += DiffRoll;  
564
  if(SummeRoll >  10000)
566
  if(SummeRoll >  10000)
565
  {
567
  {
566
    SummeRoll =  10000;
568
    SummeRoll =  10000;
567
  }
569
  }
568
  if(SummeRoll < -10000)
570
  if(SummeRoll < -10000)
569
  {
571
  {
570
    SummeRoll = -10000;
572
    SummeRoll = -10000;
571
  }
573
  }
572
 
574
 
573
  pd_ergebnis = ((scale_p *DiffNick + scale_d * (AdWertNick_Raw - (int) AdNeutralNick)) / 10) ; // + (int)(SummeNick / 2000); 
575
  pd_ergebnis = ((scale_p *DiffNick + scale_d * (AdWertNick_Raw - (int) AdNeutralNick)) / 10) ; // + (int)(SummeNick / 2000); 
574
  if(pd_ergebnis >  (GasMischanteil + abs(GierMischanteil)))
576
  if(pd_ergebnis >  (GasMischanteil + abs(GierMischanteil)))
575
  {
577
  {
576
    pd_ergebnis =  (GasMischanteil + abs(GierMischanteil));
578
    pd_ergebnis =  (GasMischanteil + abs(GierMischanteil));
577
  }
579
  }
578
  if(pd_ergebnis < -(GasMischanteil + abs(GierMischanteil)))
580
  if(pd_ergebnis < -(GasMischanteil + abs(GierMischanteil)))
579
  {
581
  {
580
    pd_ergebnis = -(GasMischanteil + abs(GierMischanteil));
582
    pd_ergebnis = -(GasMischanteil + abs(GierMischanteil));
581
  }
583
  }
582
 
584
 
583
  /* M o t o r   V o r n */
585
  /* M o t o r   V o r n */
584
  motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;
586
  motorwert = GasMischanteil + pd_ergebnis + GierMischanteil;
585
  if ((motorwert < 0))
587
  if ((motorwert < 0))
586
  {
588
  {
587
    motorwert = 0;
589
    motorwert = 0;
588
  }
590
  }
589
  else if(motorwert > MAX_GAS)
591
  else if(motorwert > MAX_GAS)
590
  {
592
  {
591
    motorwert = MAX_GAS;
593
    motorwert = MAX_GAS;
592
  }
594
  }
593
  if (motorwert < MIN_GAS)
595
  if (motorwert < MIN_GAS)
594
  {
596
  {
595
    motorwert = MIN_GAS;
597
    motorwert = MIN_GAS;
596
  }
598
  }
597
  Motor_Vorne = motorwert;  
599
  Motor_Vorne = motorwert;  
598
 
600
 
599
  /* M o t o r   H e c k */
601
  /* M o t o r   H e c k */
600
  motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
602
  motorwert = GasMischanteil - pd_ergebnis + GierMischanteil;
601
  if ((motorwert < 0))
603
  if ((motorwert < 0))
602
  {
604
  {
603
    motorwert = 0;
605
    motorwert = 0;
604
  }
606
  }
605
  else if(motorwert > MAX_GAS)
607
  else if(motorwert > MAX_GAS)
606
  {
608
  {
607
    motorwert = MAX_GAS;
609
    motorwert = MAX_GAS;
608
  }
610
  }
609
  if (motorwert < MIN_GAS)
611
  if (motorwert < MIN_GAS)
610
  {
612
  {
611
    motorwert = MIN_GAS;
613
    motorwert = MIN_GAS;
612
  }
614
  }
613
  Motor_Hinten = motorwert;
615
  Motor_Hinten = motorwert;
614
 
616
 
615
  pd_ergebnis =  ((scale_p * DiffRoll + scale_d * (AdWertRoll_Raw - (int) AdNeutralRoll)) / 10) ; //+ (int)(SummeRoll / 2000);
617
  pd_ergebnis =  ((scale_p * DiffRoll + scale_d * (AdWertRoll_Raw - (int) AdNeutralRoll)) / 10) ; //+ (int)(SummeRoll / 2000);
616
  if(pd_ergebnis >  (GasMischanteil + abs(GierMischanteil)))
618
  if(pd_ergebnis >  (GasMischanteil + abs(GierMischanteil)))
617
  {
619
  {
618
    pd_ergebnis =  (GasMischanteil + abs(GierMischanteil));
620
    pd_ergebnis =  (GasMischanteil + abs(GierMischanteil));
619
  }
621
  }
620
  if(pd_ergebnis < -(GasMischanteil + abs(GierMischanteil)))
622
  if(pd_ergebnis < -(GasMischanteil + abs(GierMischanteil)))
621
  {
623
  {
622
    pd_ergebnis = -(GasMischanteil + abs(GierMischanteil));
624
    pd_ergebnis = -(GasMischanteil + abs(GierMischanteil));
623
  }
625
  }
624
 
626
 
625
  /* M o t o r   L i n k s */
627
  /* M o t o r   L i n k s */
626
  motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
628
  motorwert = GasMischanteil + pd_ergebnis - GierMischanteil;
627
  if(motorwert > MAX_GAS)
629
  if(motorwert > MAX_GAS)
628
  {
630
  {
629
    motorwert = MAX_GAS;
631
    motorwert = MAX_GAS;
630
  }
632
  }
631
  if (motorwert < MIN_GAS)
633
  if (motorwert < MIN_GAS)
632
  {
634
  {
633
    motorwert = MIN_GAS;
635
    motorwert = MIN_GAS;
634
  }
636
  }
635
  Motor_Links = motorwert;
637
  Motor_Links = motorwert;
636
 
638
 
637
  /* M o t o r   R e c h t s */
639
  /* M o t o r   R e c h t s */
638
  motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
640
  motorwert = GasMischanteil - pd_ergebnis - GierMischanteil;
639
  if(motorwert > MAX_GAS)
641
  if(motorwert > MAX_GAS)
640
  {
642
  {
641
    motorwert = MAX_GAS;
643
    motorwert = MAX_GAS;
642
  }
644
  }
643
  if (motorwert < MIN_GAS)
645
  if (motorwert < MIN_GAS)
644
  {
646
  {
645
    motorwert = MIN_GAS;
647
    motorwert = MIN_GAS;
646
  }
648
  }
647
  Motor_Rechts = motorwert;
649
  Motor_Rechts = motorwert;
648
 
650
 
649
#if 1
651
#if 1
650
  DebugOut.Analog[0] = status.iTheta10;
652
  DebugOut.Analog[0] = status.iTheta10;
651
  DebugOut.Analog[1] = status.iPhi10;
653
  DebugOut.Analog[1] = status.iPhi10;
652
  DebugOut.Analog[2] = status.iPsi10 / 10;
654
  DebugOut.Analog[2] = status.iPsi10 / 10;
653
#endif
655
#endif
654
}
656
}
655
 
657