Subversion Repositories NaviCtrl

Rev

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

Rev 102 Rev 103
1
/*#######################################################################################*/
1
/*#######################################################################################*/
2
/*#######################################################################################*/
2
/*#######################################################################################*/
3
 
3
 
4
// IMPORTANT NOTE:
4
// IMPORTANT NOTE:
5
 
5
 
6
// This is only a dummy implementation for errorfree compiling of the NaviCtrl sources.
6
// This is only a dummy implementation for errorfree compiling of the NaviCtrl sources.
7
 
7
 
8
// The GPS navigation routines are NOT included !
8
// The GPS navigation routines are NOT included !
9
 
9
 
10
/*#######################################################################################*/
10
/*#######################################################################################*/
11
/*#######################################################################################*/
11
/*#######################################################################################*/
12
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
12
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
13
/*#######################################################################################*/
13
/*#######################################################################################*/
14
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15
// + Copyright (c) 2008 Ingo Busker, Holger Buss
15
// + Copyright (c) 2008 Ingo Busker, Holger Buss
16
// + Nur für den privaten Gebrauch
16
// + Nur für den privaten Gebrauch
17
// + FOR NON COMMERCIAL USE ONLY
17
// + FOR NON COMMERCIAL USE ONLY
18
// + www.MikroKopter.com
18
// + www.MikroKopter.com
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
20
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
21
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
21
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
22
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
22
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
23
// + bzgl. der Nutzungsbedingungen aufzunehmen.
23
// + bzgl. der Nutzungsbedingungen aufzunehmen.
24
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
24
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
25
// + Verkauf von Luftbildaufnahmen, usw.
25
// + Verkauf von Luftbildaufnahmen, usw.
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
27
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
28
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
28
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
30
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
31
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
31
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
32
// + eindeutig als Ursprung verlinkt werden
32
// + eindeutig als Ursprung verlinkt werden
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
34
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
35
// + Benutzung auf eigene Gefahr
35
// + Benutzung auf eigene Gefahr
36
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
36
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
37
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
37
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
38
// + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
38
// + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
39
// + mit unserer Zustimmung zulässig
39
// + mit unserer Zustimmung zulässig
40
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
40
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
41
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
42
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
42
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
43
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
43
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
44
// + this list of conditions and the following disclaimer.
44
// + this list of conditions and the following disclaimer.
45
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
45
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
46
// +     from this software without specific prior written permission.
46
// +     from this software without specific prior written permission.
47
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted
47
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted
48
// +     for non-commercial use (directly or indirectly)
48
// +     for non-commercial use (directly or indirectly)
49
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
49
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
50
// +     with our written permission
50
// +     with our written permission
51
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
51
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
52
// +     clearly linked as origin
52
// +     clearly linked as origin
53
// +   * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed
53
// +   * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed
54
//
54
//
55
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
55
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
56
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
58
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
59
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
59
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
60
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
60
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
61
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
61
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
62
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
62
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
63
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
63
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
64
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
64
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
65
// +  POSSIBILITY OF SUCH DAMAGE.
65
// +  POSSIBILITY OF SUCH DAMAGE.
66
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
66
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
67
#include <stdio.h>
67
#include <stdio.h>
68
#include <stdlib.h>
68
#include <stdlib.h>
69
#include <math.h>
69
#include <math.h>
70
#include "91x_lib.h"
70
#include "91x_lib.h"
71
#include "main.h"
71
#include "main.h"
72
#include "uart1.h"
72
#include "uart1.h"
73
#include "GPS.h"
73
#include "GPS.h"
74
#include "timer.h"
74
#include "timer.h"
75
#include "spi_slave.h"
75
#include "spi_slave.h"
76
#include "waypoints.h"
76
#include "waypoints.h"
77
#include "i2c.h"
77
#include "i2c.h"
78
 
78
 
79
 
79
 
80
#define M_PI_180        (M_PI / 180.0f)
80
#define M_PI_180        (M_PI / 180.0f)
81
#define GPS_UPDATETIME_MS 200           // 200ms is 5 Hz
81
#define GPS_UPDATETIME_MS 200           // 200ms is 5 Hz
82
typedef enum
82
typedef enum
83
{
83
{
84
        GPS_FLIGHT_MODE_UNDEF,
84
        GPS_FLIGHT_MODE_UNDEF,
85
        GPS_FLIGHT_MODE_FREE,
85
        GPS_FLIGHT_MODE_FREE,
86
        GPS_FLIGHT_MODE_AID,
86
        GPS_FLIGHT_MODE_AID,
87
        GPS_FLIGHT_MODE_WAYPOINT
87
        GPS_FLIGHT_MODE_WAYPOINT
88
} GPS_FlightMode_t;
88
} GPS_FlightMode_t;
89
 
89
 
90
typedef struct
90
typedef struct
91
{
91
{
92
        float Gain;
92
        float Gain;
93
        float P;
93
        float P;
94
        float I;
94
        float I;
95
        float D;
95
        float D;
96
        float A;
96
        float A;
97
        float ACC;
97
        float ACC;
98
        s32 P_Limit;
98
        s32 P_Limit;
99
        s32 I_Limit;
99
        s32 I_Limit;
100
        s32 D_Limit;
100
        s32 D_Limit;
101
        s32 PID_Limit;
101
        s32 PID_Limit;
102
        u32 BrakingDuration;
102
        u32 BrakingDuration;
103
        u8 MinSat;
103
        u8 MinSat;
104
        s8 StickThreshold;
104
        s8 StickThreshold;
105
        float WindCorrection;
105
        float WindCorrection;
106
        float SpeedCompensation;
106
        float SpeedCompensation;
107
        s32 OperatingRadius;
107
        s32 OperatingRadius;
108
        GPS_FlightMode_t  FlightMode;
108
        GPS_FlightMode_t  FlightMode;
109
} __attribute__((packed)) GPS_Parameter_t;
109
} __attribute__((packed)) GPS_Parameter_t;
110
 
110
 
111
typedef struct
111
typedef struct
112
{
112
{
113
        u8  Status; // invalid, newdata, processed
113
        u8  Status; // invalid, newdata, processed
114
        s32 North;              // in cm
114
        s32 North;              // in cm
115
        s32 East;               // in cm
115
        s32 East;               // in cm
116
        s32 Bearing;    // in deg
116
        s32 Bearing;    // in deg
117
        s32 Distance;   // in cm
117
        s32 Distance;   // in cm
118
} __attribute__((packed)) GPS_Deviation_t;
118
} __attribute__((packed)) GPS_Deviation_t;
119
GPS_Deviation_t CurrentTargetDeviation;         // Deviation from Target
119
GPS_Deviation_t CurrentTargetDeviation;         // Deviation from Target
120
GPS_Deviation_t CurrentHomeDeviation;           // Deviation from Home
120
GPS_Deviation_t CurrentHomeDeviation;           // Deviation from Home
121
GPS_Deviation_t TargetHomeDeviation;            // Deviation from Target to Home
121
GPS_Deviation_t TargetHomeDeviation;            // Deviation from Target to Home
122
 
122
 
123
GPS_Stick_t             GPS_Stick;
123
GPS_Stick_t             GPS_Stick;
124
GPS_Parameter_t GPS_Parameter;
124
GPS_Parameter_t GPS_Parameter;
125
 
125
 
126
// the gps reference positions
126
// the gps reference positions
127
GPS_Pos_t GPS_HoldPosition      = {0,0,0, INVALID};                     // the hold position
127
GPS_Pos_t GPS_HoldPosition      = {0,0,0, INVALID};                     // the hold position
128
GPS_Pos_t GPS_HomePosition      = {0,0,0, INVALID};                     // the home position
128
GPS_Pos_t GPS_HomePosition      = {0,0,0, INVALID};                     // the home position
129
GPS_Pos_t * GPS_pTargetPosition = NULL;                             // pointer to the actual target position
129
GPS_Pos_t * GPS_pTargetPosition = NULL;                             // pointer to the actual target position
130
u32 GPS_TargetRadius = 0;                                                               // catch radius for target area
130
u32 GPS_TargetRadius = 0;                                                               // catch radius for target area
131
Waypoint_t* GPS_pWaypoint = NULL;                                               // pointer to the actual waypoint
131
Waypoint_t* GPS_pWaypoint = NULL;                                               // pointer to the actual waypoint
132
 
132
 
133
//-------------------------------------------------------------
133
//-------------------------------------------------------------
134
// Update GPSParamter
134
// Update GPSParamter
135
void GPS_UpdateParameter(void)
135
void GPS_UpdateParameter(void)
136
{
136
{
137
        static GPS_FlightMode_t FlightMode_Old = GPS_FLIGHT_MODE_UNDEF;
137
        static GPS_FlightMode_t FlightMode_Old = GPS_FLIGHT_MODE_UNDEF;
138
        // in case of bad receiving conditions
138
        // in case of bad receiving conditions
139
        if(FC.RC_Quality < 100)
139
        if(FC.RC_Quality < 100)
140
        {       // set fixed parameter
140
        {       // set fixed parameter
141
                GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_WAYPOINT;
141
                GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_WAYPOINT;
142
                GPS_Parameter.Gain      = (float) 100;
142
                GPS_Parameter.Gain      = (float) 100;
143
                GPS_Parameter.P         = (float) 90;
143
                GPS_Parameter.P         = (float) 90;
144
                GPS_Parameter.I         = (float) 90;
144
                GPS_Parameter.I         = (float) 90;
145
                GPS_Parameter.D         = (float) 90;
145
                GPS_Parameter.D         = (float) 90;
146
                GPS_Parameter.A         = (float) 90;
146
                GPS_Parameter.A         = (float) 90;
147
                GPS_Parameter.ACC       = (float) 0;
147
                GPS_Parameter.ACC       = (float) 0;
148
                GPS_Parameter.P_Limit = 90;
148
                GPS_Parameter.P_Limit = 90;
149
                GPS_Parameter.I_Limit = 90;
149
                GPS_Parameter.I_Limit = 90;
150
                GPS_Parameter.D_Limit = 90;
150
                GPS_Parameter.D_Limit = 90;
151
                GPS_Parameter.PID_Limit = 200;
151
                GPS_Parameter.PID_Limit = 200;
152
                GPS_Parameter.BrakingDuration = 0;
152
                GPS_Parameter.BrakingDuration = 0;
153
                GPS_Parameter.SpeedCompensation = (float) 30;
153
                GPS_Parameter.SpeedCompensation = (float) 30;
154
                GPS_Parameter.MinSat = 6;
154
                GPS_Parameter.MinSat = 6;
155
                GPS_Parameter.StickThreshold = 8;
155
                GPS_Parameter.StickThreshold = 8;
156
                GPS_Parameter.WindCorrection = 0.0;
156
                GPS_Parameter.WindCorrection = 0.0;
157
                GPS_Parameter.OperatingRadius = 0; // forces the aircraft to fly to home positon
157
                GPS_Parameter.OperatingRadius = 0; // forces the aircraft to fly to home positon
158
 
158
 
159
        }
159
        }
160
        else
160
        else
161
        {
161
        {
162
                // update parameter from FC
162
                // update parameter from FC
163
                if(StopNavigation) GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_FREE;
163
                if(StopNavigation) GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_FREE;
164
                else
164
                else
165
                {
165
                {
166
                        if(Parameter.NaviGpsModeControl <  50)
166
                        if(Parameter.NaviGpsModeControl <  50)
167
                        {
167
                        {
168
                                GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_FREE;
168
                                GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_FREE;
169
                                NCFlags &= ~(NC_FLAG_PH | NC_FLAG_CH);
169
                                NCFlags &= ~(NC_FLAG_PH | NC_FLAG_CH);
170
                                NCFlags |= NC_FLAG_FREE;
170
                                NCFlags |= NC_FLAG_FREE;
171
                        }
171
                        }
172
                        else if(Parameter.NaviGpsModeControl < 180)
172
                        else if(Parameter.NaviGpsModeControl < 180)
173
                        {
173
                        {
174
                                GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_AID;
174
                                GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_AID;
175
                                NCFlags &= ~(NC_FLAG_FREE | NC_FLAG_CH);
175
                                NCFlags &= ~(NC_FLAG_FREE | NC_FLAG_CH);
176
                                NCFlags |= NC_FLAG_PH;
176
                                NCFlags |= NC_FLAG_PH;
177
                        }
177
                        }
178
                        else
178
                        else
179
                        {
179
                        {
180
                                GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_WAYPOINT;
180
                                GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_WAYPOINT;
181
                                NCFlags &= ~(NC_FLAG_FREE | NC_FLAG_PH);
181
                                NCFlags &= ~(NC_FLAG_FREE | NC_FLAG_PH);
182
                                NCFlags |= NC_FLAG_CH;
182
                                NCFlags |= NC_FLAG_CH;
183
                        }
183
                        }
184
                }
184
                }
185
                GPS_Parameter.Gain      = (float)Parameter.NaviGpsGain;
185
                GPS_Parameter.Gain      = (float)Parameter.NaviGpsGain;
186
                GPS_Parameter.P         = (float)Parameter.NaviGpsP;
186
                GPS_Parameter.P         = (float)Parameter.NaviGpsP;
187
                GPS_Parameter.I         = (float)Parameter.NaviGpsI;
187
                GPS_Parameter.I         = (float)Parameter.NaviGpsI;
188
                GPS_Parameter.D         = (float)Parameter.NaviGpsD;
188
                GPS_Parameter.D         = (float)Parameter.NaviGpsD;
189
                GPS_Parameter.A         = (float)Parameter.NaviGpsD;
189
                GPS_Parameter.A         = (float)Parameter.NaviGpsD;
190
                GPS_Parameter.ACC       = (float)Parameter.NaviGpsACC;
190
                GPS_Parameter.ACC       = (float)Parameter.NaviGpsACC;
191
                GPS_Parameter.P_Limit = (s32)Parameter.NaviGpsPLimit;
191
                GPS_Parameter.P_Limit = (s32)Parameter.NaviGpsPLimit;
192
                GPS_Parameter.I_Limit = (s32)Parameter.NaviGpsILimit;
192
                GPS_Parameter.I_Limit = (s32)Parameter.NaviGpsILimit;
193
                GPS_Parameter.D_Limit = (s32)Parameter.NaviGpsDLimit;
193
                GPS_Parameter.D_Limit = (s32)Parameter.NaviGpsDLimit;
194
                GPS_Parameter.PID_Limit = 2* (u32)Parameter.NaviAngleLimitation;
194
                GPS_Parameter.PID_Limit = 2* (u32)Parameter.NaviAngleLimitation;
195
                GPS_Parameter.BrakingDuration = (u32)Parameter.NaviPH_LoginTime;
195
                GPS_Parameter.BrakingDuration = (u32)Parameter.NaviPH_LoginTime;
196
                GPS_Parameter.SpeedCompensation = (float)Parameter.NaviSpeedCompensation;
196
                GPS_Parameter.SpeedCompensation = (float)Parameter.NaviSpeedCompensation;
197
                GPS_Parameter.MinSat = (u8)Parameter.NaviGpsMinSat;
197
                GPS_Parameter.MinSat = (u8)Parameter.NaviGpsMinSat;
198
                GPS_Parameter.StickThreshold = (s8)Parameter.NaviStickThreshold;
198
                GPS_Parameter.StickThreshold = (s8)Parameter.NaviStickThreshold;
199
                GPS_Parameter.WindCorrection = (float)Parameter.NaviWindCorrection;
199
                GPS_Parameter.WindCorrection = (float)Parameter.NaviWindCorrection;
200
                GPS_Parameter.OperatingRadius = (s32)Parameter.NaviOperatingRadius * 100; // conversion of m to cm
200
                GPS_Parameter.OperatingRadius = (s32)Parameter.NaviOperatingRadius * 100; // conversion of m to cm
201
        }
201
        }
202
        // FlightMode changed?
202
        // FlightMode changed?
-
 
203
        if(GPS_Parameter.FlightMode != FlightMode_Old)
-
 
204
        {
203
        if(GPS_Parameter.FlightMode != FlightMode_Old) BeepTime = 100; // beep to indicate that mode has switched
205
                BeepTime = 100; // beep to indicate that mode has been switched
-
 
206
                NCFlags &= ~NC_FLAG_TARGET_REACHED;
-
 
207
        }
204
        FlightMode_Old = GPS_Parameter.FlightMode;
208
        FlightMode_Old = GPS_Parameter.FlightMode;
205
}
209
}
206
 
210
 
207
//-------------------------------------------------------------
211
//-------------------------------------------------------------
208
// This function defines a good GPS signal condition
212
// This function defines a good GPS signal condition
209
u8 GPS_IsSignalOK(void)
213
u8 GPS_IsSignalOK(void)
210
{
214
{
211
        if( (GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) &&  (GPSData.NumOfSats >= GPS_Parameter.MinSat)) return(1);
215
        if( (GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) &&  (GPSData.NumOfSats >= GPS_Parameter.MinSat)) return(1);
212
        else return(0);
216
        else return(0);
213
}
217
}
214
 
218
 
215
//------------------------------------------------------------
219
//------------------------------------------------------------
216
// Checks for manual control action
220
// Checks for manual control action
217
u8 GPS_IsManuallyControlled(void)
221
u8 GPS_IsManuallyControlled(void)
218
{
222
{
219
        if( ( (abs(FC.StickNick) > GPS_Parameter.StickThreshold) || (abs(FC.StickRoll) > GPS_Parameter.StickThreshold)) && (GPS_Parameter.StickThreshold > 0) && (FC.RC_Quality > 150) )
223
        if( ( (abs(FC.StickNick) > GPS_Parameter.StickThreshold) || (abs(FC.StickRoll) > GPS_Parameter.StickThreshold)) && (GPS_Parameter.StickThreshold > 0) && (FC.RC_Quality > 150) )
220
        {
224
        {
221
                NCFlags |= NC_FLAG_MANUAL_CONTROL;
225
                NCFlags |= NC_FLAG_MANUAL_CONTROL;
222
                return(1);
226
                return(1);
223
        }
227
        }
224
        else
228
        else
225
        {
229
        {
226
                NCFlags &= ~NC_FLAG_MANUAL_CONTROL;
230
                NCFlags &= ~NC_FLAG_MANUAL_CONTROL;
227
                return(0);
231
                return(0);
228
        }
232
        }
229
}
233
}
230
 
234
 
231
//------------------------------------------------------------
235
//------------------------------------------------------------
232
// copy GPS position from source position to target position
236
// copy GPS position from source position to target position
233
u8 GPS_CopyPosition(GPS_Pos_t * pGPSPosSrc, GPS_Pos_t* pGPSPosTgt)
237
u8 GPS_CopyPosition(GPS_Pos_t * pGPSPosSrc, GPS_Pos_t* pGPSPosTgt)
234
{
238
{
235
        u8 retval = 0;
239
        u8 retval = 0;
236
        if((pGPSPosSrc == NULL) || (pGPSPosTgt == NULL)) return(retval);        // bad pointer
240
        if((pGPSPosSrc == NULL) || (pGPSPosTgt == NULL)) return(retval);        // bad pointer
237
        // copy only valid positions
241
        // copy only valid positions
238
        if(pGPSPosSrc->Status != INVALID)
242
        if(pGPSPosSrc->Status != INVALID)
239
        {
243
        {
240
                // if the source GPS position is not invalid
244
                // if the source GPS position is not invalid
241
                pGPSPosTgt->Longitude   = pGPSPosSrc->Longitude;
245
                pGPSPosTgt->Longitude   = pGPSPosSrc->Longitude;
242
                pGPSPosTgt->Latitude    = pGPSPosSrc->Latitude;
246
                pGPSPosTgt->Latitude    = pGPSPosSrc->Latitude;
243
                pGPSPosTgt->Altitude    = pGPSPosSrc->Altitude;
247
                pGPSPosTgt->Altitude    = pGPSPosSrc->Altitude;
244
                pGPSPosTgt->Status              = NEWDATA; // mark data in target position as new
248
                pGPSPosTgt->Status              = NEWDATA; // mark data in target position as new
245
                retval = 1;
249
                retval = 1;
246
        }
250
        }
247
        return(retval);
251
        return(retval);
248
}
252
}
249
 
253
 
250
//------------------------------------------------------------
254
//------------------------------------------------------------
251
// clear position data
255
// clear position data
252
u8 GPS_ClearPosition(GPS_Pos_t * pGPSPos)
256
u8 GPS_ClearPosition(GPS_Pos_t * pGPSPos)
253
{
257
{
254
        u8 retval = FALSE;
258
        u8 retval = FALSE;
255
        if(pGPSPos == NULL) return(retval);     // bad pointer
259
        if(pGPSPos == NULL) return(retval);     // bad pointer
256
        else
260
        else
257
        {
261
        {
258
                pGPSPos->Longitude      = 0;
262
                pGPSPos->Longitude      = 0;
259
                pGPSPos->Latitude       = 0;
263
                pGPSPos->Latitude       = 0;
260
                pGPSPos->Altitude       = 0;
264
                pGPSPos->Altitude       = 0;
261
                pGPSPos->Status         = INVALID;
265
                pGPSPos->Status         = INVALID;
262
                retval = TRUE;
266
                retval = TRUE;
263
        }
267
        }
264
        return (retval);
268
        return (retval);
265
}
269
}
266
 
270
 
267
 
271
 
268
//------------------------------------------------------------
272
//------------------------------------------------------------
269
void GPS_Neutral(void)
273
void GPS_Neutral(void)
270
{
274
{
271
        GPS_Stick.Nick  = 0;
275
        GPS_Stick.Nick  = 0;
272
        GPS_Stick.Roll  = 0;
276
        GPS_Stick.Roll  = 0;
273
        GPS_Stick.Yaw   = 0;
277
        GPS_Stick.Yaw   = 0;
274
}
278
}
275
 
279
 
276
//------------------------------------------------------------
280
//------------------------------------------------------------
277
void GPS_Init(void)
281
void GPS_Init(void)
278
{
282
{
279
        SerialPutString("\r\n GPS init...");
283
        SerialPutString("\r\n GPS init...");
280
        UBX_Init();
284
        UBX_Init();
281
        GPS_Neutral();
285
        GPS_Neutral();
282
        GPS_ClearPosition(&GPS_HoldPosition);
286
        GPS_ClearPosition(&GPS_HoldPosition);
283
        GPS_ClearPosition(&GPS_HomePosition);
287
        GPS_ClearPosition(&GPS_HomePosition);
284
        GPS_pTargetPosition = NULL;
288
        GPS_pTargetPosition = NULL;
285
        WPList_Init();
289
        WPList_Init();
286
        GPS_pWaypoint = WPList_Begin();
290
        GPS_pWaypoint = WPList_Begin();
287
        GPS_UpdateParameter();
291
        GPS_UpdateParameter();
288
        SerialPutString("ok");
292
        SerialPutString("ok");
289
}
293
}
290
 
294
 
291
//------------------------------------------------------------
295
//------------------------------------------------------------
292
// calculate the bearing to target position from its deviation
296
// calculate the bearing to target position from its deviation
293
s32 DirectionToTarget_N_E(float northdev, float eastdev)
297
s32 DirectionToTarget_N_E(float northdev, float eastdev)
294
{
298
{
295
        s32 bearing;
299
        s32 bearing;
296
        bearing = (s32)(atan2(northdev, eastdev) / M_PI_180);
300
        bearing = (s32)(atan2(northdev, eastdev) / M_PI_180);
297
        bearing = (270L - bearing)%360L;
301
        bearing = (270L - bearing)%360L;
298
        return(bearing);
302
        return(bearing);
299
}
303
}
300
 
304
 
301
 
305
 
302
//------------------------------------------------------------
306
//------------------------------------------------------------
303
// Rescale xy-vector length if length limit is violated
307
// Rescale xy-vector length if length limit is violated
304
// returns vector len after scaling
308
// returns vector len after scaling
305
s32 GPS_LimitXY(s32 *x, s32 *y, s32 limit)
309
s32 GPS_LimitXY(s32 *x, s32 *y, s32 limit)
306
{
310
{
307
        s32 dist;
311
        s32 dist;
308
 
312
 
309
        dist = (s32)hypot(*x,*y);       // the length of the vector
313
        dist = (s32)hypot(*x,*y);       // the length of the vector
310
        if (dist > limit)
314
        if (dist > limit)
311
        // if vector length is larger than the given limit
315
        // if vector length is larger than the given limit
312
        {       // scale vector compontents so that the length is cut off to limit
316
        {       // scale vector compontents so that the length is cut off to limit
313
                *x = (s32)(( (double)(*x) * (double)limit ) / (double)dist);
317
                *x = (s32)(( (double)(*x) * (double)limit ) / (double)dist);
314
                *y = (s32)(( (double)(*y) * (double)limit ) / (double)dist);
318
                *y = (s32)(( (double)(*y) * (double)limit ) / (double)dist);
315
                dist = limit;
319
                dist = limit;
316
        }
320
        }
317
        return(dist);
321
        return(dist);
318
}
322
}
319
 
323
 
320
//------------------------------------------------------------
324
//------------------------------------------------------------
321
// transform the integer deg into float radians
325
// transform the integer deg into float radians
322
inline double RadiansFromGPS(s32 deg)
326
inline double RadiansFromGPS(s32 deg)
323
{
327
{
324
  return ((double)deg * 1e-7f * M_PI_180); // 1E-7 because deg is the value in ° * 1E7
328
  return ((double)deg * 1e-7f * M_PI_180); // 1E-7 because deg is the value in ° * 1E7
325
}
329
}
326
 
330
 
327
//------------------------------------------------------------
331
//------------------------------------------------------------
328
// transform the integer deg into float deg
332
// transform the integer deg into float deg
329
inline double DegFromGPS(s32 deg)
333
inline double DegFromGPS(s32 deg)
330
{
334
{
331
  return ((double)deg  * 1e-7f); // 1E-7 because deg is the value in ° * 1E7
335
  return ((double)deg  * 1e-7f); // 1E-7 because deg is the value in ° * 1E7
332
}
336
}
333
 
337
 
334
//------------------------------------------------------------
338
//------------------------------------------------------------
335
// calculate the deviation from the current position to the target position
339
// calculate the deviation from the current position to the target position
336
u8 GPS_CalculateDeviation(GPS_Pos_t * pCurrentPos, GPS_Pos_t * pTargetPos, GPS_Deviation_t* pDeviationFromTarget)
340
u8 GPS_CalculateDeviation(GPS_Pos_t * pCurrentPos, GPS_Pos_t * pTargetPos, GPS_Deviation_t* pDeviationFromTarget)
337
{
341
{
338
        double temp1, temp2;
342
        double temp1, temp2;
339
        // if given pointer is NULL
343
        // if given pointer is NULL
340
        if((pCurrentPos == NULL) || (pTargetPos == NULL)) goto baddata;
344
        if((pCurrentPos == NULL) || (pTargetPos == NULL)) goto baddata;
341
        // if positions are invalid
345
        // if positions are invalid
342
        if((pCurrentPos->Status == INVALID) || (pTargetPos->Status == INVALID)) goto baddata;
346
        if((pCurrentPos->Status == INVALID) || (pTargetPos->Status == INVALID)) goto baddata;
343
 
347
 
344
        // The deviation from the current to the target position along north and east direction is
348
        // The deviation from the current to the target position along north and east direction is
345
        // simple the lat/lon difference. To convert that angular deviation into an
349
        // simple the lat/lon difference. To convert that angular deviation into an
346
        // arc length the spherical projection has to be considered.
350
        // arc length the spherical projection has to be considered.
347
        // The mean earth radius is 6371km. Therfore the arc length per latitude degree
351
        // The mean earth radius is 6371km. Therfore the arc length per latitude degree
348
        // is always 6371km * 2 * Pi / 360deg =  111.2 km/deg.
352
        // is always 6371km * 2 * Pi / 360deg =  111.2 km/deg.
349
        // The arc length per longitude degree depends on the correspondig latitude and
353
        // The arc length per longitude degree depends on the correspondig latitude and
350
        // is 111.2km * cos(latitude).
354
        // is 111.2km * cos(latitude).
351
 
355
 
352
        // calculate the shortest longitude deviation from target
356
        // calculate the shortest longitude deviation from target
353
        temp1 = DegFromGPS(pCurrentPos->Longitude) - DegFromGPS(pTargetPos->Longitude);
357
        temp1 = DegFromGPS(pCurrentPos->Longitude) - DegFromGPS(pTargetPos->Longitude);
354
        // outside an angular difference of -180 deg ... +180 deg its shorter to go the other way around
358
        // outside an angular difference of -180 deg ... +180 deg its shorter to go the other way around
355
        // In our application we wont fly more than 20.000 km but along the date line this is important.
359
        // In our application we wont fly more than 20.000 km but along the date line this is important.
356
        if(temp1 > 180.0f) temp1 -= 360.0f;
360
        if(temp1 > 180.0f) temp1 -= 360.0f;
357
        else if (temp1 < -180.0f) temp1 += 360.0f;
361
        else if (temp1 < -180.0f) temp1 += 360.0f;
358
        temp1 *= cos((RadiansFromGPS(pTargetPos->Latitude) + RadiansFromGPS(pCurrentPos->Latitude))/2);
362
        temp1 *= cos((RadiansFromGPS(pTargetPos->Latitude) + RadiansFromGPS(pCurrentPos->Latitude))/2);
359
        // calculate latitude deviation from target
363
        // calculate latitude deviation from target
360
        // this is allways within -180 deg ... 180 deg
364
        // this is allways within -180 deg ... 180 deg
361
        temp2 = DegFromGPS(pCurrentPos->Latitude) - DegFromGPS(pTargetPos->Latitude);
365
        temp2 = DegFromGPS(pCurrentPos->Latitude) - DegFromGPS(pTargetPos->Latitude);
362
        // deviation from target position in cm
366
        // deviation from target position in cm
363
        // i.e. the distance to walk from the target in northern and eastern direction to reach the current position
367
        // i.e. the distance to walk from the target in northern and eastern direction to reach the current position
364
 
368
 
365
        pDeviationFromTarget->Status = INVALID;
369
        pDeviationFromTarget->Status = INVALID;
366
        pDeviationFromTarget->North = (s32)(11119492.7f * temp2);
370
        pDeviationFromTarget->North = (s32)(11119492.7f * temp2);
367
        pDeviationFromTarget->East  = (s32)(11119492.7f * temp1);
371
        pDeviationFromTarget->East  = (s32)(11119492.7f * temp1);
368
        // If the position deviation is small enough to neglect the earth curvature
372
        // If the position deviation is small enough to neglect the earth curvature
369
        // (this is for our application always fulfilled) the distance to target
373
        // (this is for our application always fulfilled) the distance to target
370
        // can be calculated by the pythagoras of north and east deviation.
374
        // can be calculated by the pythagoras of north and east deviation.
371
        pDeviationFromTarget->Distance = (s32)(11119492.7f * hypot(temp1, temp2));
375
        pDeviationFromTarget->Distance = (s32)(11119492.7f * hypot(temp1, temp2));
372
        if (pDeviationFromTarget->Distance == 0L) pDeviationFromTarget->Bearing = 0L;
376
        if (pDeviationFromTarget->Distance == 0L) pDeviationFromTarget->Bearing = 0L;
373
        else pDeviationFromTarget->Bearing = DirectionToTarget_N_E(temp2, temp1);
377
        else pDeviationFromTarget->Bearing = DirectionToTarget_N_E(temp2, temp1);
374
        pDeviationFromTarget->Status = NEWDATA;
378
        pDeviationFromTarget->Status = NEWDATA;
375
        return TRUE;
379
        return TRUE;
376
 
380
 
377
        baddata:
381
        baddata:
378
        pDeviationFromTarget->North     = 0L;
382
        pDeviationFromTarget->North     = 0L;
379
        pDeviationFromTarget->East              = 0L;
383
        pDeviationFromTarget->East              = 0L;
380
        pDeviationFromTarget->Distance  = 0L;
384
        pDeviationFromTarget->Distance  = 0L;
381
        pDeviationFromTarget->Bearing   = 0L;
385
        pDeviationFromTarget->Bearing   = 0L;
382
        pDeviationFromTarget->Status = INVALID;
386
        pDeviationFromTarget->Status = INVALID;
383
        return FALSE;
387
        return FALSE;
384
}
388
}
385
 
389
 
386
//------------------------------------------------------------
390
//------------------------------------------------------------
387
void GPS_Navigation(void)
391
void GPS_Navigation(void)
388
{
392
{
389
        static u32 beep_rythm;
393
        static u32 beep_rythm;
390
        static u32 GPSDataTimeout = 0;
394
        static u32 GPSDataTimeout = 0;
391
 
395
 
392
        // pointer to current target position
396
        // pointer to current target position
393
        static GPS_Pos_t * pTargetPositionOld = NULL;
397
        static GPS_Pos_t * pTargetPositionOld = NULL;
394
        static Waypoint_t* GPS_pWaypointOld = NULL;
398
        static Waypoint_t* GPS_pWaypointOld = NULL;
395
 
399
 
396
        static GPS_Pos_t RangedTargetPosition = {0,0,0, INVALID};               // the limited target position, this is derived from the target position with repect to the operating radius
400
        static GPS_Pos_t RangedTargetPosition = {0,0,0, INVALID};               // the limited target position, this is derived from the target position with repect to the operating radius
397
        static s32 OperatingRadiusOld = -1;
401
        static s32 OperatingRadiusOld = -1;
398
        static u32 WPTime = 0;
402
        static u32 WPTime = 0;
399
 
403
 
400
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
404
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
401
        //+ Check for new data from GPS-receiver
405
        //+ Check for new data from GPS-receiver
402
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
406
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
403
        switch(GPSData.Status)
407
        switch(GPSData.Status)
404
        {
408
        {
405
                case INVALID: // no gps data available
409
                case INVALID: // no gps data available
406
                        // do nothing
410
                        // do nothing
407
                        GPS_Parameter.PID_Limit = 0; // disables PID output
411
                        GPS_Parameter.PID_Limit = 0; // disables PID output
408
                        break;
412
                        break;
409
 
413
 
410
                case PROCESSED: // the current data have been allready processed
414
                case PROCESSED: // the current data have been allready processed
411
                        // if no new data are available within the timeout switch to invalid state.
415
                        // if no new data are available within the timeout switch to invalid state.
412
                        if(CheckDelay(GPSDataTimeout)) GPSData.Status = INVALID;
416
                        if(CheckDelay(GPSDataTimeout)) GPSData.Status = INVALID;
413
                        // wait for new gps data
417
                        // wait for new gps data
414
                        break;
418
                        break;
415
 
419
 
416
                case NEWDATA: // handle new gps data
420
                case NEWDATA: // handle new gps data
417
 
421
 
418
                // update GPS Parameter from FC-Data via SPI interface
422
                // update GPS Parameter from FC-Data via SPI interface
419
                GPS_UpdateParameter();
423
                GPS_UpdateParameter();
420
 
424
 
421
                        // wait maximum of 3 times the normal data update time before data timemout
425
                        // wait maximum of 3 times the normal data update time before data timemout
422
                        GPSDataTimeout = SetDelay(3 * GPS_UPDATETIME_MS);
426
                        GPSDataTimeout = SetDelay(3 * GPS_UPDATETIME_MS);
423
                        beep_rythm++;
427
                        beep_rythm++;
424
 
428
 
425
                        // debug
429
                        // debug
426
                        DebugOut.Analog[21] = (s16)GPSData.Speed_North;
430
                        DebugOut.Analog[21] = (s16)GPSData.Speed_North;
427
                        DebugOut.Analog[22] = (s16)GPSData.Speed_East;
431
                        DebugOut.Analog[22] = (s16)GPSData.Speed_East;
428
                        DebugOut.Analog[31] = (s16)GPSData.NumOfSats;
432
                        DebugOut.Analog[31] = (s16)GPSData.NumOfSats;
429
 
433
 
430
                        // If GPS signal condition is sufficient for a reliable position measurement
434
                        // If GPS signal condition is sufficient for a reliable position measurement
431
                        if(GPS_IsSignalOK())
435
                        if(GPS_IsSignalOK())
432
                        {
436
                        {
433
                                // update home deviation info
437
                                // update home deviation info
434
                                GPS_CalculateDeviation(&(GPSData.Position), &GPS_HomePosition, &CurrentHomeDeviation);
438
                                GPS_CalculateDeviation(&(GPSData.Position), &GPS_HomePosition, &CurrentHomeDeviation);
435
 
439
 
436
                                // if the MK is starting or the home position is invalid then store the home position
440
                                // if the MK is starting or the home position is invalid then store the home position
437
                                if((FC.MKFlags & MKFLAG_START) || (GPS_HomePosition.Status == INVALID))
441
                                if((FC.MKFlags & MKFLAG_START) || (GPS_HomePosition.Status == INVALID))
438
                                {       // try to update the home position from the current position
442
                                {       // try to update the home position from the current position
439
                                        if(GPS_CopyPosition(&(GPSData.Position), &GPS_HomePosition))
443
                                        if(GPS_CopyPosition(&(GPSData.Position), &GPS_HomePosition))
440
                                        {
444
                                        {
441
                                                BeepTime = 700; // beep on success
445
                                                BeepTime = 700; // beep on success
442
                                                GPS_CopyPosition(&GPS_HomePosition, &(NaviData.HomePosition));
446
                                                GPS_CopyPosition(&GPS_HomePosition, &(NaviData.HomePosition));
443
                                        }
447
                                        }
444
                                        GPS_pWaypoint = WPList_Begin(); // go to start of waypoint list, return NULL of the list is empty
448
                                        GPS_pWaypoint = WPList_Begin(); // go to start of waypoint list, return NULL of the list is empty
445
                                }
449
                                }
446
 
450
 
447
                                /* The selected flight mode influences the target position pointer and therefore the behavior */
451
                                /* The selected flight mode influences the target position pointer and therefore the behavior */
448
 
452
 
449
                                // check for current flight mode and set the target pointer GPS_pTargetPosition respectively
453
                                // check for current flight mode and set the target pointer GPS_pTargetPosition respectively
450
                                switch(GPS_Parameter.FlightMode)
454
                                switch(GPS_Parameter.FlightMode)
451
                                {
455
                                {
452
                                        // the GPS control is deactived
456
                                        // the GPS control is deactived
453
                                        case GPS_FLIGHT_MODE_FREE:
457
                                        case GPS_FLIGHT_MODE_FREE:
454
 
458
 
455
                                                GPS_Parameter.PID_Limit = 0; // disables PID output
459
                                                GPS_Parameter.PID_Limit = 0; // disables PID output
456
                                                // update hold position
460
                                                // update hold position
457
                                                GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition);
461
                                                GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition);
458
                                                // no target position
462
                                                // no target position
459
                                                GPS_pTargetPosition = NULL;
463
                                                GPS_pTargetPosition = NULL;
460
                                                GPS_TargetRadius = 0;
464
                                                GPS_TargetRadius = 0;
461
                                                break;
465
                                                break;
462
 
466
 
463
                                        // the GPS supports the position hold, if the pilot takes no action
467
                                        // the GPS supports the position hold, if the pilot takes no action
464
                                        case GPS_FLIGHT_MODE_AID:
468
                                        case GPS_FLIGHT_MODE_AID:
465
 
469
 
466
                                                // reset WPList to begin
470
                                                // reset WPList to begin
467
                                                GPS_pWaypoint = WPList_Begin();
471
                                                GPS_pWaypoint = WPList_Begin();
468
 
472
 
469
                                                if(GPS_IsManuallyControlled())
473
                                                if(GPS_IsManuallyControlled())
470
                                                {
474
                                                {
471
                                                        GPS_Parameter.PID_Limit = 0; // disables PID output, as long as the manual conrol is active
475
                                                        GPS_Parameter.PID_Limit = 0; // disables PID output, as long as the manual conrol is active
472
                                                    GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition);
476
                                                    GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition);
473
                                                        GPS_pTargetPosition = NULL;
477
                                                        GPS_pTargetPosition = NULL;
474
                                                        GPS_TargetRadius = 0;
478
                                                        GPS_TargetRadius = 0;
475
                                                }
479
                                                }
476
                                                else
480
                                                else
477
                                                {
481
                                                {
478
                                                        GPS_pTargetPosition = &GPS_HoldPosition;
482
                                                        GPS_pTargetPosition = &GPS_HoldPosition;
479
                                                        GPS_TargetRadius = 100; // 1 meter
483
                                                        GPS_TargetRadius = 100; // 1 meter
480
                                                }
484
                                                }
481
                                                break;
485
                                                break;
482
 
486
 
483
                                        // the GPS control is directed to a target position
487
                                        // the GPS control is directed to a target position
484
                                        // given by a waypoint or by the home position
488
                                        // given by a waypoint or by the home position
485
                                        case GPS_FLIGHT_MODE_WAYPOINT:
489
                                        case GPS_FLIGHT_MODE_WAYPOINT:
486
 
490
 
487
                                                if(GPS_IsManuallyControlled()) // the human pilot takes the action
491
                                                if(GPS_IsManuallyControlled()) // the human pilot takes the action
488
                                                {
492
                                                {
489
                                                        GPS_Parameter.PID_Limit = 0; // disables PID output, as long as the manual conrol is active
493
                                                        GPS_Parameter.PID_Limit = 0; // disables PID output, as long as the manual conrol is active
490
                                                    GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition);  // update hold position
494
                                                    GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition);  // update hold position
491
                                                        GPS_pTargetPosition = NULL;     // set target position invalid
495
                                                        GPS_pTargetPosition = NULL;     // set target position invalid
492
                                                        GPS_TargetRadius = 0;
496
                                                        GPS_TargetRadius = 0;
493
                                                }
497
                                                }
494
                                                else // no manual control  -> gps position hold active
498
                                                else // no manual control  -> gps position hold active
495
                                                {
499
                                                {
496
                                                        // waypoint trigger logic
500
                                                        // waypoint trigger logic
497
                                                        if(GPS_pWaypoint != NULL) // waypoint exist
501
                                                        if(GPS_pWaypoint != NULL) // waypoint exist
498
                                                        {
502
                                                        {
499
                                                                if(GPS_pWaypoint->Position.Status == INVALID) // should never happen
503
                                                                if(GPS_pWaypoint->Position.Status == INVALID) // should never happen
500
                                                                {
504
                                                                {
501
                                                                        GPS_pWaypoint = WPList_Next(); // goto to next WP
505
                                                                        GPS_pWaypoint = WPList_Next(); // goto to next WP
502
                                                                        BeepTime = 255;
506
                                                                        BeepTime = 255;
503
                                                                }
507
                                                                }
504
                                                                else // waypoint position is valid
508
                                                                else // waypoint position is valid
505
                                                                {
509
                                                                {
506
                                                                        // check if the pointer to the waypoint has been changed or the data have been updated
510
                                                                        // check if the pointer to the waypoint has been changed or the data have been updated
507
                                                                        if((GPS_pWaypoint != GPS_pWaypointOld) || (GPS_pWaypoint->Position.Status == NEWDATA))
511
                                                                        if((GPS_pWaypoint != GPS_pWaypointOld) || (GPS_pWaypoint->Position.Status == NEWDATA))
508
                                                                        {
512
                                                                        {
509
                                                                                GPS_pWaypointOld = GPS_pWaypoint;
513
                                                                                GPS_pWaypointOld = GPS_pWaypoint;
510
                                                                        }
514
                                                                        }
511
                                                                        // if WP has been reached once, wait hold time before trigger to next one
515
                                                                        // if WP has been reached once, wait hold time before trigger to next one
512
                                                                        if(NCFlags & NC_FLAG_TARGET_REACHED)
516
                                                                        if(NCFlags & NC_FLAG_TARGET_REACHED)
513
                                                                        {
517
                                                                        {
514
                                                                                /* ToDo: Adjust GPS_pWaypoint->Heading, GPS_pWaypoint->Event handling */
518
                                                                                /* ToDo: Adjust GPS_pWaypoint->Heading, GPS_pWaypoint->Event handling */
515
                                                                                if(CheckDelay(WPTime))
519
                                                                                if(CheckDelay(WPTime))
516
                                                                                {
520
                                                                                {
517
                                                                                        GPS_pWaypoint = WPList_Next(); // goto to next waypoint, return NULL if end of list has been reached
521
                                                                                        GPS_pWaypoint = WPList_Next(); // goto to next waypoint, return NULL if end of list has been reached
518
                                                                                }
522
                                                                                }
519
                                                                        } // EOF if(WPArrived)
523
                                                                        } // EOF if(WPArrived)
520
                                                                        else
524
                                                                        else
521
                                                                        {
525
                                                                        {
522
                                                                                WPTime = SetDelay(GPS_pWaypoint->HoldTime * 1000); // set hold time stamp
526
                                                                                WPTime = SetDelay(GPS_pWaypoint->HoldTime * 1000); // set hold time stamp
523
                                                                        }
527
                                                                        }
524
                                                                }
528
                                                                }
525
                                                        } // EOF waypoint trigger logic
529
                                                        } // EOF waypoint trigger logic
526
 
530
 
527
                                                        if(GPS_pWaypoint != NULL) // Waypoint exist
531
                                                        if(GPS_pWaypoint != NULL) // Waypoint exist
528
                                                        {
532
                                                        {
529
                                                                // update the hold position
533
                                                                // update the hold position
530
                                                                GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition);
534
                                                                GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition);
531
                                                                GPS_pTargetPosition = &(GPS_pWaypoint->Position);
535
                                                                GPS_pTargetPosition = &(GPS_pWaypoint->Position);
532
                                                                GPS_TargetRadius = (s32)(GPS_pWaypoint->ToleranceRadius) * 100L;
536
                                                                GPS_TargetRadius = (s32)(GPS_pWaypoint->ToleranceRadius) * 100L;
533
 
537
 
534
                                                        }
538
                                                        }
535
                                                        else // no waypoint info available, i.e. the WPList is empty or the end of the list has been reached
539
                                                        else // no waypoint info available, i.e. the WPList is empty or the end of the list has been reached
536
                                                        {
540
                                                        {
537
                                                                // fly back to home postion
541
                                                                // fly back to home postion
538
                                                                if(GPS_HomePosition.Status == INVALID)
542
                                                                if(GPS_HomePosition.Status == INVALID)
539
                                                                {
543
                                                                {
540
                                                                        GPS_pTargetPosition = &GPS_HoldPosition; // fall back to hold mode if home position is not available
544
                                                                        GPS_pTargetPosition = &GPS_HoldPosition; // fall back to hold mode if home position is not available
541
                                                                        GPS_TargetRadius = 100;
545
                                                                        GPS_TargetRadius = 100;
542
                                                                        BeepTime = 255; // beep to indicate missin home position
546
                                                                        BeepTime = 255; // beep to indicate missin home position
543
                                                                }
547
                                                                }
544
                                                                else // the home position is valid
548
                                                                else // the home position is valid
545
                                                                {
549
                                                                {
546
                                                                        // update the hold position
550
                                                                        // update the hold position
547
                                                                        GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition);
551
                                                                        GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition);
548
                                                                        // set target to home position
552
                                                                        // set target to home position
549
                                                                        GPS_pTargetPosition = &GPS_HomePosition;
553
                                                                        GPS_pTargetPosition = &GPS_HomePosition;
550
                                                                        GPS_TargetRadius = 100;
554
                                                                        GPS_TargetRadius = 100;
551
                                                                }
555
                                                                }
552
                                                        }
556
                                                        }
553
                                                } // EOF no manual control
557
                                                } // EOF no manual control
554
                                                break;
558
                                                break;
555
 
559
 
556
                                        case GPS_FLIGHT_MODE_UNDEF:
560
                                        case GPS_FLIGHT_MODE_UNDEF:
557
                                        default:
561
                                        default:
558
                                                GPS_Parameter.PID_Limit = 0; // disables PID output
562
                                                GPS_Parameter.PID_Limit = 0; // disables PID output
559
                                                // update hold position
563
                                                // update hold position
560
                                                GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition);
564
                                                GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition);
561
                                                // no target position
565
                                                // no target position
562
                                                GPS_pTargetPosition = NULL;
566
                                                GPS_pTargetPosition = NULL;
563
                                                GPS_TargetRadius = 0;
567
                                                GPS_TargetRadius = 0;
564
                                                break;
568
                                                break;
565
 
569
 
566
                                }// EOF GPS Mode Handling
570
                                }// EOF GPS Mode Handling
567
 
571
 
568
 
572
 
569
                                /* Calculation of range target based on the real target */
573
                                /* Calculation of range target based on the real target */
570
 
574
 
571
                                // if no target position exist clear the ranged target position
575
                                // if no target position exist clear the ranged target position
572
                                if(GPS_pTargetPosition == NULL) GPS_ClearPosition(&RangedTargetPosition);
576
                                if(GPS_pTargetPosition == NULL) GPS_ClearPosition(&RangedTargetPosition);
573
                                else
577
                                else
574
                                {       // if the target position has been changed or the value has been updated or the OperatingRadius has changed
578
                                {       // if the target position has been changed or the value has been updated or the OperatingRadius has changed
575
                                        if((GPS_pTargetPosition != pTargetPositionOld)  || (GPS_pTargetPosition->Status == NEWDATA) || (GPS_Parameter.OperatingRadius != OperatingRadiusOld) )
579
                                        if((GPS_pTargetPosition != pTargetPositionOld)  || (GPS_pTargetPosition->Status == NEWDATA) || (GPS_Parameter.OperatingRadius != OperatingRadiusOld) )
576
                                        {
580
                                        {
577
                                                BeepTime = 255; // beep to indicate setting of a new target position
581
                                                BeepTime = 255; // beep to indicate setting of a new target position
578
                                                NCFlags &= ~NC_FLAG_TARGET_REACHED;     // clear target reached flag
582
                                                NCFlags &= ~NC_FLAG_TARGET_REACHED;     // clear target reached flag
579
                                                // calculate deviation of new target position from home position
583
                                                // calculate deviation of new target position from home position
580
                                                if(GPS_CalculateDeviation(GPS_pTargetPosition, &GPS_HomePosition, &TargetHomeDeviation))
584
                                                if(GPS_CalculateDeviation(GPS_pTargetPosition, &GPS_HomePosition, &TargetHomeDeviation))
581
                                                {
585
                                                {
582
                                                        // check distance from home position
586
                                                        // check distance from home position
583
                                                        if(TargetHomeDeviation.Distance > GPS_Parameter.OperatingRadius)
587
                                                        if(TargetHomeDeviation.Distance > GPS_Parameter.OperatingRadius)
584
                                                        {
588
                                                        {
585
                                                                //calculate ranged target position to be within the operation radius area
589
                                                                //calculate ranged target position to be within the operation radius area
586
                                                                NCFlags |= NC_FLAG_RANGE_LIMIT;
590
                                                                NCFlags |= NC_FLAG_RANGE_LIMIT;
587
 
591
 
588
                                                                TargetHomeDeviation.North = (s32)(((float)TargetHomeDeviation.North * (float)GPS_Parameter.OperatingRadius) / (float)TargetHomeDeviation.Distance);
592
                                                                TargetHomeDeviation.North = (s32)(((float)TargetHomeDeviation.North * (float)GPS_Parameter.OperatingRadius) / (float)TargetHomeDeviation.Distance);
589
                                                                TargetHomeDeviation.East = (s32)(((float)TargetHomeDeviation.East * (float)GPS_Parameter.OperatingRadius) / (float)TargetHomeDeviation.Distance);
593
                                                                TargetHomeDeviation.East = (s32)(((float)TargetHomeDeviation.East * (float)GPS_Parameter.OperatingRadius) / (float)TargetHomeDeviation.Distance);
590
                                                                TargetHomeDeviation.Distance = GPS_Parameter.OperatingRadius;
594
                                                                TargetHomeDeviation.Distance = GPS_Parameter.OperatingRadius;
591
 
595
 
592
                                                                RangedTargetPosition.Status = INVALID;
596
                                                                RangedTargetPosition.Status = INVALID;
593
                                                                RangedTargetPosition.Latitude = GPS_HomePosition.Latitude;
597
                                                                RangedTargetPosition.Latitude = GPS_HomePosition.Latitude;
594
                                                                RangedTargetPosition.Latitude += (s32)((float)TargetHomeDeviation.North / 1.11194927f);
598
                                                                RangedTargetPosition.Latitude += (s32)((float)TargetHomeDeviation.North / 1.11194927f);
595
                                                                RangedTargetPosition.Longitude = GPS_HomePosition.Longitude;
599
                                                                RangedTargetPosition.Longitude = GPS_HomePosition.Longitude;
596
                                                                RangedTargetPosition.Longitude += (s32)((float)TargetHomeDeviation.East / (1.11194927f * cos(RadiansFromGPS(GPS_HomePosition.Latitude))) );
600
                                                                RangedTargetPosition.Longitude += (s32)((float)TargetHomeDeviation.East / (1.11194927f * cos(RadiansFromGPS(GPS_HomePosition.Latitude))) );
597
                                                                RangedTargetPosition.Altitude = GPS_pTargetPosition->Altitude;
601
                                                                RangedTargetPosition.Altitude = GPS_pTargetPosition->Altitude;
598
                                                                RangedTargetPosition.Status = NEWDATA;
602
                                                                RangedTargetPosition.Status = NEWDATA;
599
                                                        }
603
                                                        }
600
                                                        else
604
                                                        else
601
                                                        {       // the target is located within the operation radius area
605
                                                        {       // the target is located within the operation radius area
602
                                                                // simple copy the loaction to the ranged target position
606
                                                                // simple copy the loaction to the ranged target position
603
                                                                GPS_CopyPosition(GPS_pTargetPosition, &RangedTargetPosition);
607
                                                                GPS_CopyPosition(GPS_pTargetPosition, &RangedTargetPosition);
604
                                                                NCFlags &= ~NC_FLAG_RANGE_LIMIT;
608
                                                                NCFlags &= ~NC_FLAG_RANGE_LIMIT;
605
                                                        }
609
                                                        }
606
                                                }
610
                                                }
607
                                                else
611
                                                else
608
                                                {       // deviation could not be determined
612
                                                {       // deviation could not be determined
609
                                                        GPS_ClearPosition(&RangedTargetPosition);
613
                                                        GPS_ClearPosition(&RangedTargetPosition);
610
                                                }
614
                                                }
611
                                                GPS_pTargetPosition->Status = PROCESSED;        // mark current target as processed!
615
                                                GPS_pTargetPosition->Status = PROCESSED;        // mark current target as processed!
612
                                        }
616
                                        }
613
                                }
617
                                }
614
                                OperatingRadiusOld = GPS_Parameter.OperatingRadius;
618
                                OperatingRadiusOld = GPS_Parameter.OperatingRadius;
615
                                // remember last target position pointer
619
                                // remember last target position pointer
616
                                pTargetPositionOld = GPS_pTargetPosition;
620
                                pTargetPositionOld = GPS_pTargetPosition;
617
 
621
 
618
                                /* Calculate position deviation from ranged target */
622
                                /* Calculate position deviation from ranged target */
619
 
623
 
620
                                // calculate deviation of current position to ranged target position in cm
624
                                // calculate deviation of current position to ranged target position in cm
621
                                if(GPS_CalculateDeviation(&(GPSData.Position), &RangedTargetPosition, &CurrentTargetDeviation))
625
                                if(GPS_CalculateDeviation(&(GPSData.Position), &RangedTargetPosition, &CurrentTargetDeviation))
622
                                {       // set target reached flag of we once reached the target point
626
                                {       // set target reached flag of we once reached the target point
623
                                        if(!(NCFlags & NC_FLAG_TARGET_REACHED) && (CurrentTargetDeviation.Distance < GPS_TargetRadius))
627
                                        if(!(NCFlags & NC_FLAG_TARGET_REACHED) && (CurrentTargetDeviation.Distance < GPS_TargetRadius))
624
                                        {
628
                                        {
625
                                                NCFlags |= NC_FLAG_TARGET_REACHED;      // set target reached flag
629
                                                NCFlags |= NC_FLAG_TARGET_REACHED;      // set target reached flag
626
                                        }
630
                                        }
627
                                        // implement your control code here based
631
                                        // implement your control code here based
628
                                        // in the info available in the CurrentTargetDeviation, GPSData and FromFlightCtrl.GyroHeading
632
                                        // in the info available in the CurrentTargetDeviation, GPSData and FromFlightCtrl.GyroHeading
629
                                        GPS_Stick.Nick = 0;
633
                                        GPS_Stick.Nick = 0;
630
                                        GPS_Stick.Roll = 0;
634
                                        GPS_Stick.Roll = 0;
631
                                        GPS_Stick.Yaw  = 0;
635
                                        GPS_Stick.Yaw  = 0;
632
                                }
636
                                }
633
                                else // deviation could not be calculated
637
                                else // deviation could not be calculated
634
                                {   // do nothing on gps sticks!
638
                                {   // do nothing on gps sticks!
635
                                        GPS_Neutral();
639
                                        GPS_Neutral();
-
 
640
                                        NCFlags &= ~NC_FLAG_TARGET_REACHED;     // clear target reached
636
                                }
641
                                }
637
 
642
 
638
                        }// eof if GPSSignal is OK
643
                        }// eof if GPSSignal is OK
639
                        else // GPSSignal not OK
644
                        else // GPSSignal not OK
640
                        {
645
                        {
641
                                GPS_Neutral();
646
                                GPS_Neutral();
642
                                // beep if signal is not sufficient
647
                                // beep if signal is not sufficient
643
                                if(GPS_Parameter.FlightMode != GPS_FLIGHT_MODE_FREE)
648
                                if(GPS_Parameter.FlightMode != GPS_FLIGHT_MODE_FREE)
644
                                {
649
                                {
645
                                        if(!(GPSData.Flags & FLAG_GPSFIXOK) && !(beep_rythm % 5)) BeepTime = 100;
650
                                        if(!(GPSData.Flags & FLAG_GPSFIXOK) && !(beep_rythm % 5)) BeepTime = 100;
646
                                        else if (GPSData.NumOfSats < GPS_Parameter.MinSat && !(beep_rythm % 5)) BeepTime = 10;
651
                                        else if (GPSData.NumOfSats < GPS_Parameter.MinSat && !(beep_rythm % 5)) BeepTime = 10;
647
                                }
652
                                }
648
                        }
653
                        }
649
                    GPSData.Status = PROCESSED; // mark as processed
654
                        GPSData.Status = PROCESSED; // mark as processed
650
                        break;
655
                        break;
651
        }
656
        }
652
 
657
 
653
        DebugOut.Analog[6] = NCFlags;
658
        DebugOut.Analog[6] = NCFlags;
654
        DebugOut.Analog[27] = (s16)CurrentTargetDeviation.North;
659
        DebugOut.Analog[27] = (s16)CurrentTargetDeviation.North;
655
        DebugOut.Analog[28] = (s16)CurrentTargetDeviation.East;
660
        DebugOut.Analog[28] = (s16)CurrentTargetDeviation.East;
656
        DebugOut.Analog[29] = GPS_Stick.Nick;
661
        DebugOut.Analog[29] = GPS_Stick.Nick;
657
        DebugOut.Analog[30] = GPS_Stick.Roll;
662
        DebugOut.Analog[30] = GPS_Stick.Roll;
658
 
663
 
659
        // update navi data, send back to ground station
664
        // update navi data, send back to ground station
660
        GPS_CopyPosition(&(GPSData.Position),   &(NaviData.CurrentPosition));
665
        GPS_CopyPosition(&(GPSData.Position),   &(NaviData.CurrentPosition));
661
        GPS_CopyPosition(&RangedTargetPosition, &(NaviData.TargetPosition));
666
        GPS_CopyPosition(&RangedTargetPosition, &(NaviData.TargetPosition));
662
        GPS_CopyPosition(&GPS_HomePosition,     &(NaviData.HomePosition));
667
        GPS_CopyPosition(&GPS_HomePosition,     &(NaviData.HomePosition));
663
        NaviData.SatsInUse = GPSData.NumOfSats;
668
        NaviData.SatsInUse = GPSData.NumOfSats;
664
        NaviData.TargetPositionDeviation.Distance = (u16)CurrentTargetDeviation.Distance/10; // dm
669
        NaviData.TargetPositionDeviation.Distance = (u16)CurrentTargetDeviation.Distance/10; // dm
665
        NaviData.TargetPositionDeviation.Bearing  = (s16)CurrentTargetDeviation.Bearing;
670
        NaviData.TargetPositionDeviation.Bearing  = (s16)CurrentTargetDeviation.Bearing;
666
        NaviData.HomePositionDeviation.Distance   = (u16)CurrentHomeDeviation.Distance/10; // dm
671
        NaviData.HomePositionDeviation.Distance   = (u16)CurrentHomeDeviation.Distance/10; // dm
667
        NaviData.HomePositionDeviation.Bearing    = (s16)CurrentHomeDeviation.Bearing;
672
        NaviData.HomePositionDeviation.Bearing    = (s16)CurrentHomeDeviation.Bearing;
668
        NaviData.UBat = FC.UBat;
673
        NaviData.UBat = FC.UBat;
669
        NaviData.GroundSpeed = (u16)GPSData.Speed_Ground;
674
        NaviData.GroundSpeed = (u16)GPSData.Speed_Ground;
670
        NaviData.Heading = (s16)(GPSData.Heading/100000L);
675
        NaviData.Heading = (s16)(GPSData.Heading/100000L);
671
        NaviData.CompassHeading = (s16)FromFlightCtrl.GyroHeading/10; // in deg
676
        NaviData.CompassHeading = (s16)FromFlightCtrl.GyroHeading/10; // in deg
672
        NaviData.AngleNick = FromFlightCtrl.AngleNick / 10;        // in deg
677
        NaviData.AngleNick = FromFlightCtrl.AngleNick / 10;        // in deg
673
        NaviData.AngleRoll = FromFlightCtrl.AngleRoll / 10;        // in deg
678
        NaviData.AngleRoll = FromFlightCtrl.AngleRoll / 10;        // in deg
674
        NaviData.RC_Quality = (u8)FC.RC_Quality;
679
        NaviData.RC_Quality = (u8)FC.RC_Quality;
675
        NaviData.MKFlags = (u8)FC.MKFlags;
680
        NaviData.MKFlags = (u8)FC.MKFlags;
676
        NaviData.NCFlags = NCFlags;
681
        NaviData.NCFlags = NCFlags;
677
        NaviData.OperatingRadius = Parameter.NaviOperatingRadius;
682
        NaviData.OperatingRadius = Parameter.NaviOperatingRadius;
678
        NaviData.TopSpeed = (s16)GPSData.Speed_Top;  // in cm/s
683
        NaviData.TopSpeed = (s16)GPSData.Speed_Top;  // in cm/s
679
        NaviData.TargetHoldTime = (u8)(GetDelay(WPTime)/1000); // in s
684
        NaviData.TargetHoldTime = (u8)(GetDelay(WPTime)/1000); // in s
680
        //+++++++++++++++++++++++++++++++++++++++++++++++++++
685
        //+++++++++++++++++++++++++++++++++++++++++++++++++++
681
        return;
686
        return;
682
}
687
}
683
 
688
 
684
 
689