2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
23 #include "common/axis.h"
24 #include "common/time.h"
28 #define GPS_DEGREES_DIVIDER 10000000L
35 } gpsCoordinateType_e
;
52 #define SBAS_MODE_MAX SBAS_GAGAN
61 GPS_BAUDRATE_115200
= 0,
69 GPS_AUTOCONFIG_OFF
= 0,
85 #define GPS_BAUDRATE_MAX GPS_BAUDRATE_9600
87 typedef struct gpsConfig_s
{
88 gpsProvider_e provider
;
90 gpsAutoConfig_e autoConfig
;
91 gpsAutoBaud_e autoBaud
;
92 uint8_t gps_ublox_use_galileo
;
93 ubloxMode_e gps_ublox_mode
;
94 uint8_t gps_set_home_point_once
;
95 uint8_t gps_use_3d_speed
;
96 uint8_t sbas_integrity
;
99 PG_DECLARE(gpsConfig_t
, gpsConfig
);
101 typedef struct gpsCoordinateDDDMMmmmm_s
{
104 } gpsCoordinateDDDMMmmmm_t
;
106 /* LLH Location in NEU axis system */
107 typedef struct gpsLocation_s
{
108 int32_t lat
; // latitude * 1e+7
109 int32_t lon
; // longitude * 1e+7
110 int32_t altCm
; // altitude in 0.01m
113 typedef struct gpsSolutionData_s
{
115 uint16_t speed3d
; // speed in 0.1m/s
116 uint16_t groundSpeed
; // speed in 0.1m/s
117 uint16_t groundCourse
; // degrees * 10
118 uint16_t hdop
; // generic HDOP value (*100)
122 typedef struct gpsData_s
{
123 uint32_t errors
; // gps error counter - crc error/lost of data/sync etc..
125 uint32_t lastMessage
; // last time valid GPS data was received (millis)
126 uint32_t lastLastMessage
; // last-last valid GPS message. Used to calculate delta.
128 uint32_t state_position
; // incremental variable for loops
129 uint32_t state_ts
; // timestamp for last state_position increment
130 uint8_t state
; // GPS thread state. Used for detecting cable disconnects and configuring attached devices
131 uint8_t baudrateIndex
; // index into auto-detecting or current baudrate
133 uint8_t ackWaitingMsgId
; // Message id when waiting for ACK
134 uint8_t ackTimeoutCounter
; // Ack timeout counter
135 ubloxAckState_e ackState
;
140 #define GPS_PACKET_LOG_ENTRY_COUNT 21 // To make this useful we should log as many packets as we can fit characters a single line of a OLED display.
141 extern char gpsPacketLog
[GPS_PACKET_LOG_ENTRY_COUNT
];
143 extern int32_t GPS_home
[2];
144 extern uint16_t GPS_distanceToHome
; // distance to home point in meters
145 extern int16_t GPS_directionToHome
; // direction to home or hol point in degrees
146 extern uint32_t GPS_distanceFlownInCm
; // distance flown since armed in centimeters
147 extern int16_t GPS_verticalSpeedInCmS
; // vertical speed in cm/s
148 extern int16_t GPS_angle
[ANGLE_INDEX_COUNT
]; // it's the angles that must be applied for GPS correction
149 extern float dTnav
; // Delta Time in milliseconds for navigation computations, updated with every good GPS read
150 extern float GPS_scaleLonDown
; // this is used to offset the shrinking longitude as we go towards the poles
151 extern int16_t nav_takeoff_bearing
;
154 GPS_DIRECT_TICK
= 1 << 0,
155 GPS_MSP_UPDATE
= 1 << 1
158 extern gpsData_t gpsData
;
159 extern gpsSolutionData_t gpsSol
;
161 #define GPS_SV_MAXSATS_LEGACY 16
162 #define GPS_SV_MAXSATS_M8N 32
163 #define GPS_SV_MAXSATS_M9N 42
165 extern uint8_t GPS_update
; // toogle to distinct a GPS position update (directly or via MSP)
166 extern uint32_t GPS_packetCount
;
167 extern uint32_t GPS_svInfoReceivedCount
;
168 extern uint8_t GPS_numCh
; // Number of channels
169 extern uint8_t GPS_svinfo_chn
[GPS_SV_MAXSATS_M8N
]; // When NumCh is 16 or less: Channel number
170 // When NumCh is more than 16: GNSS Id
171 // 0 = GPS, 1 = SBAS, 2 = Galileo, 3 = BeiDou
172 // 4 = IMES, 5 = QZSS, 6 = Glonass
173 extern uint8_t GPS_svinfo_svid
[GPS_SV_MAXSATS_M8N
]; // Satellite ID
174 extern uint8_t GPS_svinfo_quality
[GPS_SV_MAXSATS_M8N
]; // When NumCh is 16 or less: Bitfield Qualtity
175 // When NumCh is more than 16: flags
176 // bits 2..0: signal quality indicator
178 // 1 = searching signal
179 // 2 = signal acquired
180 // 3 = signal detected but unusable
181 // 4 = code locked and time synchronized
182 // 5,6,7 = code and carrier locked and time synchronized
184 // 1 = signal currently being used for navigaion
185 // bits 5..4: signal health flag
190 // 1 = differential correction data available for this SV
192 // 1 = carrier smoothed pseudorange used
193 extern uint8_t GPS_svinfo_cno
[GPS_SV_MAXSATS_M8N
]; // Carrier to Noise Ratio (Signal Strength)
195 #define GPS_DBHZ_MIN 0
196 #define GPS_DBHZ_MAX 55
198 #define TASK_GPS_RATE 100
199 #define TASK_GPS_RATE_FAST 1000
202 void gpsUpdate(timeUs_t currentTimeUs
);
203 bool gpsNewFrame(uint8_t c
);
204 bool gpsIsHealthy(void); // Check for healthy communications
206 void gpsEnablePassthrough(struct serialPort_s
*gpsPassthroughPort
);
207 void onGpsNewData(void);
208 void GPS_reset_home_position(void);
209 void GPS_calc_longitude_scaling(int32_t lat
);
210 void GPS_distance_cm_bearing(int32_t *currentLat1
, int32_t *currentLon1
, int32_t *destinationLat2
, int32_t *destinationLon2
, uint32_t *dist
, int32_t *bearing
);
211 void gpsSetFixState(bool state
);