Subversion Repositories FlightCtrl

Rev

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

Rev 2032 Rev 2035
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
// + Copyright (c) 04.2007 Holger Buss
2
// + Copyright (c) 04.2007 Holger Buss
3
// + Nur für den privaten Gebrauch
3
// + Nur für den privaten Gebrauch
4
// + www.MikroKopter.com
4
// + www.MikroKopter.com
5
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
6
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
7
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
7
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
8
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
8
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
9
// + bzgl. der Nutzungsbedingungen aufzunehmen.
9
// + bzgl. der Nutzungsbedingungen aufzunehmen.
10
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
10
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
11
// + Verkauf von Luftbildaufnahmen, usw.
11
// + Verkauf von Luftbildaufnahmen, usw.
12
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
13
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
14
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
14
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
16
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
17
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
17
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
18
// + eindeutig als Ursprung verlinkt werden
18
// + eindeutig als Ursprung verlinkt werden
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
20
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
21
// + Benutzung auf eigene Gefahr
21
// + Benutzung auf eigene Gefahr
22
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
22
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
24
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
25
// + mit unserer Zustimmung zulässig
25
// + mit unserer Zustimmung zulässig
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
27
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
29
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
30
// + this list of conditions and the following disclaimer.
30
// + this list of conditions and the following disclaimer.
31
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
31
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
32
// +     from this software without specific prior written permission.
32
// +     from this software without specific prior written permission.
33
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
33
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
34
// +     for non-commercial use (directly or indirectly)
34
// +     for non-commercial use (directly or indirectly)
35
// +     Commercial use (for example: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
35
// +     Commercial use (for example: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
36
// +     with our written permission
36
// +     with our written permission
37
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
37
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
38
// +     clearly linked as origin
38
// +     clearly linked as origin
39
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
39
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
40
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
40
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
41
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
43
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
44
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
44
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
45
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
45
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
46
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
47
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
48
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49
// +  POSSIBILITY OF SUCH DAMAGE.
49
// +  POSSIBILITY OF SUCH DAMAGE.
50
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
50
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
51
 
51
 
52
#include <stdlib.h>
52
#include <stdlib.h>
53
#include <avr/io.h>
53
#include <avr/io.h>
54
#include "eeprom.h"
54
#include "eeprom.h"
55
#include "flight.h"
55
#include "flight.h"
56
#include "output.h"
56
#include "output.h"
57
 
57
 
58
// Necessary for external control and motor test
58
// Necessary for external control and motor test
59
#include "uart0.h"
59
#include "uart0.h"
60
#include "twimaster.h"
60
#include "twimaster.h"
61
#include "attitude.h"
61
#include "attitude.h"
62
#include "controlMixer.h"
62
#include "controlMixer.h"
63
#include "commands.h"
63
#include "commands.h"
64
#ifdef USE_MK3MAG
64
#ifdef USE_MK3MAG
65
#include "gps.h"
65
#include "gps.h"
66
#endif
66
#endif
67
 
67
 
68
#define CHECK_MIN_MAX(value, min, max) {if(value < min) value = min; else if(value > max) value = max;}
68
#define CHECK_MIN_MAX(value, min, max) {if(value < min) value = min; else if(value > max) value = max;}
69
 
69
 
70
/*
70
/*
71
 * These are no longer maintained, just left at 0. The original implementation just summed the acc.
71
 * These are no longer maintained, just left at 0. The original implementation just summed the acc.
72
 * value to them every 2 ms. No filtering or anything. Just a case for an eventual overflow?? Hey???
72
 * value to them every 2 ms. No filtering or anything. Just a case for an eventual overflow?? Hey???
73
 */
73
 */
74
// int16_t naviAccPitch = 0, naviAccRoll = 0, naviCntAcc = 0;
74
// int16_t naviAccPitch = 0, naviAccRoll = 0, naviCntAcc = 0;
75
 
75
 
76
uint8_t gyroPFactor, gyroIFactor; // the PD factors for the attitude control
76
uint8_t gyroPFactor, gyroIFactor; // the PD factors for the attitude control
77
uint8_t yawPFactor, yawIFactor; // the PD factors for the yaw control
77
uint8_t yawPFactor, yawIFactor; // the PD factors for the yaw control
78
 
78
 
79
// Some integral weight constant...
79
// Some integral weight constant...
80
uint16_t Ki = 10300 / 33;
80
uint16_t Ki = 10300 / 33;
81
 
81
 
82
/************************************************************************/
82
/************************************************************************/
83
/*  Filter for motor value smoothing (necessary???)                     */
83
/*  Filter for motor value smoothing (necessary???)                     */
84
/************************************************************************/
84
/************************************************************************/
85
int16_t motorFilter(int16_t newvalue, int16_t oldvalue) {
85
int16_t motorFilter(int16_t newvalue, int16_t oldvalue) {
86
  switch (staticParams.motorSmoothing) {
86
  switch (staticParams.motorSmoothing) {
87
  case 0:
87
  case 0:
88
    return newvalue;
88
    return newvalue;
89
  case 1:
89
  case 1:
90
    return (oldvalue + newvalue) / 2;
90
    return (oldvalue + newvalue) / 2;
91
  case 2:
91
  case 2:
92
    if (newvalue > oldvalue)
92
    if (newvalue > oldvalue)
93
      return (1 * (int16_t) oldvalue + newvalue) / 2; //mean of old and new
93
      return (1 * (int16_t) oldvalue + newvalue) / 2; //mean of old and new
94
    else
94
    else
95
      return newvalue - (oldvalue - newvalue) * 1; // 2 * new - old
95
      return newvalue - (oldvalue - newvalue) * 1; // 2 * new - old
96
  case 3:
96
  case 3:
97
    if (newvalue < oldvalue)
97
    if (newvalue < oldvalue)
98
      return (1 * (int16_t) oldvalue + newvalue) / 2; //mean of old and new
98
      return (1 * (int16_t) oldvalue + newvalue) / 2; //mean of old and new
99
    else
99
    else
100
      return newvalue - (oldvalue - newvalue) * 1; // 2 * new - old
100
      return newvalue - (oldvalue - newvalue) * 1; // 2 * new - old
101
  default:
101
  default:
102
    return newvalue;
102
    return newvalue;
103
  }
103
  }
104
}
104
}
105
 
105
 
106
/************************************************************************/
106
/************************************************************************/
107
/*  Neutral Readings                                                    */
107
/*  Neutral Readings                                                    */
108
/************************************************************************/
108
/************************************************************************/
109
void flight_setNeutral() {
109
void flight_setNeutral() {
110
  MKFlags |= MKFLAG_CALIBRATE;
110
  MKFlags |= MKFLAG_CALIBRATE;
111
  // not really used here any more.
111
  // not really used here any more.
112
  /*
112
  /*
113
  dynamicParams.KalmanK = -1;
113
  dynamicParams.KalmanK = -1;
114
  dynamicParams.KalmanMaxDrift = 0;
114
  dynamicParams.KalmanMaxDrift = 0;
115
  dynamicParams.KalmanMaxFusion = 32;
115
  dynamicParams.KalmanMaxFusion = 32;
116
  */
116
  */
117
  controlMixer_initVariables();
117
  controlMixer_initVariables();
118
}
118
}
119
 
119
 
120
void setFlightParameters(uint8_t _Ki, uint8_t _gyroPFactor,
120
void setFlightParameters(uint8_t _Ki, uint8_t _gyroPFactor,
121
    uint8_t _gyroIFactor, uint8_t _yawPFactor, uint8_t _yawIFactor) {
121
    uint8_t _gyroIFactor, uint8_t _yawPFactor, uint8_t _yawIFactor) {
122
  Ki = 10300 / _Ki;
122
  Ki = 10300 / _Ki;
123
  gyroPFactor = _gyroPFactor;
123
  gyroPFactor = _gyroPFactor;
124
  gyroIFactor = _gyroIFactor;
124
  gyroIFactor = _gyroIFactor;
125
  yawPFactor = _yawPFactor;
125
  yawPFactor = _yawPFactor;
126
  yawIFactor = _yawIFactor;
126
  yawIFactor = _yawIFactor;
127
}
127
}
128
 
128
 
129
void setNormalFlightParameters(void) {
129
void setNormalFlightParameters(void) {
130
  setFlightParameters(
130
  setFlightParameters(
131
                      staticParams.IFactor,
131
                      staticParams.IFactor,
132
                      dynamicParams.gyroP,
132
                      dynamicParams.gyroP,
133
                      staticParams.bitConfig & CFG_HEADING_HOLD ? 0 : dynamicParams.gyroI,
133
                      staticParams.bitConfig & CFG_HEADING_HOLD ? 0 : dynamicParams.gyroI,
134
                      dynamicParams.gyroP,
134
                      dynamicParams.gyroP,
135
                      staticParams.yawIFactor
135
                      staticParams.yawIFactor
136
                      );
136
                      );
137
}
137
}
138
 
138
 
139
void setStableFlightParameters(void) {
139
void setStableFlightParameters(void) {
140
  setFlightParameters(33, 90, 120, 90, 120);
140
  setFlightParameters(33, 90, 120, 90, 120);
141
}
141
}
142
 
142
 
143
/************************************************************************/
143
/************************************************************************/
144
/*  Main Flight Control                                                 */
144
/*  Main Flight Control                                                 */
145
/************************************************************************/
145
/************************************************************************/
146
void flight_control(void) {
146
void flight_control(void) {
147
  int16_t tmp_int;
147
  int16_t tmp_int;
148
  // Mixer Fractions that are combined for Motor Control
148
  // Mixer Fractions that are combined for Motor Control
149
  int16_t yawTerm, throttleTerm, term[2];
149
  int16_t yawTerm, throttleTerm, term[2];
150
 
150
 
151
  // PID controller variables
151
  // PID controller variables
152
  int16_t PDPart[2],/* DPart[2],*/ PDPartYaw /*, DPartYaw */;
152
  int16_t PDPart[2],/* DPart[2],*/ PDPartYaw /*, DPartYaw */;
153
  static int32_t IPart[2] = { 0, 0 };
153
  static int32_t IPart[2] = { 0, 0 };
154
  static uint16_t emergencyFlightTime;
154
  static uint16_t emergencyFlightTime;
155
  static int8_t debugDataTimer = 1;
155
  static int8_t debugDataTimer = 1;
156
 
156
 
157
  // High resolution motor values for smoothing of PID motor outputs
157
  // High resolution motor values for smoothing of PID motor outputs
158
  static int16_t motorFilters[MAX_MOTORS];
158
  static int16_t motorFilters[MAX_MOTORS];
159
 
159
 
160
  uint8_t i, axis;
160
  uint8_t i, axis;
161
 
161
 
162
  // Fire the main flight attitude calculation, including integration of angles.
162
  // Fire the main flight attitude calculation, including integration of angles.
163
  // We want that to kick as early as possible, not to delay new AD sampling further.
163
  // We want that to kick as early as possible, not to delay new AD sampling further.
164
  calculateFlightAttitude();
164
  calculateFlightAttitude();
165
  controlMixer_update();
165
  controlMixer_update();
166
  throttleTerm = controls[CONTROL_THROTTLE];
166
  throttleTerm = controls[CONTROL_THROTTLE];
167
 
167
 
168
  // This check removed. Is done on a per-motor basis, after output matrix multiplication.
168
  // This check removed. Is done on a per-motor basis, after output matrix multiplication.
169
  if (throttleTerm < staticParams.minThrottle + 10)
169
  if (throttleTerm < staticParams.minThrottle + 10)
170
    throttleTerm = staticParams.minThrottle + 10;
170
    throttleTerm = staticParams.minThrottle + 10;
171
  else if (throttleTerm > staticParams.maxThrottle - 20)
171
  else if (throttleTerm > staticParams.maxThrottle - 20)
172
    throttleTerm = (staticParams.maxThrottle - 20);
172
    throttleTerm = (staticParams.maxThrottle - 20);
173
 
173
 
174
  /************************************************************************/
174
  /************************************************************************/
175
  /* RC-signal is bad                                                     */
175
  /* RC-signal is bad                                                     */
176
  /* This part could be abstracted, as having yet another control input   */
176
  /* This part could be abstracted, as having yet another control input   */
177
  /* to the control mixer: An emergency autopilot control.                */
177
  /* to the control mixer: An emergency autopilot control.                */
178
  /************************************************************************/
178
  /************************************************************************/
179
 
179
 
180
  if (controlMixer_getSignalQuality() <= SIGNAL_BAD) { // the rc-frame signal is not reveived or noisy
180
  if (controlMixer_getSignalQuality() <= SIGNAL_BAD) { // the rc-frame signal is not reveived or noisy
181
    if (controlMixer_didReceiveSignal) beepRCAlarm();
181
    if (controlMixer_didReceiveSignal) beepRCAlarm();
182
    if (emergencyFlightTime) {
182
    if (emergencyFlightTime) {
183
      // continue emergency flight
183
      // continue emergency flight
184
      emergencyFlightTime--;
184
      emergencyFlightTime--;
185
      if (isFlying > 256) {
185
      if (isFlying > 256) {
186
        // We're probably still flying. Descend slowly.
186
        // We're probably still flying. Descend slowly.
187
        throttleTerm = staticParams.emergencyThrottle; // Set emergency throttle
187
        throttleTerm = staticParams.emergencyThrottle; // Set emergency throttle
188
        MKFlags |= (MKFLAG_EMERGENCY_FLIGHT); // Set flag for emergency landing
188
        MKFlags |= (MKFLAG_EMERGENCY_FLIGHT); // Set flag for emergency landing
189
        setStableFlightParameters();
189
        setStableFlightParameters();
190
      } else {
190
      } else {
191
        MKFlags &= ~(MKFLAG_MOTOR_RUN); // Probably not flying, and bad R/C signal. Kill motors.
191
        MKFlags &= ~(MKFLAG_MOTOR_RUN); // Probably not flying, and bad R/C signal. Kill motors.
192
      }
192
      }
193
    } else {
193
    } else {
194
      // end emergency flight (just cut the motors???)
194
      // end emergency flight (just cut the motors???)
195
      MKFlags &= ~(MKFLAG_MOTOR_RUN | MKFLAG_EMERGENCY_FLIGHT);
195
      MKFlags &= ~(MKFLAG_MOTOR_RUN | MKFLAG_EMERGENCY_FLIGHT);
196
    }
196
    }
197
  } else {
197
  } else {
198
    // signal is acceptable
198
    // signal is acceptable
199
    if (controlMixer_getSignalQuality() > SIGNAL_BAD) {
199
    if (controlMixer_getSignalQuality() > SIGNAL_BAD) {
200
      // Reset emergency landing control variables.
200
      // Reset emergency landing control variables.
201
      MKFlags &= ~(MKFLAG_EMERGENCY_FLIGHT); // clear flag for emergency landing
201
      MKFlags &= ~(MKFLAG_EMERGENCY_FLIGHT); // clear flag for emergency landing
202
      // The time is in whole seconds.
202
      // The time is in whole seconds.
203
      emergencyFlightTime = (uint16_t) staticParams.emergencyFlightDuration * 488;
203
      emergencyFlightTime = (uint16_t) staticParams.emergencyFlightDuration * 488;
204
    }
204
    }
205
 
205
 
206
    // If some throttle is given, and the motor-run flag is on, increase the probability that we are flying.
206
    // If some throttle is given, and the motor-run flag is on, increase the probability that we are flying.
207
    if (throttleTerm > 40 && (MKFlags & MKFLAG_MOTOR_RUN)) {
207
    if (throttleTerm > 40 && (MKFlags & MKFLAG_MOTOR_RUN)) {
208
      // increment flight-time counter until overflow.
208
      // increment flight-time counter until overflow.
209
      if (isFlying != 0xFFFF)
209
      if (isFlying != 0xFFFF)
210
        isFlying++;
210
        isFlying++;
211
    } else
211
    } else
212
    /*
212
    /*
213
     * When standing on the ground, do not apply I controls and zero the yaw stick.
213
     * When standing on the ground, do not apply I controls and zero the yaw stick.
214
     * Probably to avoid integration effects that will cause the copter to spin
214
     * Probably to avoid integration effects that will cause the copter to spin
215
     * or flip when taking off.
215
     * or flip when taking off.
216
     */
216
     */
217
      if (isFlying < 256) {
217
      if (isFlying < 256) {
218
        IPart[PITCH] = IPart[ROLL] = 0;
218
        IPart[PITCH] = IPart[ROLL] = 0;
219
        PDPartYaw = 0;
219
        PDPartYaw = 0;
220
        if (isFlying == 250) {
220
        if (isFlying == 250) {
221
          // HC_setGround();
221
          // HC_setGround();
222
          updateCompassCourse = 1;
222
          updateCompassCourse = 1;
223
          yawAngleDiff = 0;
223
          yawAngleDiff = 0;
224
        }
224
        }
225
      } else {
225
      } else {
226
        // Set fly flag. TODO: Hmmm what can we trust - the isFlying counter or the flag?
226
        // Set fly flag. TODO: Hmmm what can we trust - the isFlying counter or the flag?
227
        // Answer: The counter. The flag is not read from anywhere anyway... except the NC maybe.
227
        // Answer: The counter. The flag is not read from anywhere anyway... except the NC maybe.
228
        MKFlags |= (MKFLAG_FLY);
228
        MKFlags |= (MKFLAG_FLY);
229
      }
229
      }
230
   
230
   
231
    commands_handleCommands();
231
    commands_handleCommands();
232
    setNormalFlightParameters();
232
    setNormalFlightParameters();
233
  } // end else (not bad signal case)
233
  } // end else (not bad signal case)
234
 
234
 
235
  /************************************************************************/
235
  /************************************************************************/
236
  /*  Yawing                                                              */
236
  /*  Yawing                                                              */
237
  /************************************************************************/
237
  /************************************************************************/
238
  if (abs(controls[CONTROL_YAW]) > 4 * staticParams.stickYawP) { // yaw stick is activated
238
  if (abs(controls[CONTROL_YAW]) > 4 * staticParams.stickYawP) { // yaw stick is activated
239
    ignoreCompassTimer = 1000;
239
    ignoreCompassTimer = 1000;
240
    if (!(staticParams.bitConfig & CFG_COMPASS_FIX)) {
240
    if (!(staticParams.bitConfig & CFG_COMPASS_FIX)) {
241
      updateCompassCourse = 1;
241
      updateCompassCourse = 1;
242
    }
242
    }
243
  }
243
  }
244
 
244
 
245
  // yawControlRate = controlYaw;
245
  // yawControlRate = controlYaw;
246
  // Trim drift of yawAngleDiff with controlYaw.
246
  // Trim drift of yawAngleDiff with controlYaw.
247
  // TODO: We want NO feedback of control related stuff to the attitude related stuff.
247
  // TODO: We want NO feedback of control related stuff to the attitude related stuff.
248
  // This seems to be used as: Difference desired <--> real heading.
248
  // This seems to be used as: Difference desired <--> real heading.
249
  yawAngleDiff -= controls[CONTROL_YAW];
249
  yawAngleDiff -= controls[CONTROL_YAW];
250
 
250
 
251
  // limit the effect
251
  // limit the effect
252
  CHECK_MIN_MAX(yawAngleDiff, -50000, 50000);
252
  CHECK_MIN_MAX(yawAngleDiff, -50000, 50000);
253
 
253
 
254
  /************************************************************************/
254
  /************************************************************************/
255
  /* Compass is currently not supported.                                  */
255
  /* Compass is currently not supported.                                  */
256
  /************************************************************************/
256
  /************************************************************************/
257
  if (staticParams.bitConfig & (CFG_COMPASS_ACTIVE | CFG_GPS_ACTIVE)) {
257
  if (staticParams.bitConfig & (CFG_COMPASS_ACTIVE | CFG_GPS_ACTIVE)) {
258
    updateCompass();
258
    updateCompass();
259
  }
259
  }
260
 
260
 
261
#if defined (USE_NAVICTRL)
261
#if defined (USE_NAVICTRL)
262
  /************************************************************************/
262
  /************************************************************************/
263
  /* GPS is currently not supported.                                      */
263
  /* GPS is currently not supported.                                      */
264
  /************************************************************************/
264
  /************************************************************************/
265
  if(staticParams.GlobalConfig & CFG_GPS_ACTIVE) {
265
  if(staticParams.GlobalConfig & CFG_GPS_ACTIVE) {
266
    GPS_Main();
266
    GPS_Main();
267
    MKFlags &= ~(MKFLAG_CALIBRATE | MKFLAG_START);
267
    MKFlags &= ~(MKFLAG_CALIBRATE | MKFLAG_START);
268
  } else {
268
  } else {
269
  }
269
  }
270
#endif
270
#endif
271
  // end part 1: 750-800 usec.
271
  // end part 1: 750-800 usec.
272
  // start part 3: 350 - 400 usec.
272
  // start part 3: 350 - 400 usec.
273
#define SENSOR_LIMIT  (4096 * 4)
273
#define SENSOR_LIMIT  (4096 * 4)
274
  /************************************************************************/
274
  /************************************************************************/
275
 
275
 
276
  /* Calculate control feedback from angle (gyro integral)                */
276
  /* Calculate control feedback from angle (gyro integral)                */
277
  /* and angular velocity (gyro signal)                                   */
277
  /* and angular velocity (gyro signal)                                   */
278
  /************************************************************************/
278
  /************************************************************************/
279
  // The P-part is the P of the PID controller. That's the angle integrals (not rates).
279
  // The P-part is the P of the PID controller. That's the angle integrals (not rates).
280
  for (axis = PITCH; axis <= ROLL; axis++) {
280
  for (axis = PITCH; axis <= ROLL; axis++) {
281
    PDPart[axis] = angle[axis] * gyroIFactor / (44000 / CONTROL_SCALING); // P-Part - Proportional to Integral
281
    PDPart[axis] = angle[axis] * gyroIFactor / (44000 / CONTROL_SCALING); // P-Part - Proportional to Integral
282
    PDPart[axis] += ((int32_t) rate_PID[axis] * gyroPFactor / (256L / CONTROL_SCALING));
282
    PDPart[axis] += ((int32_t) rate_PID[axis] * gyroPFactor / (256L / CONTROL_SCALING));
283
    PDPart[axis] += (differential[axis] * (int16_t) dynamicParams.gyroD) / 16;
283
    PDPart[axis] += (differential[axis] * (int16_t) dynamicParams.gyroD) / 16;
284
    CHECK_MIN_MAX(PDPart[axis], -SENSOR_LIMIT, SENSOR_LIMIT);
284
    CHECK_MIN_MAX(PDPart[axis], -SENSOR_LIMIT, SENSOR_LIMIT);
285
  }
285
  }
286
 
286
 
287
  PDPartYaw = (int32_t) (yawAngleDiff * yawIFactor) / (2 * (44000 / CONTROL_SCALING));
287
  PDPartYaw = (int32_t) (yawAngleDiff * yawIFactor) / (2 * (44000 / CONTROL_SCALING));
288
  PDPartYaw += (int32_t) (yawRate * 2 * (int32_t) yawPFactor) / (256L / CONTROL_SCALING);
288
  PDPartYaw += (int32_t) (yawRate * 2 * (int32_t) yawPFactor) / (256L / CONTROL_SCALING);
289
 
289
 
290
  // limit control feedback
290
  // limit control feedback
291
  // CHECK_MIN_MAX(PDPartYaw, -SENSOR_LIMIT, SENSOR_LIMIT);
291
  // CHECK_MIN_MAX(PDPartYaw, -SENSOR_LIMIT, SENSOR_LIMIT);
292
 
292
 
293
  /*
293
  /*
294
   * Compose throttle term.
294
   * Compose throttle term.
295
   * If a Bl-Ctrl is missing, prevent takeoff.
295
   * If a Bl-Ctrl is missing, prevent takeoff.
296
   */
296
   */
297
  if (missingMotor) {
297
  if (missingMotor) {
298
    // if we are in the lift off condition. Hmmmmmm when is throttleTerm == 0 anyway???
298
    // if we are in the lift off condition. Hmmmmmm when is throttleTerm == 0 anyway???
299
    if (isFlying > 1 && isFlying < 50 && throttleTerm > 0)
299
    if (isFlying > 1 && isFlying < 50 && throttleTerm > 0)
300
      isFlying = 1; // keep within lift off condition
300
      isFlying = 1; // keep within lift off condition
301
    throttleTerm = staticParams.minThrottle; // reduce gas to min to avoid lift of
301
    throttleTerm = staticParams.minThrottle; // reduce gas to min to avoid lift of
302
  }
302
  }
303
 
303
 
304
  // Scale up to higher resolution. Hmm why is it not (from controlMixer and down) scaled already?
304
  // Scale up to higher resolution. Hmm why is it not (from controlMixer and down) scaled already?
305
  throttleTerm *= CONTROL_SCALING;
305
  throttleTerm *= CONTROL_SCALING;
306
 
306
 
307
  /*
307
  /*
308
   * Compose yaw term.
308
   * Compose yaw term.
309
   * The yaw term is limited: Absolute value is max. = the throttle term / 2.
309
   * The yaw term is limited: Absolute value is max. = the throttle term / 2.
310
   * However, at low throttle the yaw term is limited to a fixed value,
310
   * However, at low throttle the yaw term is limited to a fixed value,
311
   * and at high throttle it is limited by the throttle reserve (the difference
311
   * and at high throttle it is limited by the throttle reserve (the difference
312
   * between current throttle and maximum throttle).
312
   * between current throttle and maximum throttle).
313
   */
313
   */
314
#define MIN_YAWGAS (40 * CONTROL_SCALING)  // yaw also below this gas value
314
#define MIN_YAWGAS (40 * CONTROL_SCALING)  // yaw also below this gas value
315
  yawTerm = PDPartYaw - controls[CONTROL_YAW] * CONTROL_SCALING;
315
  yawTerm = PDPartYaw - controls[CONTROL_YAW] * CONTROL_SCALING;
316
  // Limit yawTerm
316
  // Limit yawTerm
317
  debugOut.digital[0] &= ~DEBUG_CLIP;
317
  debugOut.digital[0] &= ~DEBUG_CLIP;
318
  if (throttleTerm > MIN_YAWGAS) {
318
  if (throttleTerm > MIN_YAWGAS) {
319
    if (yawTerm < -throttleTerm / 2) {
319
    if (yawTerm < -throttleTerm / 2) {
320
      debugOut.digital[0] |= DEBUG_CLIP;
320
      debugOut.digital[0] |= DEBUG_CLIP;
321
      yawTerm = -throttleTerm / 2;
321
      yawTerm = -throttleTerm / 2;
322
    } else if (yawTerm > throttleTerm / 2) {
322
    } else if (yawTerm > throttleTerm / 2) {
323
      debugOut.digital[0] |= DEBUG_CLIP;
323
      debugOut.digital[0] |= DEBUG_CLIP;
324
      yawTerm = throttleTerm / 2;
324
      yawTerm = throttleTerm / 2;
325
    }
325
    }
326
  } else {
326
  } else {
327
    if (yawTerm < -MIN_YAWGAS / 2) {
327
    if (yawTerm < -MIN_YAWGAS / 2) {
328
      debugOut.digital[0] |= DEBUG_CLIP;
328
      debugOut.digital[0] |= DEBUG_CLIP;
329
      yawTerm = -MIN_YAWGAS / 2;
329
      yawTerm = -MIN_YAWGAS / 2;
330
    } else if (yawTerm > MIN_YAWGAS / 2) {
330
    } else if (yawTerm > MIN_YAWGAS / 2) {
331
      debugOut.digital[0] |= DEBUG_CLIP;
331
      debugOut.digital[0] |= DEBUG_CLIP;
332
      yawTerm = MIN_YAWGAS / 2;
332
      yawTerm = MIN_YAWGAS / 2;
333
    }
333
    }
334
  }
334
  }
335
 
335
 
336
  tmp_int = staticParams.maxThrottle * CONTROL_SCALING;
336
  tmp_int = staticParams.maxThrottle * CONTROL_SCALING;
337
  if (yawTerm < -(tmp_int - throttleTerm)) {
337
  if (yawTerm < -(tmp_int - throttleTerm)) {
338
    yawTerm = -(tmp_int - throttleTerm);
338
    yawTerm = -(tmp_int - throttleTerm);
339
    debugOut.digital[0] |= DEBUG_CLIP;
339
    debugOut.digital[0] |= DEBUG_CLIP;
340
  } else if (yawTerm > (tmp_int - throttleTerm)) {
340
  } else if (yawTerm > (tmp_int - throttleTerm)) {
341
    yawTerm = (tmp_int - throttleTerm);
341
    yawTerm = (tmp_int - throttleTerm);
342
    debugOut.digital[0] |= DEBUG_CLIP;
342
    debugOut.digital[0] |= DEBUG_CLIP;
343
  }
343
  }
344
 
344
 
345
  // CHECK_MIN_MAX(yawTerm, -(tmp_int - throttleTerm), (tmp_int - throttleTerm));
345
  // CHECK_MIN_MAX(yawTerm, -(tmp_int - throttleTerm), (tmp_int - throttleTerm));
346
  debugOut.digital[1] &= ~DEBUG_CLIP;
346
  debugOut.digital[1] &= ~DEBUG_CLIP;
347
  for (axis = PITCH; axis <= ROLL; axis++) {
347
  for (axis = PITCH; axis <= ROLL; axis++) {
348
    /*
348
    /*
349
     * Compose pitch and roll terms. This is finally where the sticks come into play.
349
     * Compose pitch and roll terms. This is finally where the sticks come into play.
350
     */
350
     */
351
    if (gyroIFactor) {
351
    if (gyroIFactor) {
352
      // Integration mode: Integrate (angle - stick) = the difference between angle and stick pos.
352
      // Integration mode: Integrate (angle - stick) = the difference between angle and stick pos.
353
      // That means: Holding the stick a little forward will, at constant flight attitude, cause this to grow (decline??) over time.
353
      // That means: Holding the stick a little forward will, at constant flight attitude, cause this to grow (decline??) over time.
354
      // TODO: Find out why this seems to be proportional to stick position - not integrating it at all.
354
      // TODO: Find out why this seems to be proportional to stick position - not integrating it at all.
355
      IPart[axis] += PDPart[axis] - controls[axis]; // Integrate difference between P part (the angle) and the stick pos.
355
      IPart[axis] += PDPart[axis] - controls[axis]; // Integrate difference between P part (the angle) and the stick pos.
356
    } else {
356
    } else {
357
      // "HH" mode: Integrate (rate - stick) = the difference between rotation rate and stick pos.
357
      // "HH" mode: Integrate (rate - stick) = the difference between rotation rate and stick pos.
358
      // To keep up with a full stick PDPart should be about 156...
358
      // To keep up with a full stick PDPart should be about 156...
359
      IPart[axis] += PDPart[axis] - controls[axis]; // With gyroIFactor == 0, PDPart is really just a D-part. Integrate D-part (the rot. rate) and the stick pos.
359
      IPart[axis] += PDPart[axis] - controls[axis]; // With gyroIFactor == 0, PDPart is really just a D-part. Integrate D-part (the rot. rate) and the stick pos.
360
    }
360
    }
361
 
361
 
362
    tmp_int = (int32_t) ((int32_t) dynamicParams.dynamicStability
362
    tmp_int = (int32_t) ((int32_t) dynamicParams.dynamicStability
363
        * (int32_t) (throttleTerm + abs(yawTerm) / 2)) / 64;
363
        * (int32_t) (throttleTerm + abs(yawTerm) / 2)) / 64;
364
 
364
 
365
    // TODO: From which planet comes the 16000?
365
    // TODO: From which planet comes the 16000?
366
    CHECK_MIN_MAX(IPart[axis], -(CONTROL_SCALING * 16000L), (CONTROL_SCALING * 16000L));
366
    CHECK_MIN_MAX(IPart[axis], -(CONTROL_SCALING * 16000L), (CONTROL_SCALING * 16000L));
367
    // Add (P, D) parts minus stick pos. to the scaled-down I part.
367
    // Add (P, D) parts minus stick pos. to the scaled-down I part.
368
    term[axis] = PDPart[axis] - controls[axis] + IPart[axis] / Ki; // PID-controller for pitch
368
    term[axis] = PDPart[axis] - controls[axis] + IPart[axis] / Ki; // PID-controller for pitch
369
        term[axis] += (dynamicParams.levelCorrection[axis] - 128);
369
        term[axis] += (dynamicParams.levelCorrection[axis] - 128);
370
    /*
370
    /*
371
     * Apply "dynamic stability" - that is: Limit pitch and roll terms to a growing function of throttle and yaw(!).
371
     * Apply "dynamic stability" - that is: Limit pitch and roll terms to a growing function of throttle and yaw(!).
372
     * The higher the dynamic stability parameter, the wider the bounds. 64 seems to be a kind of unity
372
     * The higher the dynamic stability parameter, the wider the bounds. 64 seems to be a kind of unity
373
     * (max. pitch or roll term is the throttle value).
373
     * (max. pitch or roll term is the throttle value).
374
     * TODO: Why a growing function of yaw?
374
     * TODO: Why a growing function of yaw?
375
     */
375
     */
376
    if (term[axis] < -tmp_int) {
376
    if (term[axis] < -tmp_int) {
377
      debugOut.digital[1] |= DEBUG_CLIP;
377
      debugOut.digital[1] |= DEBUG_CLIP;
378
    } else if (term[axis] > tmp_int) {
378
    } else if (term[axis] > tmp_int) {
379
      debugOut.digital[1] |= DEBUG_CLIP;
379
      debugOut.digital[1] |= DEBUG_CLIP;
380
    }
380
    }
381
  }
381
  }
382
 
382
 
383
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
383
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
384
  // Universal Mixer
384
  // Universal Mixer
385
  // Each (pitch, roll, throttle, yaw) term is in the range [0..255 * CONTROL_SCALING].
385
  // Each (pitch, roll, throttle, yaw) term is in the range [0..255 * CONTROL_SCALING].
386
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
386
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
387
 
387
 
388
  debugOut.analog[3]  = rate_ATT[PITCH];
388
  debugOut.analog[3]  = rate_ATT[PITCH];
389
  debugOut.analog[4]  = rate_ATT[ROLL];
389
  debugOut.analog[4]  = rate_ATT[ROLL];
390
  debugOut.analog[5]  = yawRate;
390
  debugOut.analog[5]  = yawRate;
391
 
391
 
392
  debugOut.analog[6]  = filteredAcc[PITCH];
392
  debugOut.analog[6]  = filteredAcc[PITCH];
393
  debugOut.analog[7]  = filteredAcc[ROLL];
393
  debugOut.analog[7]  = filteredAcc[ROLL];
394
  debugOut.analog[8]  = filteredAcc[Z];
394
  debugOut.analog[8]  = filteredAcc[Z];
395
 
395
 
396
  debugOut.analog[12] = term[PITCH];
396
  debugOut.analog[12] = term[PITCH];
397
  debugOut.analog[13] = term[ROLL];
397
  debugOut.analog[13] = term[ROLL];
398
  debugOut.analog[14] = yawTerm;
398
  debugOut.analog[14] = yawTerm;
399
  debugOut.analog[15] = throttleTerm;
399
  debugOut.analog[15] = throttleTerm;
400
 
400
 
401
  for (i = 0; i < MAX_MOTORS; i++) {
401
  for (i = 0; i < MAX_MOTORS; i++) {
402
    int32_t tmp;
402
    int32_t tmp;
403
    uint8_t throttle;
403
    uint8_t throttle;
404
 
404
 
405
    tmp = (int32_t)throttleTerm * mixerMatrix.motor[i][MIX_THROTTLE];
405
    tmp = (int32_t)throttleTerm * mixerMatrix.motor[i][MIX_THROTTLE];
406
    tmp += (int32_t)term[PITCH] * mixerMatrix.motor[i][MIX_PITCH];
406
    tmp += (int32_t)term[PITCH] * mixerMatrix.motor[i][MIX_PITCH];
407
    tmp += (int32_t)term[ROLL] * mixerMatrix.motor[i][MIX_ROLL];
407
    tmp += (int32_t)term[ROLL] * mixerMatrix.motor[i][MIX_ROLL];
408
    tmp += (int32_t)yawTerm * mixerMatrix.motor[i][MIX_YAW];
408
    tmp += (int32_t)yawTerm * mixerMatrix.motor[i][MIX_YAW];
409
    tmp = tmp >> 6;
409
    tmp = tmp >> 6;
410
    motorFilters[i] = motorFilter(tmp, motorFilters[i]);
410
    motorFilters[i] = motorFilter(tmp, motorFilters[i]);
411
    // Now we scale back down to a 0..255 range.
411
    // Now we scale back down to a 0..255 range.
412
    tmp = motorFilters[i] / MOTOR_SCALING;
412
    tmp = motorFilters[i] / MOTOR_SCALING;
413
 
413
 
414
    // So this was the THIRD time a throttle was limited. But should the limitation
414
    // So this was the THIRD time a throttle was limited. But should the limitation
415
    // apply to the common throttle signal (the one used for setting the "power" of
415
    // apply to the common throttle signal (the one used for setting the "power" of
416
    // all motors together) or should it limit the throttle set for each motor,
416
    // all motors together) or should it limit the throttle set for each motor,
417
    // including mix components of pitch, roll and yaw? I think only the common
417
    // including mix components of pitch, roll and yaw? I think only the common
418
    // throttle should be limited.
418
    // throttle should be limited.
419
    // --> WRONG. This caused motors to stall completely in tight maneuvers.
419
    // --> WRONG. This caused motors to stall completely in tight maneuvers.
420
    // Apply to individual signals instead.
420
    // Apply to individual signals instead.
421
    CHECK_MIN_MAX(tmp, 1, 255);
421
    CHECK_MIN_MAX(tmp, 1, 255);
422
    throttle = tmp;
422
    throttle = tmp;
423
 
423
 
424
    // if (i < 4) debugOut.analog[22 + i] = throttle;
424
    // if (i < 4) debugOut.analog[22 + i] = throttle;
425
 
425
 
426
    if ((MKFlags & MKFLAG_MOTOR_RUN) && mixerMatrix.motor[i][MIX_THROTTLE] > 0) {
426
    if ((MKFlags & MKFLAG_MOTOR_RUN) && mixerMatrix.motor[i][MIX_THROTTLE] > 0) {
427
      motor[i].SetPoint = throttle;
427
      motor[i].throttle = throttle;
428
    } else if (motorTestActive) {
428
    } else if (motorTestActive) {
429
      motor[i].SetPoint = motorTest[i];
429
      motor[i].throttle = motorTest[i];
430
    } else {
430
    } else {
431
      motor[i].SetPoint = 0;
431
      motor[i].throttle = 0;
432
    }
432
    }
433
  }
433
  }
434
 
434
 
435
  I2C_Start(TWI_STATE_MOTOR_TX);
435
  I2C_Start(TWI_STATE_MOTOR_TX);
436
 
436
 
437
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
437
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
438
  // Debugging
438
  // Debugging
439
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
439
  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
440
  if (!(--debugDataTimer)) {
440
  if (!(--debugDataTimer)) {
441
    debugDataTimer = 24; // update debug outputs at 488 / 24 = 20.3 Hz.
441
    debugDataTimer = 24; // update debug outputs at 488 / 24 = 20.3 Hz.
442
    debugOut.analog[0] = (10 * angle[PITCH]) / GYRO_DEG_FACTOR_PITCHROLL; // in 0.1 deg
442
    debugOut.analog[0] = (10 * angle[PITCH]) / GYRO_DEG_FACTOR_PITCHROLL; // in 0.1 deg
443
    debugOut.analog[1] = (10 * angle[ROLL]) / GYRO_DEG_FACTOR_PITCHROLL; // in 0.1 deg
443
    debugOut.analog[1] = (10 * angle[ROLL]) / GYRO_DEG_FACTOR_PITCHROLL; // in 0.1 deg
444
    debugOut.analog[2] = yawGyroHeading / GYRO_DEG_FACTOR_YAW;
444
    debugOut.analog[2] = yawGyroHeading / GYRO_DEG_FACTOR_YAW;
445
 
-
 
446
    debugOut.analog[16] = gyroPFactor;
-
 
447
  }
445
  }
448
}
446
}
449
 
447