Rev 89 | Rev 93 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 89 | Rev 92 | ||
---|---|---|---|
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 | u32 P_Limit; |
99 | s32 I_Limit; |
99 | u32 I_Limit; |
100 | s32 D_Limit; |
100 | u32 D_Limit; |
101 | s32 PID_Limit; |
101 | u32 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 | u32 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 | u32 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 | Waypoint_t* GPS_pWaypoint = NULL; // pointer to the actual waypoint |
131 | Waypoint_t* GPS_pWaypoint = NULL; // pointer to the actual waypoint |
131 | 132 | ||
132 | //------------------------------------------------------------- |
133 | //------------------------------------------------------------- |
133 | // Update GPSParamter |
134 | // Update GPSParamter |
134 | void GPS_UpdateParameter(void) |
135 | void GPS_UpdateParameter(void) |
135 | { |
136 | { |
136 | static GPS_FlightMode_t FlightMode_Old = GPS_FLIGHT_MODE_UNDEF; |
137 | static GPS_FlightMode_t FlightMode_Old = GPS_FLIGHT_MODE_UNDEF; |
137 | // in case of bad receiving conditions |
138 | // in case of bad receiving conditions |
138 | if(FC.RC_Quality < 100) |
139 | if(FC.RC_Quality < 100) |
139 | { // set fixed parameter |
140 | { // set fixed parameter |
140 | GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_FREE; |
141 | GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_FREE; |
141 | GPS_Parameter.Gain = (float) 100; |
142 | GPS_Parameter.Gain = (float) 100; |
142 | GPS_Parameter.P = (float) 90; |
143 | GPS_Parameter.P = (float) 90; |
143 | GPS_Parameter.I = (float) 90; |
144 | GPS_Parameter.I = (float) 90; |
144 | GPS_Parameter.D = (float) 90; |
145 | GPS_Parameter.D = (float) 90; |
145 | GPS_Parameter.A = (float) 90; |
146 | GPS_Parameter.A = (float) 90; |
146 | GPS_Parameter.ACC = (float) 0; |
147 | GPS_Parameter.ACC = (float) 0; |
147 | GPS_Parameter.P_Limit = 90; |
148 | GPS_Parameter.P_Limit = 90; |
148 | GPS_Parameter.I_Limit = 90; |
149 | GPS_Parameter.I_Limit = 90; |
149 | GPS_Parameter.D_Limit = 90; |
150 | GPS_Parameter.D_Limit = 90; |
150 | GPS_Parameter.PID_Limit = 200; |
151 | GPS_Parameter.PID_Limit = 200; |
151 | GPS_Parameter.BrakingDuration = 0; |
152 | GPS_Parameter.BrakingDuration = 0; |
152 | GPS_Parameter.SpeedCompensation = (float) 30; |
153 | GPS_Parameter.SpeedCompensation = (float) 30; |
153 | GPS_Parameter.MinSat = 6; |
154 | GPS_Parameter.MinSat = 6; |
154 | GPS_Parameter.StickThreshold = 8; |
155 | GPS_Parameter.StickThreshold = 8; |
155 | GPS_Parameter.WindCorrection = 0.0; |
156 | GPS_Parameter.WindCorrection = 0.0; |
156 | 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 |
157 | 158 | ||
158 | } |
159 | } |
159 | else |
160 | else |
160 | { |
161 | { |
161 | // update parameter from FC |
162 | // update parameter from FC |
162 | if(StopNavigation) GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_FREE; |
163 | if(StopNavigation) GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_FREE; |
163 | else |
164 | else |
164 | { |
165 | { |
165 | if (Parameter.NaviGpsModeControl < 50) GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_AID; |
166 | if (Parameter.NaviGpsModeControl < 50) GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_FREE; |
166 | else if(Parameter.NaviGpsModeControl < 180) GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_FREE; |
167 | else if(Parameter.NaviGpsModeControl < 180) GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_AID; |
167 | else GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_WAYPOINT; |
168 | else GPS_Parameter.FlightMode = GPS_FLIGHT_MODE_WAYPOINT; |
168 | } |
169 | } |
169 | GPS_Parameter.Gain = (float)Parameter.NaviGpsGain; |
170 | GPS_Parameter.Gain = (float)Parameter.NaviGpsGain; |
170 | GPS_Parameter.P = (float)Parameter.NaviGpsP; |
171 | GPS_Parameter.P = (float)Parameter.NaviGpsP; |
171 | GPS_Parameter.I = (float)Parameter.NaviGpsI; |
172 | GPS_Parameter.I = (float)Parameter.NaviGpsI; |
172 | GPS_Parameter.D = (float)Parameter.NaviGpsD; |
173 | GPS_Parameter.D = (float)Parameter.NaviGpsD; |
173 | GPS_Parameter.A = (float)Parameter.NaviGpsD; |
174 | GPS_Parameter.A = (float)Parameter.NaviGpsD; |
174 | GPS_Parameter.ACC = (float)Parameter.NaviGpsACC; |
175 | GPS_Parameter.ACC = (float)Parameter.NaviGpsACC; |
175 | GPS_Parameter.P_Limit = (s32)Parameter.NaviGpsPLimit; |
176 | GPS_Parameter.P_Limit = (u32)Parameter.NaviGpsPLimit; |
176 | GPS_Parameter.I_Limit = (s32)Parameter.NaviGpsILimit; |
177 | GPS_Parameter.I_Limit = (u32)Parameter.NaviGpsILimit; |
177 | GPS_Parameter.D_Limit = (s32)Parameter.NaviGpsDLimit; |
178 | GPS_Parameter.D_Limit = (u32)Parameter.NaviGpsDLimit; |
178 | GPS_Parameter.PID_Limit = 2* (s32)Parameter.NaviAngleLimitation; |
179 | GPS_Parameter.PID_Limit = 2* (u32)Parameter.NaviAngleLimitation; |
179 | GPS_Parameter.BrakingDuration = (u32)Parameter.NaviPH_LoginTime; |
180 | GPS_Parameter.BrakingDuration = (u32)Parameter.NaviPH_LoginTime; |
180 | GPS_Parameter.SpeedCompensation = (float)Parameter.NaviSpeedCompensation; |
181 | GPS_Parameter.SpeedCompensation = (float)Parameter.NaviSpeedCompensation; |
181 | GPS_Parameter.MinSat = (u8)Parameter.NaviGpsMinSat; |
182 | GPS_Parameter.MinSat = (u8)Parameter.NaviGpsMinSat; |
182 | GPS_Parameter.StickThreshold = (s8)Parameter.NaviStickThreshold; |
183 | GPS_Parameter.StickThreshold = (s8)Parameter.NaviStickThreshold; |
183 | GPS_Parameter.WindCorrection = (float)Parameter.NaviWindCorrection; |
184 | GPS_Parameter.WindCorrection = (float)Parameter.NaviWindCorrection; |
184 | GPS_Parameter.OperatingRadius = (s32)Parameter.NaviOperatingRadius * 100; // conversion of m to cm |
185 | GPS_Parameter.OperatingRadius = (u32)Parameter.NaviOperatingRadius * 100; // conversion of m to cm |
185 | } |
186 | } |
186 | // FlightMode changed? |
187 | // FlightMode changed? |
187 | if(GPS_Parameter.FlightMode != FlightMode_Old) BeepTime = 100; // beep to indicate that mode has switched |
188 | if(GPS_Parameter.FlightMode != FlightMode_Old) BeepTime = 100; // beep to indicate that mode has switched |
188 | FlightMode_Old = GPS_Parameter.FlightMode; |
189 | FlightMode_Old = GPS_Parameter.FlightMode; |
189 | } |
190 | } |
190 | 191 | ||
191 | //------------------------------------------------------------- |
192 | //------------------------------------------------------------- |
192 | // This function defines a good GPS signal condition |
193 | // This function defines a good GPS signal condition |
193 | u8 GPS_IsSignalOK(void) |
194 | u8 GPS_IsSignalOK(void) |
194 | { |
195 | { |
195 | if( (GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) && (GPSData.NumOfSats >= GPS_Parameter.MinSat)) return(1); |
196 | if( (GPSData.Status != INVALID) && (GPSData.SatFix == SATFIX_3D) && (GPSData.NumOfSats >= GPS_Parameter.MinSat)) return(1); |
196 | else return(0); |
197 | else return(0); |
197 | } |
198 | } |
198 | 199 | ||
199 | //------------------------------------------------------------ |
200 | //------------------------------------------------------------ |
200 | // Checks for manual control action |
201 | // Checks for manual control action |
201 | u8 GPS_IsManuallyControlled(void) |
202 | u8 GPS_IsManuallyControlled(void) |
202 | { |
203 | { |
203 | if( ( (abs(FC.StickNick) > GPS_Parameter.StickThreshold) || (abs(FC.StickRoll) > GPS_Parameter.StickThreshold)) && (GPS_Parameter.StickThreshold > 0)) return 1; |
204 | if( ( (abs(FC.StickNick) > GPS_Parameter.StickThreshold) || (abs(FC.StickRoll) > GPS_Parameter.StickThreshold)) && (GPS_Parameter.StickThreshold > 0)) return 1; |
204 | else return 0; |
205 | else return 0; |
205 | } |
206 | } |
206 | 207 | ||
207 | //------------------------------------------------------------ |
208 | //------------------------------------------------------------ |
208 | // copy GPS position from source position to target position |
209 | // copy GPS position from source position to target position |
209 | u8 GPS_CopyPosition(GPS_Pos_t * pGPSPosSrc, GPS_Pos_t* pGPSPosTgt) |
210 | u8 GPS_CopyPosition(GPS_Pos_t * pGPSPosSrc, GPS_Pos_t* pGPSPosTgt) |
210 | { |
211 | { |
211 | u8 retval = 0; |
212 | u8 retval = 0; |
212 | if((pGPSPosSrc == NULL) || (pGPSPosTgt == NULL)) return(retval); // bad pointer |
213 | if((pGPSPosSrc == NULL) || (pGPSPosTgt == NULL)) return(retval); // bad pointer |
213 | // copy only valid positions |
214 | // copy only valid positions |
214 | if(pGPSPosSrc->Status != INVALID) |
215 | if(pGPSPosSrc->Status != INVALID) |
215 | { |
216 | { |
216 | // if the source GPS position is not invalid |
217 | // if the source GPS position is not invalid |
217 | pGPSPosTgt->Longitude = pGPSPosSrc->Longitude; |
218 | pGPSPosTgt->Longitude = pGPSPosSrc->Longitude; |
218 | pGPSPosTgt->Latitude = pGPSPosSrc->Latitude; |
219 | pGPSPosTgt->Latitude = pGPSPosSrc->Latitude; |
219 | pGPSPosTgt->Altitude = pGPSPosSrc->Altitude; |
220 | pGPSPosTgt->Altitude = pGPSPosSrc->Altitude; |
220 | pGPSPosTgt->Status = NEWDATA; // mark data in target position as new |
221 | pGPSPosTgt->Status = NEWDATA; // mark data in target position as new |
221 | retval = 1; |
222 | retval = 1; |
222 | } |
223 | } |
223 | return(retval); |
224 | return(retval); |
224 | } |
225 | } |
225 | 226 | ||
226 | //------------------------------------------------------------ |
227 | //------------------------------------------------------------ |
227 | // clear position data |
228 | // clear position data |
228 | u8 GPS_ClearPosition(GPS_Pos_t * pGPSPos) |
229 | u8 GPS_ClearPosition(GPS_Pos_t * pGPSPos) |
229 | { |
230 | { |
230 | u8 retval = FALSE; |
231 | u8 retval = FALSE; |
231 | if(pGPSPos == NULL) return(retval); // bad pointer |
232 | if(pGPSPos == NULL) return(retval); // bad pointer |
232 | else |
233 | else |
233 | { |
234 | { |
234 | pGPSPos->Longitude = 0; |
235 | pGPSPos->Longitude = 0; |
235 | pGPSPos->Latitude = 0; |
236 | pGPSPos->Latitude = 0; |
236 | pGPSPos->Altitude = 0; |
237 | pGPSPos->Altitude = 0; |
237 | pGPSPos->Status = INVALID; |
238 | pGPSPos->Status = INVALID; |
238 | retval = TRUE; |
239 | retval = TRUE; |
239 | } |
240 | } |
240 | return (retval); |
241 | return (retval); |
241 | } |
242 | } |
242 | 243 | ||
243 | 244 | ||
244 | //------------------------------------------------------------ |
245 | //------------------------------------------------------------ |
245 | void GPS_Neutral() |
246 | void GPS_Neutral() |
246 | { |
247 | { |
247 | GPS_Stick.Nick = 0; |
248 | GPS_Stick.Nick = 0; |
248 | GPS_Stick.Roll = 0; |
249 | GPS_Stick.Roll = 0; |
249 | GPS_Stick.Yaw = 0; |
250 | GPS_Stick.Yaw = 0; |
250 | } |
251 | } |
251 | 252 | ||
252 | //------------------------------------------------------------ |
253 | //------------------------------------------------------------ |
253 | void GPS_Init(void) |
254 | void GPS_Init(void) |
254 | { |
255 | { |
255 | SerialPutString("\r\n GPS init..."); |
256 | SerialPutString("\r\n GPS init..."); |
256 | UBX_Init(); |
257 | UBX_Init(); |
257 | GPS_Neutral(); |
258 | GPS_Neutral(); |
258 | GPS_ClearPosition(&GPS_HoldPosition); |
259 | GPS_ClearPosition(&GPS_HoldPosition); |
259 | GPS_ClearPosition(&GPS_HomePosition); |
260 | GPS_ClearPosition(&GPS_HomePosition); |
260 | GPS_pTargetPosition = NULL; |
261 | GPS_pTargetPosition = NULL; |
261 | WPList_Init(); |
262 | WPList_Init(); |
262 | GPS_pWaypoint = WPList_Begin(); |
263 | GPS_pWaypoint = WPList_Begin(); |
263 | GPS_UpdateParameter(); |
264 | GPS_UpdateParameter(); |
264 | SerialPutString("ok"); |
265 | SerialPutString("ok"); |
265 | } |
266 | } |
266 | 267 | ||
267 | //------------------------------------------------------------ |
268 | //------------------------------------------------------------ |
268 | // calculate the bearing to target position from its deviation |
269 | // calculate the bearing to target position from its deviation |
269 | s32 DirectionToTarget_N_E(float northdev, float eastdev) |
270 | s32 DirectionToTarget_N_E(float northdev, float eastdev) |
270 | { |
271 | { |
271 | s32 bearing; |
272 | s32 bearing; |
272 | bearing = (s32)(atan2(northdev, eastdev) / M_PI_180); |
273 | bearing = (s32)(atan2(northdev, eastdev) / M_PI_180); |
273 | bearing = (270L - bearing)%360L; |
274 | bearing = (270L - bearing)%360L; |
274 | return(bearing); |
275 | return(bearing); |
275 | } |
276 | } |
276 | 277 | ||
277 | 278 | ||
278 | //------------------------------------------------------------ |
279 | //------------------------------------------------------------ |
279 | // Rescale xy-vector length if length limit is violated |
280 | // Rescale xy-vector length if length limit is violated |
280 | void GPS_LimitXY(s32 *x, s32 *y, s32 limit) |
281 | void GPS_LimitXY(s32 *x, s32 *y, u32 limit) |
281 | { |
282 | { |
282 | s32 dist; |
283 | u32 dist; |
283 | dist = (s32)hypot(*x,*y); // the length of the vector |
284 | dist = (u32)hypot(*x,*y); // the length of the vector |
284 | if (dist == 0) |
285 | if (dist == 0) |
285 | { |
286 | { |
286 | *x = 0; |
287 | *x = 0; |
287 | *y = 0; |
288 | *y = 0; |
288 | } |
289 | } |
289 | else if (dist > limit) |
290 | else if (dist > limit) |
290 | // if vector length is larger than the given limit |
291 | // if vector length is larger than the given limit |
291 | { // scale vector compontents so that the length is cut off to limit |
292 | { // scale vector compontents so that the length is cut off to limit |
292 | *x = (*x * limit) / dist; |
293 | *x = (*x * limit) / dist; |
293 | *y = (*y * limit) / dist; |
294 | *y = (*y * limit) / dist; |
294 | } |
295 | } |
295 | } |
296 | } |
296 | 297 | ||
297 | //------------------------------------------------------------ |
298 | //------------------------------------------------------------ |
298 | // transform the integer deg into float radians |
299 | // transform the integer deg into float radians |
299 | inline double RadiansFromGPS(s32 deg) |
300 | inline double RadiansFromGPS(s32 deg) |
300 | { |
301 | { |
301 | return ((double)deg * 1e-7f * M_PI_180); // 1E-7 because deg is the value in ° * 1E7 |
302 | return ((double)deg * 1e-7f * M_PI_180); // 1E-7 because deg is the value in ° * 1E7 |
302 | } |
303 | } |
303 | 304 | ||
304 | //------------------------------------------------------------ |
305 | //------------------------------------------------------------ |
305 | // transform the integer deg into float deg |
306 | // transform the integer deg into float deg |
306 | inline double DegFromGPS(s32 deg) |
307 | inline double DegFromGPS(s32 deg) |
307 | { |
308 | { |
308 | return ((double)deg * 1e-7f); // 1E-7 because deg is the value in ° * 1E7 |
309 | return ((double)deg * 1e-7f); // 1E-7 because deg is the value in ° * 1E7 |
309 | } |
310 | } |
310 | 311 | ||
311 | //------------------------------------------------------------ |
312 | //------------------------------------------------------------ |
312 | // calculate the deviation from the current position to the target position |
313 | // calculate the deviation from the current position to the target position |
313 | u8 GPS_CalculateDeviation(GPS_Pos_t * pCurrentPos, GPS_Pos_t * pTargetPos, GPS_Deviation_t* pDeviationFromTarget) |
314 | u8 GPS_CalculateDeviation(GPS_Pos_t * pCurrentPos, GPS_Pos_t * pTargetPos, GPS_Deviation_t* pDeviationFromTarget) |
314 | { |
315 | { |
315 | double temp1, temp2; |
316 | double temp1, temp2; |
316 | // if given pointer is NULL |
317 | // if given pointer is NULL |
317 | if((pCurrentPos == NULL) || (pTargetPos == NULL)) goto baddata; |
318 | if((pCurrentPos == NULL) || (pTargetPos == NULL)) goto baddata; |
318 | // if positions are invalid |
319 | // if positions are invalid |
319 | if((pCurrentPos->Status == INVALID) || (pTargetPos->Status == INVALID)) goto baddata; |
320 | if((pCurrentPos->Status == INVALID) || (pTargetPos->Status == INVALID)) goto baddata; |
320 | 321 | ||
321 | // The deviation from the current to the target position along north and east direction is |
322 | // The deviation from the current to the target position along north and east direction is |
322 | // simple the lat/lon difference. To convert that angular deviation into an |
323 | // simple the lat/lon difference. To convert that angular deviation into an |
323 | // arc length the spherical projection has to be considered. |
324 | // arc length the spherical projection has to be considered. |
324 | // The mean earth radius is 6371km. Therfore the arc length per latitude degree |
325 | // The mean earth radius is 6371km. Therfore the arc length per latitude degree |
325 | // is always 6371km * 2 * Pi / 360deg = 111.2 km/deg. |
326 | // is always 6371km * 2 * Pi / 360deg = 111.2 km/deg. |
326 | // The arc length per longitude degree depends on the correspondig latitude and |
327 | // The arc length per longitude degree depends on the correspondig latitude and |
327 | // is 111.2km * cos(latitude). |
328 | // is 111.2km * cos(latitude). |
328 | 329 | ||
329 | // calculate the shortest longitude deviation from target |
330 | // calculate the shortest longitude deviation from target |
330 | temp1 = DegFromGPS(pCurrentPos->Longitude) - DegFromGPS(pTargetPos->Longitude); |
331 | temp1 = DegFromGPS(pCurrentPos->Longitude) - DegFromGPS(pTargetPos->Longitude); |
331 | // outside an angular difference of -180 deg ... +180 deg its shorter to go the other way around |
332 | // outside an angular difference of -180 deg ... +180 deg its shorter to go the other way around |
332 | // In our application we wont fly more than 20.000 km but along the date line this is important. |
333 | // In our application we wont fly more than 20.000 km but along the date line this is important. |
333 | if(temp1 > 180.0f) temp1 -= 360.0f; |
334 | if(temp1 > 180.0f) temp1 -= 360.0f; |
334 | else if (temp1 < -180.0f) temp1 += 360.0f; |
335 | else if (temp1 < -180.0f) temp1 += 360.0f; |
335 | temp1 *= cos((RadiansFromGPS(pTargetPos->Latitude) + RadiansFromGPS(pCurrentPos->Latitude))/2); |
336 | temp1 *= cos((RadiansFromGPS(pTargetPos->Latitude) + RadiansFromGPS(pCurrentPos->Latitude))/2); |
336 | // calculate latitude deviation from target |
337 | // calculate latitude deviation from target |
337 | // this is allways within -180 deg ... 180 deg |
338 | // this is allways within -180 deg ... 180 deg |
338 | temp2 = DegFromGPS(pCurrentPos->Latitude) - DegFromGPS(pTargetPos->Latitude); |
339 | temp2 = DegFromGPS(pCurrentPos->Latitude) - DegFromGPS(pTargetPos->Latitude); |
339 | // deviation from target position in cm |
340 | // deviation from target position in cm |
340 | // i.e. the distance to walk from the target in northern and eastern direction to reach the current position |
341 | // i.e. the distance to walk from the target in northern and eastern direction to reach the current position |
341 | 342 | ||
342 | pDeviationFromTarget->Status = INVALID; |
343 | pDeviationFromTarget->Status = INVALID; |
343 | pDeviationFromTarget->North = (s32)(11119492.7f * temp2); |
344 | pDeviationFromTarget->North = (s32)(11119492.7f * temp2); |
344 | pDeviationFromTarget->East = (s32)(11119492.7f * temp1); |
345 | pDeviationFromTarget->East = (s32)(11119492.7f * temp1); |
345 | // If the position deviation is small enough to neglect the earth curvature |
346 | // If the position deviation is small enough to neglect the earth curvature |
346 | // (this is for our application always fulfilled) the distance to target |
347 | // (this is for our application always fulfilled) the distance to target |
347 | // can be calculated by the pythagoras of north and east deviation. |
348 | // can be calculated by the pythagoras of north and east deviation. |
348 | pDeviationFromTarget->Distance = (s32)(11119492.7f * hypot(temp1, temp2)); |
349 | pDeviationFromTarget->Distance = (u32)(11119492.7f * hypot(temp1, temp2)); |
349 | if (pDeviationFromTarget->Distance == 0L) pDeviationFromTarget->Bearing = 0L; |
350 | if (pDeviationFromTarget->Distance == 0L) pDeviationFromTarget->Bearing = 0L; |
350 | else pDeviationFromTarget->Bearing = DirectionToTarget_N_E(temp2, temp1); |
351 | else pDeviationFromTarget->Bearing = DirectionToTarget_N_E(temp2, temp1); |
351 | pDeviationFromTarget->Status = NEWDATA; |
352 | pDeviationFromTarget->Status = NEWDATA; |
352 | return TRUE; |
353 | return TRUE; |
353 | 354 | ||
354 | baddata: |
355 | baddata: |
355 | pDeviationFromTarget->North = 0L; |
356 | pDeviationFromTarget->North = 0L; |
356 | pDeviationFromTarget->East = 0L; |
357 | pDeviationFromTarget->East = 0L; |
357 | pDeviationFromTarget->Distance = 0L; |
358 | pDeviationFromTarget->Distance = 0L; |
358 | pDeviationFromTarget->Bearing = 0L; |
359 | pDeviationFromTarget->Bearing = 0L; |
359 | pDeviationFromTarget->Status = INVALID; |
360 | pDeviationFromTarget->Status = INVALID; |
360 | return FALSE; |
361 | return FALSE; |
361 | } |
362 | } |
362 | 363 | ||
363 | //------------------------------------------------------------ |
364 | //------------------------------------------------------------ |
364 | void GPS_Navigation(void) |
365 | void GPS_Navigation(void) |
365 | { |
366 | { |
366 | static u32 beep_rythm; |
367 | static u32 beep_rythm; |
367 | static u32 GPSDataTimeout = 0; |
368 | static u32 GPSDataTimeout = 0; |
368 | 369 | ||
369 | // pointer to current target position |
370 | // pointer to current target position |
370 | static GPS_Pos_t * pTargetPositionOld = NULL; |
371 | static GPS_Pos_t * pTargetPositionOld = NULL; |
371 | static Waypoint_t* GPS_pWaypointOld = NULL; |
372 | static Waypoint_t* GPS_pWaypointOld = NULL; |
372 | 373 | ||
373 | 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 |
374 | 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 |
374 | static s32 OperatingRadiusOld = -1; |
375 | static u32 OperatingRadiusOld = -1; |
375 | static u8 WPArrived = FALSE; |
- | |
376 | static u32 WPTime = 0; |
376 | static u32 WPTime = 0; |
377 | 377 | ||
378 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
378 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
379 | //+ Check for new data from GPS-receiver |
379 | //+ Check for new data from GPS-receiver |
380 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
380 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
381 | switch(GPSData.Status) |
381 | switch(GPSData.Status) |
382 | { |
382 | { |
383 | case INVALID: // no gps data available |
383 | case INVALID: // no gps data available |
384 | // do nothing |
384 | // do nothing |
385 | GPS_Parameter.PID_Limit = 0; // disables PID output |
385 | GPS_Parameter.PID_Limit = 0; // disables PID output |
386 | break; |
386 | break; |
387 | 387 | ||
388 | case PROCESSED: // the current data have been allready processed |
388 | case PROCESSED: // the current data have been allready processed |
389 | // if no new data are available within the timeout switch to invalid state. |
389 | // if no new data are available within the timeout switch to invalid state. |
390 | if(CheckDelay(GPSDataTimeout)) GPSData.Status = INVALID; |
390 | if(CheckDelay(GPSDataTimeout)) GPSData.Status = INVALID; |
391 | // wait for new gps data |
391 | // wait for new gps data |
392 | break; |
392 | break; |
393 | 393 | ||
394 | case NEWDATA: // handle new gps data |
394 | case NEWDATA: // handle new gps data |
395 | 395 | ||
396 | // update GPS Parameter from FC-Data via SPI interface |
396 | // update GPS Parameter from FC-Data via SPI interface |
397 | GPS_UpdateParameter(); |
397 | GPS_UpdateParameter(); |
398 | 398 | ||
399 | // wait maximum of 3 times the normal data update time before data timemout |
399 | // wait maximum of 3 times the normal data update time before data timemout |
400 | GPSDataTimeout = SetDelay(3 * GPS_UPDATETIME_MS); |
400 | GPSDataTimeout = SetDelay(3 * GPS_UPDATETIME_MS); |
401 | beep_rythm++; |
401 | beep_rythm++; |
402 | 402 | ||
403 | // debug |
403 | // debug |
404 | DebugOut.Analog[21] = (u16)GPSData.Speed_North; |
404 | DebugOut.Analog[21] = (s16)GPSData.Speed_North; |
405 | DebugOut.Analog[22] = (u16)GPSData.Speed_East; |
405 | DebugOut.Analog[22] = (s16)GPSData.Speed_East; |
406 | DebugOut.Analog[31] = (u16)GPSData.NumOfSats; |
406 | DebugOut.Analog[31] = (s16)GPSData.NumOfSats; |
407 | 407 | ||
408 | // If GPS signal condition is sufficient for a reliable position measurement |
408 | // If GPS signal condition is sufficient for a reliable position measurement |
409 | if(GPS_IsSignalOK()) |
409 | if(GPS_IsSignalOK()) |
410 | { |
410 | { |
411 | // update home deviation info |
411 | // update home deviation info |
412 | GPS_CalculateDeviation(&(GPSData.Position), &GPS_HomePosition, &CurrentHomeDeviation); |
412 | GPS_CalculateDeviation(&(GPSData.Position), &GPS_HomePosition, &CurrentHomeDeviation); |
413 | 413 | ||
414 | // if the MK is starting or the home position is invalid then store the home position |
414 | // if the MK is starting or the home position is invalid then store the home position |
415 | if((FC.MKFlags & MKFLAG_START) || (GPS_HomePosition.Status == INVALID)) |
415 | if((FC.MKFlags & MKFLAG_START) || (GPS_HomePosition.Status == INVALID)) |
416 | { // try to update the home position from the current position |
416 | { // try to update the home position from the current position |
417 | if(GPS_CopyPosition(&(GPSData.Position), &GPS_HomePosition)) |
417 | if(GPS_CopyPosition(&(GPSData.Position), &GPS_HomePosition)) |
418 | { |
418 | { |
419 | BeepTime = 700; // beep on success |
419 | BeepTime = 700; // beep on success |
420 | GPS_CopyPosition(&GPS_HomePosition, &(NaviData.HomePosition)); |
420 | GPS_CopyPosition(&GPS_HomePosition, &(NaviData.HomePosition)); |
421 | } |
421 | } |
422 | GPS_pWaypoint = WPList_Begin(); // go to start of waypoint list, return NULL of the list is empty |
422 | GPS_pWaypoint = WPList_Begin(); // go to start of waypoint list, return NULL of the list is empty |
423 | } |
423 | } |
424 | 424 | ||
425 | /* The selected flight mode influences the target position pointer and therefore the behavior */ |
425 | /* The selected flight mode influences the target position pointer and therefore the behavior */ |
426 | 426 | ||
427 | // check for current flight mode and set the target pointer GPS_pTargetPosition respectively |
427 | // check for current flight mode and set the target pointer GPS_pTargetPosition respectively |
428 | switch(GPS_Parameter.FlightMode) |
428 | switch(GPS_Parameter.FlightMode) |
429 | { |
429 | { |
430 | // the GPS control is deactived |
430 | // the GPS control is deactived |
431 | case GPS_FLIGHT_MODE_FREE: |
431 | case GPS_FLIGHT_MODE_FREE: |
432 | NaviData.NCFlags &= ~(NC_FLAG_PH | NC_FLAG_CH); |
432 | NCFlags &= ~(NC_FLAG_PH | NC_FLAG_CH); |
433 | NaviData.NCFlags |= NC_FLAG_FREE; |
433 | NCFlags |= NC_FLAG_FREE; |
434 | GPS_Parameter.PID_Limit = 0; // disables PID output |
434 | GPS_Parameter.PID_Limit = 0; // disables PID output |
435 | // update hold position |
435 | // update hold position |
436 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); |
436 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); |
437 | // no target position |
437 | // no target position |
438 | GPS_pTargetPosition = NULL; |
438 | GPS_pTargetPosition = NULL; |
- | 439 | GPS_TargetRadius = 0; |
|
439 | break; |
440 | break; |
440 | 441 | ||
441 | // the GPS supports the position hold, if the pilot takes no action |
442 | // the GPS supports the position hold, if the pilot takes no action |
442 | case GPS_FLIGHT_MODE_AID: |
443 | case GPS_FLIGHT_MODE_AID: |
443 | NaviData.NCFlags &= ~(NC_FLAG_FREE | NC_FLAG_CH); |
444 | NCFlags &= ~(NC_FLAG_FREE | NC_FLAG_CH); |
444 | NaviData.NCFlags |= NC_FLAG_PH; |
445 | NCFlags |= NC_FLAG_PH; |
445 | // reset WPList to begin |
446 | // reset WPList to begin |
446 | GPS_pWaypoint = WPList_Begin(); |
447 | GPS_pWaypoint = WPList_Begin(); |
447 | 448 | ||
448 | if(GPS_IsManuallyControlled()) |
449 | if(GPS_IsManuallyControlled()) |
449 | { |
450 | { |
450 | GPS_Parameter.PID_Limit = 0; // disables PID output, as long as the manual conrol is active |
451 | GPS_Parameter.PID_Limit = 0; // disables PID output, as long as the manual conrol is active |
451 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); |
452 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); |
452 | GPS_pTargetPosition = NULL; |
453 | GPS_pTargetPosition = NULL; |
- | 454 | GPS_TargetRadius = 0; |
|
453 | } |
455 | } |
454 | else |
456 | else |
455 | { |
457 | { |
456 | GPS_pTargetPosition = &GPS_HoldPosition; |
458 | GPS_pTargetPosition = &GPS_HoldPosition; |
- | 459 | GPS_TargetRadius = 100; // 1 meter |
|
457 | } |
460 | } |
458 | break; |
461 | break; |
459 | 462 | ||
460 | // the GPS control is directed to a target position |
463 | // the GPS control is directed to a target position |
461 | // given by a waypoint or by the home position |
464 | // given by a waypoint or by the home position |
462 | case GPS_FLIGHT_MODE_WAYPOINT: |
465 | case GPS_FLIGHT_MODE_WAYPOINT: |
463 | NaviData.NCFlags &= ~(NC_FLAG_FREE | NC_FLAG_PH); |
466 | NCFlags &= ~(NC_FLAG_FREE | NC_FLAG_PH); |
464 | NaviData.NCFlags |= NC_FLAG_CH; |
467 | NCFlags |= NC_FLAG_CH; |
465 | 468 | ||
466 | if(GPS_IsManuallyControlled()) // the human pilot takes the action |
469 | if(GPS_IsManuallyControlled()) // the human pilot takes the action |
467 | { |
470 | { |
468 | GPS_Parameter.PID_Limit = 0; // disables PID output, as long as the manual conrol is active |
471 | GPS_Parameter.PID_Limit = 0; // disables PID output, as long as the manual conrol is active |
469 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); // update hold position |
472 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); // update hold position |
470 | GPS_pTargetPosition = NULL; // set target position invalid |
473 | GPS_pTargetPosition = NULL; // set target position invalid |
- | 474 | GPS_TargetRadius = 0; |
|
471 | } |
475 | } |
472 | else // no manual control -> gps position hold active |
476 | else // no manual control -> gps position hold active |
473 | { |
477 | { |
474 | // waypoint trigger logic |
478 | // waypoint trigger logic |
475 | if(GPS_pWaypoint != NULL) // waypoint exist |
479 | if(GPS_pWaypoint != NULL) // waypoint exist |
476 | { |
480 | { |
477 | if(GPS_pWaypoint->Position.Status == INVALID) // should never happen |
481 | if(GPS_pWaypoint->Position.Status == INVALID) // should never happen |
478 | { |
482 | { |
479 | GPS_pWaypoint = WPList_Next(); // goto to next WP |
483 | GPS_pWaypoint = WPList_Next(); // goto to next WP |
480 | WPArrived = FALSE; |
- | |
481 | BeepTime = 255; |
484 | BeepTime = 255; |
482 | } |
485 | } |
483 | else // waypoint position is valid |
486 | else // waypoint position is valid |
484 | { |
487 | { |
485 | // check if the pointer to the waypoint has been changed or the data have been updated |
488 | // check if the pointer to the waypoint has been changed or the data have been updated |
486 | if((GPS_pWaypoint != GPS_pWaypointOld) || (GPS_pWaypoint->Position.Status == NEWDATA)) |
489 | if((GPS_pWaypoint != GPS_pWaypointOld) || (GPS_pWaypoint->Position.Status == NEWDATA)) |
487 | { |
490 | { |
488 | GPS_pWaypointOld = GPS_pWaypoint; |
491 | GPS_pWaypointOld = GPS_pWaypoint; |
489 | // reset the arrived bit to break a pending HoldTime of the old WP |
- | |
490 | WPArrived = FALSE; |
- | |
491 | } |
492 | } |
492 | - | ||
493 | if(CurrentTargetDeviation.Status != INVALID) |
- | |
494 | { // if the waypoint was not catched and the target area has been reached |
- | |
495 | if(!WPArrived && (CurrentTargetDeviation.Distance < (GPS_pWaypoint->ToleranceRadius * 100))) |
- | |
496 | { |
- | |
497 | WPArrived = TRUE; |
- | |
498 | WPTime = SetDelay(GPS_pWaypoint->HoldTime * 1000); // set hold time stamp |
- | |
499 | } |
- | |
500 | } |
- | |
501 | // if WP has been reached once, wait hold time before trigger to next one |
493 | // if WP has been reached once, wait hold time before trigger to next one |
502 | if(WPArrived) |
494 | if(NCFlags & NC_FLAG_TARGET_REACHED) |
503 | { |
495 | { |
504 | /* ToDo: Adjust GPS_pWaypoint->Heading, GPS_pWaypoint->Event handling */ |
496 | /* ToDo: Adjust GPS_pWaypoint->Heading, GPS_pWaypoint->Event handling */ |
505 | if(CheckDelay(WPTime)) |
497 | if(CheckDelay(WPTime)) |
506 | { |
498 | { |
507 | GPS_pWaypoint = WPList_Next(); // goto to next waypoint, return NULL if end of list has been reached |
499 | GPS_pWaypoint = WPList_Next(); // goto to next waypoint, return NULL if end of list has been reached |
508 | WPArrived = FALSE; // which is not arrived |
- | |
509 | } |
500 | } |
510 | } // EOF if(WPArrived) |
501 | } // EOF if(WPArrived) |
- | 502 | else |
|
- | 503 | { |
|
- | 504 | WPTime = SetDelay(GPS_pWaypoint->HoldTime * 1000); // set hold time stamp |
|
- | 505 | } |
|
511 | } |
506 | } |
512 | } // EOF waypoint trigger logic |
507 | } // EOF waypoint trigger logic |
513 | 508 | ||
514 | if(GPS_pWaypoint != NULL) // Waypoint exist |
509 | if(GPS_pWaypoint != NULL) // Waypoint exist |
515 | { |
510 | { |
516 | // update the hold position |
511 | // update the hold position |
517 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); |
512 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); |
518 | GPS_pTargetPosition = &(GPS_pWaypoint->Position); |
513 | GPS_pTargetPosition = &(GPS_pWaypoint->Position); |
- | 514 | GPS_TargetRadius = (u32)(GPS_pWaypoint->ToleranceRadius) * 100L; |
|
- | 515 | ||
519 | } |
516 | } |
520 | else // no waypoint info available, i.e. the WPList is empty or the end of the list has been reached |
517 | else // no waypoint info available, i.e. the WPList is empty or the end of the list has been reached |
521 | { |
518 | { |
522 | // fly back to home postion |
519 | // fly back to home postion |
523 | if(GPS_HomePosition.Status == INVALID) |
520 | if(GPS_HomePosition.Status == INVALID) |
524 | { |
521 | { |
525 | GPS_pTargetPosition = &GPS_HoldPosition; // fall back to hold mode if home position is not available |
522 | GPS_pTargetPosition = &GPS_HoldPosition; // fall back to hold mode if home position is not available |
- | 523 | GPS_TargetRadius = 100; |
|
526 | BeepTime = 255; // beep to indicate missin home position |
524 | BeepTime = 255; // beep to indicate missin home position |
527 | } |
525 | } |
528 | else // the home position is valid |
526 | else // the home position is valid |
529 | { |
527 | { |
530 | // update the hold position |
528 | // update the hold position |
531 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); |
529 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); |
532 | // set target to home position |
530 | // set target to home position |
533 | GPS_pTargetPosition = &GPS_HomePosition; |
531 | GPS_pTargetPosition = &GPS_HomePosition; |
- | 532 | GPS_TargetRadius = 100; |
|
534 | } |
533 | } |
535 | } |
534 | } |
536 | } // EOF no manual control |
535 | } // EOF no manual control |
537 | break; |
536 | break; |
538 | 537 | ||
539 | case GPS_FLIGHT_MODE_UNDEF: |
538 | case GPS_FLIGHT_MODE_UNDEF: |
540 | default: |
539 | default: |
541 | GPS_Parameter.PID_Limit = 0; // disables PID output |
540 | GPS_Parameter.PID_Limit = 0; // disables PID output |
542 | // update hold position |
541 | // update hold position |
543 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); |
542 | GPS_CopyPosition(&(GPSData.Position), &GPS_HoldPosition); |
544 | // no target position |
543 | // no target position |
545 | GPS_pTargetPosition = NULL; |
544 | GPS_pTargetPosition = NULL; |
- | 545 | GPS_TargetRadius = 0; |
|
546 | break; |
546 | break; |
547 | 547 | ||
548 | }// EOF GPS Mode Handling |
548 | }// EOF GPS Mode Handling |
549 | 549 | ||
550 | 550 | ||
551 | /* Calculation of range target based on the real target */ |
551 | /* Calculation of range target based on the real target */ |
552 | 552 | ||
553 | // if no target position exist clear the ranged target position |
553 | // if no target position exist clear the ranged target position |
554 | if(GPS_pTargetPosition == NULL) GPS_ClearPosition(&RangedTargetPosition); |
554 | if(GPS_pTargetPosition == NULL) GPS_ClearPosition(&RangedTargetPosition); |
555 | else |
555 | else |
556 | { // if the target position has been changed or the value has been updated or the OperatingRadius has changed |
556 | { // if the target position has been changed or the value has been updated or the OperatingRadius has changed |
557 | if((GPS_pTargetPosition != pTargetPositionOld) || (GPS_pTargetPosition->Status == NEWDATA) || (GPS_Parameter.OperatingRadius != OperatingRadiusOld) ) |
557 | if((GPS_pTargetPosition != pTargetPositionOld) || (GPS_pTargetPosition->Status == NEWDATA) || (GPS_Parameter.OperatingRadius != OperatingRadiusOld) ) |
558 | { |
558 | { |
559 | BeepTime = 255; // beep to indicate setting of a new target position |
559 | BeepTime = 255; // beep to indicate setting of a new target position |
- | 560 | NCFlags &= ~NC_FLAG_TARGET_REACHED; // clear target reached flag |
|
560 | // calculate deviation of new target position from home position |
561 | // calculate deviation of new target position from home position |
561 | if(GPS_CalculateDeviation(GPS_pTargetPosition, &GPS_HomePosition, &TargetHomeDeviation)) |
562 | if(GPS_CalculateDeviation(GPS_pTargetPosition, &GPS_HomePosition, &TargetHomeDeviation)) |
562 | { |
563 | { |
563 | // check distance from home position |
564 | // check distance from home position |
564 | if(TargetHomeDeviation.Distance > GPS_Parameter.OperatingRadius) |
565 | if(TargetHomeDeviation.Distance > GPS_Parameter.OperatingRadius) |
565 | { |
566 | { |
566 | //calculate ranged target position to be within the operation radius area |
567 | //calculate ranged target position to be within the operation radius area |
567 | NaviData.NCFlags |= NC_FLAG_RANGE_LIMIT; |
568 | NCFlags |= NC_FLAG_RANGE_LIMIT; |
568 | 569 | ||
569 | TargetHomeDeviation.North *= GPS_Parameter.OperatingRadius; |
570 | TargetHomeDeviation.North *= GPS_Parameter.OperatingRadius; |
570 | TargetHomeDeviation.North /= TargetHomeDeviation.Distance; |
571 | TargetHomeDeviation.North /= TargetHomeDeviation.Distance; |
571 | TargetHomeDeviation.East *= GPS_Parameter.OperatingRadius; |
572 | TargetHomeDeviation.East *= GPS_Parameter.OperatingRadius; |
572 | TargetHomeDeviation.East /= TargetHomeDeviation.Distance; |
573 | TargetHomeDeviation.East /= TargetHomeDeviation.Distance; |
573 | TargetHomeDeviation.Distance = GPS_Parameter.OperatingRadius; |
574 | TargetHomeDeviation.Distance = GPS_Parameter.OperatingRadius; |
574 | 575 | ||
575 | RangedTargetPosition.Status = INVALID; |
576 | RangedTargetPosition.Status = INVALID; |
576 | RangedTargetPosition.Latitude = GPS_HomePosition.Latitude; |
577 | RangedTargetPosition.Latitude = GPS_HomePosition.Latitude; |
577 | RangedTargetPosition.Latitude += (s32)((float)TargetHomeDeviation.North / 1.11194927f); |
578 | RangedTargetPosition.Latitude += (s32)((float)TargetHomeDeviation.North / 1.11194927f); |
578 | RangedTargetPosition.Longitude = GPS_HomePosition.Longitude; |
579 | RangedTargetPosition.Longitude = GPS_HomePosition.Longitude; |
579 | RangedTargetPosition.Longitude += (s32)((float)TargetHomeDeviation.East / (1.11194927f * cos(RadiansFromGPS(GPS_HomePosition.Latitude))) ); |
580 | RangedTargetPosition.Longitude += (s32)((float)TargetHomeDeviation.East / (1.11194927f * cos(RadiansFromGPS(GPS_HomePosition.Latitude))) ); |
580 | RangedTargetPosition.Altitude = GPS_pTargetPosition->Altitude; |
581 | RangedTargetPosition.Altitude = GPS_pTargetPosition->Altitude; |
581 | RangedTargetPosition.Status = NEWDATA; |
582 | RangedTargetPosition.Status = NEWDATA; |
582 | } |
583 | } |
583 | else |
584 | else |
584 | { // the target is located within the operation radius area |
585 | { // the target is located within the operation radius area |
585 | // simple copy the loaction to the ranged target position |
586 | // simple copy the loaction to the ranged target position |
586 | GPS_CopyPosition(GPS_pTargetPosition, &RangedTargetPosition); |
587 | GPS_CopyPosition(GPS_pTargetPosition, &RangedTargetPosition); |
587 | NaviData.NCFlags &= ~NC_FLAG_RANGE_LIMIT; |
588 | NCFlags &= ~NC_FLAG_RANGE_LIMIT; |
588 | } |
589 | } |
589 | } |
590 | } |
590 | else |
591 | else |
591 | { // deviation could not be determined |
592 | { // deviation could not be determined |
592 | GPS_ClearPosition(&RangedTargetPosition); |
593 | GPS_ClearPosition(&RangedTargetPosition); |
593 | } |
594 | } |
594 | GPS_pTargetPosition->Status = PROCESSED; // mark current target as processed! |
595 | GPS_pTargetPosition->Status = PROCESSED; // mark current target as processed! |
595 | } |
596 | } |
596 | } |
597 | } |
597 | OperatingRadiusOld = GPS_Parameter.OperatingRadius; |
598 | OperatingRadiusOld = GPS_Parameter.OperatingRadius; |
598 | // remember last target position pointer |
599 | // remember last target position pointer |
599 | pTargetPositionOld = GPS_pTargetPosition; |
600 | pTargetPositionOld = GPS_pTargetPosition; |
600 | 601 | ||
601 | /* Calculate position deviation from ranged target */ |
602 | /* Calculate position deviation from ranged target */ |
602 | 603 | ||
603 | // calculate deviation of current position to ranged target position in cm |
604 | // calculate deviation of current position to ranged target position in cm |
604 | if(GPS_CalculateDeviation(&(GPSData.Position), &RangedTargetPosition, &CurrentTargetDeviation)) |
605 | if(GPS_CalculateDeviation(&(GPSData.Position), &RangedTargetPosition, &CurrentTargetDeviation)) |
- | 606 | { // set target reached flag of we once reached the target point |
|
- | 607 | if(!(NCFlags |= NC_FLAG_TARGET_REACHED) && (CurrentTargetDeviation.Distance < GPS_TargetRadius)) |
|
605 | { |
608 | { |
- | 609 | NCFlags |= NC_FLAG_TARGET_REACHED; // set target reached flag |
|
- | 610 | } |
|
606 | // implement your control code here based |
611 | // implement your control code here based |
607 | // in the info available in the CurrentTargetDeviation, GPSData and FromFlightCtrl.GyroHeading |
612 | // in the info available in the CurrentTargetDeviation, GPSData and FromFlightCtrl.GyroHeading |
608 | GPS_Stick.Nick = 0; |
613 | GPS_Stick.Nick = 0; |
609 | GPS_Stick.Roll = 0; |
614 | GPS_Stick.Roll = 0; |
610 | GPS_Stick.Yaw = 0; |
615 | GPS_Stick.Yaw = 0; |
611 | } |
616 | } |
612 | else // deviation could not be calculated |
617 | else // deviation could not be calculated |
613 | { // do nothing on gps sticks! |
618 | { // do nothing on gps sticks! |
614 | GPS_Neutral(); |
619 | GPS_Neutral(); |
615 | } |
620 | } |
616 | 621 | ||
617 | }// eof if GPSSignal is OK |
622 | }// eof if GPSSignal is OK |
618 | else // GPSSignal not OK |
623 | else // GPSSignal not OK |
619 | { |
624 | { |
620 | GPS_Neutral(); |
625 | GPS_Neutral(); |
621 | // beep if signal is not sufficient |
626 | // beep if signal is not sufficient |
622 | if(GPS_Parameter.FlightMode != GPS_FLIGHT_MODE_FREE) |
627 | if(GPS_Parameter.FlightMode != GPS_FLIGHT_MODE_FREE) |
623 | { |
628 | { |
624 | if(!(GPSData.Flags & FLAG_GPSFIXOK) && !(beep_rythm % 5)) BeepTime = 100; |
629 | if(!(GPSData.Flags & FLAG_GPSFIXOK) && !(beep_rythm % 5)) BeepTime = 100; |
625 | else if (GPSData.NumOfSats < GPS_Parameter.MinSat && !(beep_rythm % 5)) BeepTime = 10; |
630 | else if (GPSData.NumOfSats < GPS_Parameter.MinSat && !(beep_rythm % 5)) BeepTime = 10; |
626 | } |
631 | } |
627 | } |
632 | } |
628 | GPSData.Status = PROCESSED; // mark as processed |
633 | GPSData.Status = PROCESSED; // mark as processed |
629 | break; |
634 | break; |
630 | } |
635 | } |
631 | 636 | ||
632 | DebugOut.Analog[27] = (s16)CurrentTargetDeviation.North; |
637 | DebugOut.Analog[27] = (s16)CurrentTargetDeviation.North; |
633 | DebugOut.Analog[28] = (s16)CurrentTargetDeviation.East; |
638 | DebugOut.Analog[28] = (s16)CurrentTargetDeviation.East; |
634 | DebugOut.Analog[29] = GPS_Stick.Nick; |
639 | DebugOut.Analog[29] = GPS_Stick.Nick; |
635 | DebugOut.Analog[30] = GPS_Stick.Roll; |
640 | DebugOut.Analog[30] = GPS_Stick.Roll; |
636 | 641 | ||
637 | // update navi data, send back to ground station |
642 | // update navi data, send back to ground station |
638 | GPS_CopyPosition(&(GPSData.Position), &(NaviData.CurrentPosition)); |
643 | GPS_CopyPosition(&(GPSData.Position), &(NaviData.CurrentPosition)); |
639 | GPS_CopyPosition(&RangedTargetPosition, &(NaviData.TargetPosition)); |
644 | GPS_CopyPosition(&RangedTargetPosition, &(NaviData.TargetPosition)); |
640 | GPS_CopyPosition(&GPS_HomePosition, &(NaviData.HomePosition)); |
645 | GPS_CopyPosition(&GPS_HomePosition, &(NaviData.HomePosition)); |
641 | NaviData.SatsInUse = GPSData.NumOfSats; |
646 | NaviData.SatsInUse = GPSData.NumOfSats; |
642 | NaviData.TargetPositionDeviation.Distance = (u16)CurrentTargetDeviation.Distance/10; // dm |
647 | NaviData.TargetPositionDeviation.Distance = (u16)CurrentTargetDeviation.Distance/10; // dm |
643 | NaviData.TargetPositionDeviation.Bearing = (s16)CurrentTargetDeviation.Bearing; |
648 | NaviData.TargetPositionDeviation.Bearing = (s16)CurrentTargetDeviation.Bearing; |
644 | NaviData.HomePositionDeviation.Distance = (u16)CurrentHomeDeviation.Distance/10; // dm |
649 | NaviData.HomePositionDeviation.Distance = (u16)CurrentHomeDeviation.Distance/10; // dm |
645 | NaviData.HomePositionDeviation.Bearing = (s16)CurrentHomeDeviation.Bearing; |
650 | NaviData.HomePositionDeviation.Bearing = (s16)CurrentHomeDeviation.Bearing; |
646 | NaviData.UBat = FC.UBat; |
651 | NaviData.UBat = FC.UBat; |
647 | NaviData.GroundSpeed = (u16)GPSData.Speed_Ground; |
652 | NaviData.GroundSpeed = (u16)GPSData.Speed_Ground; |
648 | NaviData.Heading = (s16)(GPSData.Heading/100000L); |
653 | NaviData.Heading = (s16)(GPSData.Heading/100000L); |
649 | NaviData.CompassHeading = (s16)FromFlightCtrl.GyroHeading/10; // in deg |
654 | NaviData.CompassHeading = (s16)FromFlightCtrl.GyroHeading/10; // in deg |
650 | NaviData.AngleNick = FromFlightCtrl.AngleNick / 10; // in deg |
655 | NaviData.AngleNick = FromFlightCtrl.AngleNick / 10; // in deg |
651 | NaviData.AngleRoll = FromFlightCtrl.AngleRoll / 10; // in deg |
656 | NaviData.AngleRoll = FromFlightCtrl.AngleRoll / 10; // in deg |
652 | NaviData.RC_Quality = (u8) FC.RC_Quality; |
657 | NaviData.RC_Quality = (u8)FC.RC_Quality; |
653 | NaviData.MKFlags = (u8)FC.MKFlags; |
658 | NaviData.MKFlags = (u8)FC.MKFlags; |
- | 659 | NaviData.NCFlags = NCFlags; |
|
654 | NaviData.OperatingRadius = Parameter.NaviOperatingRadius; |
660 | NaviData.OperatingRadius = Parameter.NaviOperatingRadius; |
655 | NaviData.TopSpeed = (s16)GPSData.Speed_Top; // in cm/s |
661 | NaviData.TopSpeed = (s16)GPSData.Speed_Top; // in cm/s |
656 | - | ||
- | 662 | NaviData.TargetHoldTime = (u16)GetDelay(WPTime); |
|
657 | //+++++++++++++++++++++++++++++++++++++++++++++++++++ |
663 | //+++++++++++++++++++++++++++++++++++++++++++++++++++ |
658 | return; |
664 | return; |
659 | } |
665 | } |
660 | 666 | ||
661 | 667 |