Rev 157 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 157 | Rev 158 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | This program (files gps.c and gps.h) is free software; you can redistribute it and/or modify |
2 | This program (files gps.c and gps.h) is free software; you can redistribute it and/or modify |
3 | it under the terms of the GNU General Public License as published by the Free Software Foundation; |
3 | it under the terms of the GNU General Public License as published by the Free Software Foundation; |
4 | either version 3 of the License, or (at your option) any later version. |
4 | either version 3 of the License, or (at your option) any later version. |
5 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
5 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
6 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7 | GNU General Public License for more details. You should have received a copy of the GNU General Public License |
7 | GNU General Public License for more details. You should have received a copy of the GNU General Public License |
8 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
8 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
9 | 9 | ||
10 | Please note: All the other files for the project "Mikrokopter" by H.Buss are under the license (license_buss.txt) published by www.mikrokopter.de |
10 | Please note: All the other files for the project "Mikrokopter" by H.Buss are under the license (license_buss.txt) published by www.mikrokopter.de |
11 | */ |
11 | */ |
12 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
12 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | Peter Muehlenbrock |
13 | Peter Muehlenbrock |
14 | Auswertung der Daten vom GPS im ublox Format |
14 | Auswertung der Daten vom GPS im ublox Format |
15 | Regelung fuer GPS noch nicht implementiert |
15 | Regelung fuer GPS noch nicht implementiert |
16 | Stand 15.9.2007 |
16 | Stand 16.9.2007 |
17 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
17 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
18 | */ |
18 | */ |
19 | #include "main.h" |
19 | #include "main.h" |
20 | //#include "gps.h" |
20 | //#include "gps.h" |
21 | 21 | ||
22 | // Defines fuer ublox Messageformat um Auswertung zu steuern |
22 | // Defines fuer ublox Messageformat um Auswertung zu steuern |
23 | #define UBLOX_IDLE 0 |
23 | #define UBLOX_IDLE 0 |
24 | #define UBLOX_SYNC1 1 |
24 | #define UBLOX_SYNC1 1 |
25 | #define UBLOX_SYNC2 2 |
25 | #define UBLOX_SYNC2 2 |
26 | #define UBLOX_CLASS 3 |
26 | #define UBLOX_CLASS 3 |
27 | #define UBLOX_ID 4 |
27 | #define UBLOX_ID 4 |
28 | #define UBLOX_LEN1 5 |
28 | #define UBLOX_LEN1 5 |
29 | #define UBLOX_LEN2 6 |
29 | #define UBLOX_LEN2 6 |
30 | #define UBLOX_CKA 7 |
30 | #define UBLOX_CKA 7 |
31 | #define UBLOX_CKB 8 |
31 | #define UBLOX_CKB 8 |
32 | #define UBLOX_PAYLOAD 9 |
32 | #define UBLOX_PAYLOAD 9 |
33 | 33 | ||
34 | // ublox Protokoll Identifier |
34 | // ublox Protokoll Identifier |
35 | #define UBLOX_NAV_POSUTM 0x08 |
35 | #define UBLOX_NAV_POSUTM 0x08 |
36 | #define UBLOX_NAV_STATUS 0x03 |
36 | #define UBLOX_NAV_STATUS 0x03 |
37 | #define UBLOX_NAV_VELED 0x12 |
37 | #define UBLOX_NAV_VELED 0x12 |
38 | #define UBLOX_NAV_CLASS 0x01 |
38 | #define UBLOX_NAV_CLASS 0x01 |
39 | #define UBLOX_SYNCH1_CHAR 0xB5 |
39 | #define UBLOX_SYNCH1_CHAR 0xB5 |
40 | #define UBLOX_SYNCH2_CHAR 0x62 |
40 | #define UBLOX_SYNCH2_CHAR 0x62 |
41 | 41 | ||
42 | signed int GPS_Nick = 0; |
42 | signed int GPS_Nick = 0; |
43 | signed int GPS_Roll = 0; |
43 | signed int GPS_Roll = 0; |
44 | static uint8_t ublox_msg_state = UBLOX_IDLE; |
44 | short int ublox_msg_state = UBLOX_IDLE; |
45 | static uint8_t chk_a =0; //Checksum |
45 | static uint8_t chk_a =0; //Checksum |
46 | static uint8_t chk_b =0; |
46 | static uint8_t chk_b =0; |
- | 47 | short int gps_state; |
|
- | 48 | short int gps_updte_flag; |
|
- | 49 | signed int GPS_hdng_abs_2trgt; //Winkel zum Ziel bezogen auf Nordpol |
|
- | 50 | signed int GPS_hdng_rel_2trgt; //Winkel zum Ziel bezogen auf Nordachse des Kopters |
|
- | 51 | signed int GPS_dist_2trgt; //vorzeichenlose Distanz zum Ziel |
|
47 | 52 | ||
48 | static unsigned int rx_len; |
53 | static unsigned int rx_len; |
49 | unsigned int cnt0,cnt1,cnt2; //******Provisorisch |
54 | unsigned int cnt0,cnt1,cnt2; //******Provisorisch |
50 | static unsigned int ptr_payload_data_end; |
55 | static unsigned int ptr_payload_data_end; |
51 | 56 | ||
52 | static uint8_t *ptr_payload_data; |
57 | static uint8_t *ptr_payload_data; |
53 | static uint8_t *ptr_pac_status; |
58 | static uint8_t *ptr_pac_status; |
54 | 59 | ||
55 | short int Get_GPS_data(void); |
60 | short int Get_GPS_data(void); |
56 | 61 | ||
57 | NAV_POSUTM_t actual_pos; // Aktuelle Nav Daten werden hier im ublox Format abgelegt |
62 | NAV_POSUTM_t actual_pos; // Aktuelle Nav Daten werden hier im ublox Format abgelegt |
58 | NAV_STATUS_t actual_status; // Aktueller Nav Status |
63 | NAV_STATUS_t actual_status; // Aktueller Nav Status |
59 | NAV_VELNED_t actual_speed; // Aktueller Geschwindigkeits und Richtungsdaten |
64 | NAV_VELNED_t actual_speed; // Aktueller Geschwindigkeits und Richtungsdaten |
60 | 65 | ||
61 | GPS_ABS_POSITION_t gps_act_position; // Alle wichtigen Daten zusammengefasst |
66 | GPS_ABS_POSITION_t gps_act_position; // Alle wichtigen Daten zusammengefasst |
62 | GPS_ABS_POSITION_t gps_home_position; // Die Startposition, beim Kalibrieren ermittelt |
67 | GPS_ABS_POSITION_t gps_home_position; // Die Startposition, beim Kalibrieren ermittelt |
63 | GPS_REL_POSITION_t gps_rel_act_position; // Die aktuelle relative Position bezogen auf Home Position |
68 | GPS_REL_POSITION_t gps_rel_act_position; // Die aktuelle relative Position bezogen auf Home Position |
- | 69 | GPS_REL_POSITION_t gps_rel_hold_position; // Die gespeicherte Sollposition fuer GPS_ Hold Mode |
|
64 | 70 | ||
65 | // Initialisierung |
71 | // Initialisierung |
66 | void GPS_Neutral(void) |
72 | void GPS_Neutral(void) |
67 | { |
73 | { |
- | 74 | short int n; |
|
68 | ublox_msg_state = UBLOX_IDLE; |
75 | ublox_msg_state = UBLOX_IDLE; |
- | 76 | gps_state = GPS_CRTL_IDLE; |
|
69 | actual_pos.status = 0; |
77 | actual_pos.status = 0; |
70 | actual_speed.status = 0; |
78 | actual_speed.status = 0; |
71 | actual_status.status = 0; |
79 | actual_status.status = 0; |
72 | gps_home_position.status = 0; // Noch keine gueltige Home Position |
80 | gps_home_position.status = 0; // Noch keine gueltige Home Position |
73 | gps_act_position.status = 0; |
81 | gps_act_position.status = 0; |
74 | gps_rel_act_position.status = 0; |
82 | gps_rel_act_position.status = 0; |
75 | - | ||
- | 83 | GPS_Nick = 0; |
|
- | 84 | GPS_Roll = 0; |
|
- | 85 | gps_updte_flag = 0; |
|
76 | } |
86 | } |
77 | 87 | ||
78 | // Home Position sichern falls Daten verfuegbar sind. |
88 | // Home Position sichern falls Daten verfuegbar sind. |
79 | void GPS_Save_Home(void) |
89 | void GPS_Save_Home(void) |
80 | { |
90 | { |
81 | short int n; |
91 | short int n; |
82 | n = Get_GPS_data(); |
92 | n = Get_GPS_data(); |
83 | if (n == 0) // Gueltige und aktuelle Daten ? |
93 | if (n == 0) // Gueltige und aktuelle Daten ? |
84 | { |
94 | { |
85 | // Neue GPS Daten liegen vor |
95 | // Neue GPS Daten liegen vor |
86 | gps_home_position.utm_east = gps_act_position.utm_east; |
96 | gps_home_position.utm_east = gps_act_position.utm_east; |
87 | gps_home_position.utm_north = gps_act_position.utm_north; |
97 | gps_home_position.utm_north = gps_act_position.utm_north; |
88 | gps_home_position.utm_alt = gps_act_position.utm_alt; |
98 | gps_home_position.utm_alt = gps_act_position.utm_alt; |
89 | gps_home_position.status = 1; // Home Position gueltig |
99 | gps_home_position.status = 1; // Home Position gueltig |
90 | } |
100 | } |
91 | } |
101 | } |
92 | 102 | ||
93 | // Relative Position zur Home Position bestimmen |
103 | // Relative Position zur Home Position bestimmen |
94 | // Rueckgabewert 0= Daten sind aktuell und gueltig. 1= Keine Aenderung. 2= Daten ungueltig |
104 | // Rueckgabewert 0= Daten sind aktuell und gueltig. 1= Keine Aenderung. 2= Daten ungueltig |
95 | short int Get_Rel_Position(void) |
105 | short int Get_Rel_Position(void) |
96 | { |
106 | { |
97 | short int n = 0; |
107 | short int n = 0; |
98 | n = Get_GPS_data(); |
108 | n = Get_GPS_data(); |
99 | if (n >=1) return (n); // nix zu tun, weil keine neue Daten da sind |
109 | if (n >=1) return (n); // nix zu tun, weil keine neue Daten da sind |
100 | if (gps_home_position.status > 0) //Nur wenn Home Position vorliegt |
110 | if (gps_home_position.status > 0) //Nur wenn Home Position vorliegt |
101 | { |
111 | { |
102 | gps_rel_act_position.utm_east = (int) (gps_act_position.utm_east - gps_home_position.utm_east); |
112 | gps_rel_act_position.utm_east = (int) (gps_act_position.utm_east - gps_home_position.utm_east); |
103 | gps_rel_act_position.utm_north = (int) (gps_act_position.utm_north - gps_home_position.utm_north); |
113 | gps_rel_act_position.utm_north = (int) (gps_act_position.utm_north - gps_home_position.utm_north); |
104 | gps_rel_act_position.status = 1; // gueltige Positionsdaten |
114 | gps_rel_act_position.status = 1; // gueltige Positionsdaten |
105 | n = 0; |
115 | n = 0; |
- | 116 | gps_updte_flag = 1; // zeigt an, dass neue Daten vorliegen. |
|
106 | } |
117 | } |
107 | else |
118 | else |
108 | { |
119 | { |
109 | n = 2; //keine gueltigen Daten vorhanden |
120 | n = 2; //keine gueltigen Daten vorhanden |
110 | gps_rel_act_position.status = 0; //keine gueltige Position weil keine home Position da ist. |
121 | gps_rel_act_position.status = 0; //keine gueltige Position weil keine home Position da ist. |
111 | } |
122 | } |
112 | return (n); |
123 | return (n); |
113 | } |
124 | } |
114 | 125 | ||
115 | // Daten aus aktuellen ublox Messages extrahieren |
126 | // Daten aus aktuellen ublox Messages extrahieren |
116 | // Rueckgabewert 0= Daten sind aktuell und gueltig. 1= Keine Aenderung. 2= Daten ungueltig |
127 | // Rueckgabewert 0= Daten sind aktuell und gueltig. 1= Keine Aenderung. 2= Daten ungueltig |
117 | short int Get_GPS_data(void) |
128 | short int Get_GPS_data(void) |
118 | { |
129 | { |
119 | short int n = 1; |
130 | short int n = 1; |
120 | 131 | ||
121 | if (actual_pos.status == 0) return (1); //damit es schnell geht, wenn nix zu tun ist |
132 | if (actual_pos.status == 0) return (1); //damit es schnell geht, wenn nix zu tun ist |
122 | if ((actual_pos.status > 0) && (actual_status.status > 0) && (actual_speed.status > 0)) |
133 | if ((actual_pos.status > 0) && (actual_status.status > 0) && (actual_speed.status > 0)) |
123 | { |
134 | { |
124 | cnt1++; //**** noch Rausschmeissen |
135 | cnt1++; //**** noch Rausschmeissen |
125 | if (((actual_status.gpsfix_type & 0x03) >=2) && ((actual_status.nav_status_flag & 0x01) >=1)) // nur wenn Daten aktuell und gueltig sind |
136 | if (((actual_status.gpsfix_type & 0x03) >=2) && ((actual_status.nav_status_flag & 0x01) >=1)) // nur wenn Daten aktuell und gueltig sind |
126 | { |
137 | { |
127 | gps_act_position.utm_east = actual_pos.utm_east/10; |
138 | gps_act_position.utm_east = actual_pos.utm_east/10; |
128 | gps_act_position.utm_north = actual_pos.utm_north/10; |
139 | gps_act_position.utm_north = actual_pos.utm_north/10; |
129 | gps_act_position.utm_alt = actual_pos.utm_alt/10; |
140 | gps_act_position.utm_alt = actual_pos.utm_alt/10; |
130 | gps_act_position.speed_gnd = actual_speed.speed_gnd/10; |
141 | gps_act_position.speed_gnd = actual_speed.speed_gnd/10; |
131 | gps_act_position.speed_gnd = actual_speed.speed_gnd/10; |
142 | gps_act_position.speed_gnd = actual_speed.speed_gnd/10; |
132 | gps_act_position.heading = actual_speed.heading/100000; |
143 | gps_act_position.heading = actual_speed.heading/100000; |
133 | gps_act_position.status = 1; |
144 | gps_act_position.status = 1; |
134 | n = 0; //Daten gueltig |
145 | n = 0; //Daten gueltig |
135 | } |
146 | } |
136 | else |
147 | else |
137 | { |
148 | { |
138 | gps_act_position.status = 0; //Keine gueltigen Daten |
149 | gps_act_position.status = 0; //Keine gueltigen Daten |
139 | n = 2; |
150 | n = 2; |
140 | } |
151 | } |
141 | actual_pos.status = 0; //neue ublox Messages anfordern |
152 | actual_pos.status = 0; //neue ublox Messages anfordern |
142 | actual_status.status = 0; |
153 | actual_status.status = 0; |
143 | actual_speed.status = 0; |
154 | actual_speed.status = 0; |
144 | } |
155 | } |
145 | return (n); |
156 | return (n); |
146 | } |
157 | } |
147 | 158 | ||
148 | 159 | ||
149 | /* |
160 | /* |
150 | Daten vom GPS im ublox MSG Format auswerten |
161 | Daten vom GPS im ublox MSG Format auswerten |
151 | Die Routine wird bei jedem Empfang eines Zeichens vom GPS Modul durch den UART IRQ aufgerufen |
162 | Die Routine wird bei jedem Empfang eines Zeichens vom GPS Modul durch den UART IRQ aufgerufen |
152 | // Die UBX Messages NAV_POSUTM, NAV_STATUS und NAV_VALED muessen aktiviert sein |
163 | // Die UBX Messages NAV_POSUTM, NAV_STATUS und NAV_VALED muessen aktiviert sein |
153 | */ |
164 | */ |
154 | void Get_Ublox_Msg(uint8_t rx) |
165 | void Get_Ublox_Msg(uint8_t rx) |
155 | { |
166 | { |
156 | 167 | ||
157 | switch (ublox_msg_state) |
168 | switch (ublox_msg_state) |
158 | { |
169 | { |
159 | 170 | ||
160 | case UBLOX_IDLE: // Zuerst Synchcharacters pruefen |
171 | case UBLOX_IDLE: // Zuerst Synchcharacters pruefen |
161 | if ( rx == UBLOX_SYNCH1_CHAR ) ublox_msg_state = UBLOX_SYNC1; |
172 | if ( rx == UBLOX_SYNCH1_CHAR ) ublox_msg_state = UBLOX_SYNC1; |
162 | else ublox_msg_state = UBLOX_IDLE; |
173 | else ublox_msg_state = UBLOX_IDLE; |
163 | break; |
174 | break; |
164 | 175 | ||
165 | case UBLOX_SYNC1: |
176 | case UBLOX_SYNC1: |
166 | 177 | ||
167 | if (rx == UBLOX_SYNCH2_CHAR) ublox_msg_state = UBLOX_SYNC2; |
178 | if (rx == UBLOX_SYNCH2_CHAR) ublox_msg_state = UBLOX_SYNC2; |
168 | else ublox_msg_state = UBLOX_IDLE; |
179 | else ublox_msg_state = UBLOX_IDLE; |
169 | chk_a = 0,chk_b = 0; |
180 | chk_a = 0,chk_b = 0; |
170 | break; |
181 | break; |
171 | 182 | ||
172 | case UBLOX_SYNC2: |
183 | case UBLOX_SYNC2: |
173 | if (rx == UBLOX_NAV_CLASS) ublox_msg_state = UBLOX_CLASS; |
184 | if (rx == UBLOX_NAV_CLASS) ublox_msg_state = UBLOX_CLASS; |
174 | else ublox_msg_state = UBLOX_IDLE; |
185 | else ublox_msg_state = UBLOX_IDLE; |
175 | break; |
186 | break; |
176 | 187 | ||
177 | case UBLOX_CLASS: // Nur NAV Meldungen auswerten |
188 | case UBLOX_CLASS: // Nur NAV Meldungen auswerten |
178 | switch (rx) |
189 | switch (rx) |
179 | { |
190 | { |
180 | case UBLOX_NAV_POSUTM: |
191 | case UBLOX_NAV_POSUTM: |
181 | ptr_pac_status = &actual_pos.status; |
192 | ptr_pac_status = &actual_pos.status; |
182 | if (*ptr_pac_status > 0) ublox_msg_state = UBLOX_IDLE; //Abbruch weil Daten noch nicht verwendet wurden |
193 | if (*ptr_pac_status > 0) ublox_msg_state = UBLOX_IDLE; //Abbruch weil Daten noch nicht verwendet wurden |
183 | else |
194 | else |
184 | { |
195 | { |
185 | ptr_payload_data = &actual_pos; |
196 | ptr_payload_data = &actual_pos; |
186 | ptr_payload_data_end = &actual_pos.status; |
197 | ptr_payload_data_end = &actual_pos.status; |
187 | ublox_msg_state = UBLOX_LEN1; |
198 | ublox_msg_state = UBLOX_LEN1; |
188 | } |
199 | } |
189 | break; |
200 | break; |
190 | 201 | ||
191 | case UBLOX_NAV_STATUS: |
202 | case UBLOX_NAV_STATUS: |
192 | ptr_pac_status = &actual_status.status; |
203 | ptr_pac_status = &actual_status.status; |
193 | if (*ptr_pac_status > 0) ublox_msg_state = UBLOX_IDLE; |
204 | if (*ptr_pac_status > 0) ublox_msg_state = UBLOX_IDLE; |
194 | else |
205 | else |
195 | { |
206 | { |
196 | ptr_payload_data = &actual_status; |
207 | ptr_payload_data = &actual_status; |
197 | ptr_payload_data_end = &actual_status.status; |
208 | ptr_payload_data_end = &actual_status.status; |
198 | ublox_msg_state = UBLOX_LEN1; |
209 | ublox_msg_state = UBLOX_LEN1; |
199 | } |
210 | } |
200 | break; |
211 | break; |
201 | 212 | ||
202 | case UBLOX_NAV_VELED: |
213 | case UBLOX_NAV_VELED: |
203 | ptr_pac_status = &actual_speed.status; |
214 | ptr_pac_status = &actual_speed.status; |
204 | if (*ptr_pac_status > 0) ublox_msg_state = UBLOX_IDLE; |
215 | if (*ptr_pac_status > 0) ublox_msg_state = UBLOX_IDLE; |
205 | else |
216 | else |
206 | { |
217 | { |
207 | ptr_payload_data = &actual_speed; |
218 | ptr_payload_data = &actual_speed; |
208 | ptr_payload_data_end = &actual_speed.status; |
219 | ptr_payload_data_end = &actual_speed.status; |
209 | ublox_msg_state = UBLOX_LEN1; |
220 | ublox_msg_state = UBLOX_LEN1; |
210 | } |
221 | } |
211 | break; |
222 | break; |
212 | 223 | ||
213 | default: |
224 | default: |
214 | ublox_msg_state = UBLOX_IDLE; |
225 | ublox_msg_state = UBLOX_IDLE; |
215 | break; |
226 | break; |
216 | } |
227 | } |
217 | chk_a = UBLOX_NAV_CLASS + rx; |
228 | chk_a = UBLOX_NAV_CLASS + rx; |
218 | chk_b = UBLOX_NAV_CLASS + chk_a; |
229 | chk_b = UBLOX_NAV_CLASS + chk_a; |
219 | break; |
230 | break; |
220 | 231 | ||
221 | case UBLOX_LEN1: // Laenge auswerten |
232 | case UBLOX_LEN1: // Laenge auswerten |
222 | rx_len = rx; |
233 | rx_len = rx; |
223 | chk_a += rx; |
234 | chk_a += rx; |
224 | chk_b += chk_a; |
235 | chk_b += chk_a; |
225 | ublox_msg_state = UBLOX_LEN2; |
236 | ublox_msg_state = UBLOX_LEN2; |
226 | break; |
237 | break; |
227 | 238 | ||
228 | 239 | ||
229 | case UBLOX_LEN2: // Laenge auswerten |
240 | case UBLOX_LEN2: // Laenge auswerten |
230 | rx_len = rx_len + (rx *256); // Laenge ermitteln |
241 | rx_len = rx_len + (rx *256); // Laenge ermitteln |
231 | chk_a += rx; |
242 | chk_a += rx; |
232 | chk_b += chk_a; |
243 | chk_b += chk_a; |
233 | ublox_msg_state = UBLOX_PAYLOAD; |
244 | ublox_msg_state = UBLOX_PAYLOAD; |
234 | break; |
245 | break; |
235 | 246 | ||
236 | case UBLOX_PAYLOAD: // jetzt Nutzdaten einlesen |
247 | case UBLOX_PAYLOAD: // jetzt Nutzdaten einlesen |
237 | if (rx_len > 0) |
248 | if (rx_len > 0) |
238 | { |
249 | { |
239 | *ptr_payload_data = rx; |
250 | *ptr_payload_data = rx; |
240 | chk_a += rx; |
251 | chk_a += rx; |
241 | chk_b += chk_a; |
252 | chk_b += chk_a; |
242 | --rx_len; |
253 | --rx_len; |
243 | if ((rx_len > 0) && (ptr_payload_data <= ptr_payload_data_end)) |
254 | if ((rx_len > 0) && (ptr_payload_data <= ptr_payload_data_end)) |
244 | { |
255 | { |
245 | ptr_payload_data++; |
256 | ptr_payload_data++; |
246 | ublox_msg_state = UBLOX_PAYLOAD; |
257 | ublox_msg_state = UBLOX_PAYLOAD; |
247 | } |
258 | } |
248 | else ublox_msg_state = UBLOX_CKA; |
259 | else ublox_msg_state = UBLOX_CKA; |
249 | } |
260 | } |
250 | else ublox_msg_state = UBLOX_IDLE; // Abbruch wegen Fehler |
261 | else ublox_msg_state = UBLOX_IDLE; // Abbruch wegen Fehler |
251 | break; |
262 | break; |
252 | 263 | ||
253 | case UBLOX_CKA: // Checksum pruefen |
264 | case UBLOX_CKA: // Checksum pruefen |
254 | if (rx == chk_a) ublox_msg_state = UBLOX_CKB; |
265 | if (rx == chk_a) ublox_msg_state = UBLOX_CKB; |
255 | else ublox_msg_state = UBLOX_IDLE; // Abbruch wegen Fehler |
266 | else ublox_msg_state = UBLOX_IDLE; // Abbruch wegen Fehler |
256 | break; |
267 | break; |
257 | 268 | ||
258 | case UBLOX_CKB: // Checksum pruefen |
269 | case UBLOX_CKB: // Checksum pruefen |
259 | if (rx == chk_b) *ptr_pac_status = 1; // Paket ok |
270 | if (rx == chk_b) *ptr_pac_status = 1; // Paket ok |
260 | ublox_msg_state = UBLOX_IDLE; |
271 | ublox_msg_state = UBLOX_IDLE; |
261 | break; |
272 | break; |
262 | 273 | ||
263 | default: |
274 | default: |
264 | ublox_msg_state = UBLOX_IDLE; |
275 | ublox_msg_state = UBLOX_IDLE; |
265 | break; |
276 | break; |
- | 277 | } |
|
- | 278 | } |
|
- | 279 | ||
- | 280 | //Zentrale Statemachine fuer alle GPS relevanten Regelungsablauefe |
|
- | 281 | short int GPS_CRTL(short int cmd) |
|
- | 282 | { |
|
- | 283 | static unsigned int cnt; //Zaehler fuer diverse Verzoegerungen |
|
- | 284 | ||
- | 285 | switch (cmd) |
|
- | 286 | { |
|
- | 287 | case GPS_CMD_REQ_HOLD: // Die Lageregelung soll aktiviert werden. |
|
- | 288 | if (gps_state != GPS_CRTL_HOLD_ACTIVE) |
|
- | 289 | { |
|
- | 290 | cnt++; |
|
- | 291 | if (cnt > 300) // erst nach Verzoegerung |
|
- | 292 | { |
|
- | 293 | cnt = 0; |
|
- | 294 | // aktuelle positionsdaten abespeichern |
|
- | 295 | if (gps_rel_act_position.status > 0) |
|
- | 296 | { |
|
- | 297 | gps_rel_hold_position.utm_east = gps_rel_act_position.utm_east; |
|
- | 298 | gps_rel_hold_position.utm_north = gps_rel_act_position.utm_north; |
|
- | 299 | gps_rel_hold_position.status = 1; // gueltige Positionsdaten |
|
- | 300 | gps_state = GPS_CRTL_HOLD_ACTIVE; |
|
- | 301 | return (GPS_STST_OK); |
|
- | 302 | } |
|
- | 303 | else |
|
- | 304 | { |
|
- | 305 | gps_rel_hold_position.status = 0; //Keine Daten verfuegbar |
|
- | 306 | gps_state = GPS_CRTL_IDLE; |
|
- | 307 | return(GPS_STST_ERR); // Keine Daten da |
|
- | 308 | } |
|
- | 309 | } |
|
- | 310 | else return(GPS_STST_PEND); // noch warten |
|
- | 311 | } |
|
- | 312 | break; |
|
- | 313 | ||
- | 314 | case GPS_CMD_STOP_HOLD: // Lageregelung beenden |
|
- | 315 | cnt = 0; |
|
- | 316 | GPS_Nick = 0; |
|
- | 317 | GPS_Roll = 0; |
|
- | 318 | gps_state = GPS_CRTL_IDLE; |
|
- | 319 | return (GPS_STST_OK); |
|
- | 320 | break; |
|
- | 321 | ||
- | 322 | default: |
|
- | 323 | return (GPS_STST_ERR); |
|
- | 324 | break; |
|
- | 325 | } |
|
- | 326 | ||
- | 327 | switch (gps_state) |
|
- | 328 | { |
|
- | 329 | case GPS_CRTL_IDLE: |
|
- | 330 | cnt = 0; |
|
- | 331 | return (GPS_STST_OK); |
|
- | 332 | break; |
|
- | 333 | ||
- | 334 | case GPS_CRTL_HOLD_ACTIVE: // Hier werden die Daten fuer Nick und Roll errechnet |
|
- | 335 | if (gps_updte_flag = 1) //nur wenn neue GPS Daten vorliegen |
|
- | 336 | { |
|
- | 337 | gps_updte_flag = 0; |
|
- | 338 | // ab hier wird geregelt |
|
- | 339 | // Richtung zum Ziel ermitteln |
|
- | 340 | signed int dist_north,dist_east; |
|
- | 341 | dist_east = gps_rel_hold_position.utm_east - gps_rel_act_position.utm_east; |
|
- | 342 | dist_north = gps_rel_hold_position.utm_north - gps_rel_act_position.utm_north; |
|
- | 343 | GPS_hdng_abs_2trgt = arctan_i((long)dist_east,(long)dist_north); |
|
- | 344 | //in Winkel 0..360 grad umrechnen |
|
- | 345 | if ((dist_east >= 0) && (dist_north < 0)) GPS_hdng_abs_2trgt = ( 90-GPS_hdng_abs_2trgt); |
|
- | 346 | else if ((dist_east < 0) ) GPS_hdng_abs_2trgt = (270 - GPS_hdng_abs_2trgt); |
|
- | 347 | ||
- | 348 | // Distanz zum Ziel ermitteln |
|
- | 349 | GPS_dist_2trgt = abs(dist_north) + abs(dist_east);//ACHTUNG: Noch Nicht korrekt |
|
- | 350 | return (GPS_STST_OK); |
|
- | 351 | } |
|
- | 352 | else return (GPS_STST_OK); |
|
- | 353 | break; |
|
- | 354 | ||
- | 355 | default: |
|
- | 356 | gps_state = GPS_CRTL_IDLE; |
|
- | 357 | return (GPS_STST_ERR); |
|
- | 358 | break; |
|
266 | } |
359 | } |
- | 360 | return (GPS_STST_ERR); |
|
- | 361 | ||
267 | } |
362 | } |
268 | 363 | ||
269 | 364 |