Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPS Fix estimation (dead reconing, RTH without GPS fix) for fixed wing #8347

Merged
merged 83 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
f87c081
gps fix estimation squashed commit
RomanLut Aug 21, 2022
00b5085
Update GPS_fix_estimation.md
RomanLut Aug 21, 2022
ccfa58e
included fixed USER3 BOX ID collision
RomanLut Aug 21, 2022
2272b6e
Merge branch 'submit-gps-fix-estimation' of https://github.com/RomanL…
RomanLut Aug 21, 2022
b276d26
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut Aug 22, 2022
ffa28d8
updated documentation
RomanLut Aug 22, 2022
7de16ff
retrigger checks
RomanLut Aug 22, 2022
2f6a192
retrigger checks
RomanLut Aug 22, 2022
9f0489e
retrigger checks
RomanLut Aug 22, 2022
e93145e
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut Aug 22, 2022
e4ff863
fixed rename getAirspeedEstimate()
RomanLut Aug 22, 2022
ccad410
retrigger checks
RomanLut Aug 22, 2022
bd5a92c
retrigger checks
RomanLut Aug 22, 2022
2b83b16
Update GPS_fix_estimation.md
RomanLut Sep 26, 2022
cb2d448
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut Dec 10, 2022
1ed4c3e
Merge branch 'submit-gps-fix-estimation' of https://github.com/RomanL…
RomanLut Dec 10, 2022
a439e29
adjusted docs
RomanLut Dec 10, 2022
3ade7e2
fixed typo in comment
RomanLut Dec 28, 2022
01ada27
added failsafe_gps_fix_estimation_delay
RomanLut Dec 28, 2022
731b16c
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut Dec 28, 2022
dfd9dff
Update GPS_fix_estimation.md
RomanLut Dec 29, 2022
064a8ee
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut Feb 14, 2023
bf3a857
Update GPS_fix_estimation.md
RomanLut Feb 15, 2023
637f072
Merge branch 'submit-gps-fix-estimation' of https://github.com/RomanL…
RomanLut Feb 19, 2023
dc71194
show pitot failure status on osd
RomanLut Feb 27, 2023
7591ed5
enable possibility to simulate GPS sensor timeout, mag failure and pi…
RomanLut Feb 26, 2023
e602707
fix GPS timeout display on OSD
RomanLut Mar 5, 2023
ce9cbd1
estimate GPS Fix only if compass and barometer are healthy
RomanLut Mar 5, 2023
12cb0c5
support GPS Fix estimation on sensor timeout
RomanLut Mar 6, 2023
a62bc74
Update GPS_fix_estimation.md
RomanLut Mar 6, 2023
6e7dafb
fixed compilation error
RomanLut Mar 6, 2023
caa048c
Merge branch 'submit-gps-fix-estimation' of https://github.com/RomanL…
RomanLut Mar 6, 2023
f0d5358
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut Mar 6, 2023
064c6e2
Merge branch 'submit-simulator-sensor-failures' of https://github.com…
RomanLut Mar 6, 2023
7afaa0d
fixed indentation
RomanLut Mar 6, 2023
69a1220
fixed indentation
RomanLut Mar 6, 2023
f9e078f
fixed indentation
RomanLut Mar 6, 2023
4c39d77
removed debug code
RomanLut Mar 6, 2023
2ce2904
attempt to fix failsafe_gps_fix_estimation_delay bug
RomanLut Mar 6, 2023
a10b7ce
enable ground course estimation
RomanLut Mar 8, 2023
20cdfc8
fixed landing detection with GPS fix estimation
RomanLut Mar 8, 2023
ec5e0c8
fixed: forced RTH is not activated on GPS Fix estimation event during…
RomanLut Mar 8, 2023
0fb2c1e
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut Apr 5, 2023
44fea0e
fixed merge conflict
RomanLut Apr 5, 2023
cc39912
fixed: groundspeed is not sent in mavlink telemetry
RomanLut Apr 25, 2023
9796bbb
use any wind estimator value with gps fix estimation
RomanLut Apr 27, 2023
55fdeae
improved course hold with GPS Fix estimation
RomanLut Apr 27, 2023
46150ad
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut Apr 27, 2023
4d888e4
fixed gpsSol access race conditions
RomanLut May 19, 2023
8c933ed
fixed HITL HW sensors failure simulation
RomanLut Apr 28, 2023
7d007a5
use wind vector for course correction on estimation on gps timeout
RomanLut May 19, 2023
cdd299f
fixed gps fix estimation on gps timeout
RomanLut May 19, 2023
3040cd7
return 99 satellites for logic condition on estimation
RomanLut May 19, 2023
daac5b5
removed redundand code
RomanLut May 19, 2023
f18b5a0
allow course correction on estimation with gps sensor timeout
RomanLut May 19, 2023
7e777fa
Update GPS_fix_estimation.md
RomanLut May 19, 2023
221d300
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut May 20, 2023
d5187ed
Merge branch 'submit-gps-fix-estimation' of https://github.com/RomanL…
RomanLut May 20, 2023
ff1cd25
fixed compilation error
RomanLut May 20, 2023
8778980
Update GPS_fix_estimation.md
RomanLut Jul 7, 2023
2b9a5a6
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut Aug 3, 2023
5eb46f5
Update GPS_fix_estimation.md
RomanLut Aug 4, 2023
8b1330c
Update GPS_fix_estimation.md
RomanLut Aug 4, 2023
ee66d0f
Update GPS_fix_estimation.md
RomanLut Aug 4, 2023
ae5c144
Update GPS_fix_estimation.md
RomanLut Aug 4, 2023
599e45c
added USE_GPS_FIX_ESTIMATION
RomanLut Aug 9, 2023
9e6df5f
Merge branch 'submit-gps-fix-estimation' of https://github.com/RomanL…
RomanLut Aug 9, 2023
4602a83
fixed unit test error
RomanLut Aug 9, 2023
dc1d2e8
ignore project file
RomanLut Aug 9, 2023
86b875d
allow gps fix estimation without compass
RomanLut Sep 3, 2023
6168348
Update GPS_fix_estimation.md
RomanLut Sep 3, 2023
713b521
Update GPS_fix_estimation.md
RomanLut Sep 3, 2023
0829ef6
Update GPS_fix_estimation.md
RomanLut Sep 3, 2023
3ee200d
Update GPS_fix_estimation.md
RomanLut Sep 3, 2023
f05dcc1
Update GPS_fix_estimation.md
RomanLut Sep 3, 2023
9cd68b1
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut Sep 3, 2023
8a1dd1c
Merge branch 'submit-gps-fix-estimation' of https://github.com/RomanL…
RomanLut Sep 3, 2023
b7745af
fixed compilation error
RomanLut Sep 3, 2023
e4453c3
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut Sep 30, 2023
a08e8c4
Merge branch 'master' of https://github.com/iNavFlight/inav into subm…
RomanLut Oct 27, 2023
9a633d1
Merge branch 'master' of https://github.com/iNavFlight/inav into subm…
RomanLut Nov 3, 2023
f3359ef
Update GPS_fix_estimation.md
RomanLut Nov 3, 2023
229eac4
Update GPS_fix_estimation.md
RomanLut Nov 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions docs/GPS_fix_estimation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# GPS Fix estimation (dead reconing, RTH without GPS) for fixed wing

Video demonstration

[![IMAGE ALT TEXT HERE](https://img.youtube.com/vi/wzvgRpXCS4U/0.jpg)](https://www.youtube.com/watch?v=wzvgRpXCS4U)

There is possibility to allow plane to estimate it's position when GPS fix is lost.
The main purpose is RTH without GPS.
It works for fixed wing only.

Plane should have the following sensors:
- acceleromenter, gyroscope
- barometer
- GPS
- magnethometer
- pitot (optional)

By befault, all navigation modes are disabled when GPS fix is lost. If RC signal is lost also, plane will not be able to enable RTH. Plane will switch to LANDING instead. When flying above inreachable spaces, plane will be lost.

GPS fix estimation allows to recover plane using magnetometer and baromener only.

Note, that GPS fix estimation is not a solution for navigation without GPS. Without GPS fix, position error accumulates quickly. But it is acceptable for RTH.

# How it works ?

In normal situation, plane is receiving it's position from GPS sensor. This way it is able to hold course, RTH or navigate by waypoints.


Without GPS fix, plane has nose heading from magnetometer only.

To navigate without GPS fix, we make the following assumptions:
- plane is flying in the direction where nose is pointing
- (if pitot tube is not installed) plane is flying with constant airspeed, specified in settings

It is posible to roughtly estimate position using theese assumptions. To increase accuracy, plane will use information about wind direction and speed, estimated before GPS fix was lost. To increase groundspeed estimation accuracy, plane will use pitot tube data(if available).

From estimated heading direction and speed, plane is able to **roughtly** estimate it's position.

It is assumed, that plane will fly in roughtly estimated direction to home position untill either GPS fix or RC signal is recovered.

*Plane has to aquire GPS fix and store home position before takeoff. Estimation completely without GPS fix will not work*.

# Settings

GPS Fix estimation is enabled with CLI command:

```set inav_allow_gps_fix_estimation=ON```

Also you have to specify criuse airspeed of the plane.

To find out cruise airspeed, make a test flight. Enable ground speed display on OSD. Flight in CRUISE mode in two opposite directions. Take average speed.

Cruise airspeed is specified in cm/s.

To convert km/h to m/s, multiply by 27.77.


Example: 100 km/h = 100 * 27.77 = 2777 cm/s

```set fw_reference_airspeed=2777```

*It is important, that plane fly with specified speed in CRUISE mode. If you have set option "Increase cruise speed with throttle" - do not use it without GPS Fix.*

*If pitot is available, pitot sensor data will be used instead of constant.*

*Note related command: to continue mission without RC signal, see command ```set failsafe_mission=OFF```.*

**After entering CLI command, make sure that settings are saved:**

```save```

# Disabling GPS sensor from RC controller

![](Screenshots/programming_disable_gps_sensor_fix.png)

For testing purpoces, it is possible to disable GPS sensor fix from RC controller in programming tab:

*GPS can be disabled only after 1) initial GPS fix is acquired 2) in ARMED mode.*

# Allowing wp missions with GPS Fix estimation

```failsafe_gps_fix_estimation_delay```

Controls whether waypoint mission is allowed to proceed with gps fix estimation. Sets the time delay in seconds between gps fix lost event and RTH activation. Minimum delay is 7 seconds. If set to -1 the mission will continue until the end. With default setting(7), waypoint mission is aborted and switched to RTH with 7 seconds delay. RTH is done with GPS Fix estimation.

# Is it possible to implement this for multirotor ?

There are some ideas, but there is no solution now. We can not make assumptions with multirotor which we can make with a fixed wing.


# Links

INAV HITL https://github.com/RomanLut/INAV-X-Plane-HITL
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions docs/Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,16 @@ Requested yaw rate to execute when `LAND` (or old `SET-THR`) failsafe is active

---

### failsafe_gps_fix_estimation_delay

Controls whether waypoint mission is allowed to proceed with gps fix estimation. Sets the time delay in seconds between gps fix lost event and RTH activation. Minimum delay is 7 seconds. If set to -1 the mission will continue until the end. With default setting(7), waypoint mission is aborted and switched to RTH with 7 seconds delay. RTH is done with GPS Fix estimation.

| Default | Min | Max |
| --- | --- | --- |
| 7 | -1 | 600 |

---

### failsafe_lights

Enable or disable the lights when the `FAILSAFE` flight mode is enabled. The target needs to be compiled with `USE_LIGHTS` [ON/OFF].
Expand Down Expand Up @@ -1712,6 +1722,16 @@ Defines if INAV will dead-reckon over short GPS outages. May also be useful for

---

### inav_allow_gps_fix_estimation

Defines if inav will estimate GPS fix with magnetometer and barometer on GPS outages. Enables navigation and RTH without GPS fix on fixed wing. Also see failsafe_gps_fix_estimation_delay.

| Default | Min | Max |
| --- | --- | --- |
| OFF | OFF | ON |

---

### inav_auto_mag_decl

Automatic setting of magnetic declination based on GPS position. When used manual magnetic declination is ignored.
Expand Down
1 change: 1 addition & 0 deletions src/main/fc/runtime_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ typedef enum {
NAV_MOTOR_STOP_OR_IDLE = (1 << 7), // navigation requests MOTOR_STOP or motor idle regardless of throttle stick, will only activate if MOTOR_STOP feature is available
COMPASS_CALIBRATED = (1 << 8),
ACCELEROMETER_CALIBRATED = (1 << 9),
GPS_ESTIMATED_FIX = (1 << 10),
NAV_CRUISE_BRAKING = (1 << 11),
NAV_CRUISE_BRAKING_BOOST = (1 << 12),
NAV_CRUISE_BRAKING_LOCKED = (1 << 13),
Expand Down
10 changes: 10 additions & 0 deletions src/main/fc/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,11 @@ groups:
default_value: 0
min: -1
max: 600
- name: failsafe_gps_fix_estimation_delay
description: "Controls whether waypoint mission is allowed to proceed with gps fix estimation. Sets the time delay in seconds between gps fix lost event and RTH activation. Minimum delay is 7 seconds. If set to -1 the mission will continue until the end. With default setting(7), waypoint mission is aborted and switched to RTH with 7 seconds delay. RTH is done with GPS Fix estimation."
default_value: 7
min: -1
max: 600

- name: PG_LIGHTS_CONFIG
type: lightsConfig_t
Expand Down Expand Up @@ -2188,6 +2193,11 @@ groups:
default_value: OFF
field: allow_dead_reckoning
type: bool
- name: inav_allow_gps_fix_estimation
description: "Defines if inav will estimate GPS fix with magnetometer and barometer on GPS outages. Enables navigation and RTH without GPS fix on fixed wing. Also see failsafe_gps_fix_estimation_delay."
default_value: OFF
field: allow_gps_fix_estimation
type: bool
- name: inav_reset_altitude
description: "Defines when relative estimated altitude is reset to zero. Variants - `NEVER` (once reference is acquired it's used regardless); `FIRST_ARM` (keep altitude at zero until firstly armed), `EACH_ARM` (altitude is reset to zero on each arming)"
default_value: "FIRST_ARM"
Expand Down
15 changes: 14 additions & 1 deletion src/main/flight/failsafe.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ PG_RESET_TEMPLATE(failsafeConfig_t, failsafeConfig,
.failsafe_min_distance = SETTING_FAILSAFE_MIN_DISTANCE_DEFAULT, // No minimum distance for failsafe by default
.failsafe_min_distance_procedure = SETTING_FAILSAFE_MIN_DISTANCE_PROCEDURE_DEFAULT, // default minimum distance failsafe procedure
.failsafe_mission_delay = SETTING_FAILSAFE_MISSION_DELAY_DEFAULT, // Time delay before Failsafe activated during WP mission (s)
.failsafe_gps_fix_estimation_delay = SETTING_FAILSAFE_GPS_FIX_ESTIMATION_DELAY_DEFAULT, // Time delay before Failsafe activated when GPS Fix estimation is allied
);

typedef enum {
Expand Down Expand Up @@ -349,7 +350,7 @@ static failsafeProcedure_e failsafeChooseFailsafeProcedure(void)
// Craft is closer than minimum failsafe procedure distance (if set to non-zero)
// GPS must also be working, and home position set
if (failsafeConfig()->failsafe_min_distance > 0 &&
sensors(SENSOR_GPS) && STATE(GPS_FIX) && STATE(GPS_FIX_HOME)) {
sensors(SENSOR_GPS) && (STATE(GPS_FIX) || STATE(GPS_ESTIMATED_FIX)) && STATE(GPS_FIX_HOME)) {

// get the distance to the original arming point
uint32_t distance = calculateDistanceToDestination(&original_rth_home);
Expand Down Expand Up @@ -403,6 +404,18 @@ void failsafeUpdateState(void)
}
reprocessState = true;
}
else {
if (STATE(GPS_ESTIMATED_FIX) && (FLIGHT_MODE(NAV_WP_MODE) || isWaypointMissionRTHActive()) && (failsafeConfig()->failsafe_gps_fix_estimation_delay >= 0)) {
if (!failsafeState.wpModeGPSFixEstimationDelayedFailsafeStart) {
failsafeState.wpModeGPSFixEstimationDelayedFailsafeStart = millis();
} else if ((millis() - failsafeState.wpModeGPSFixEstimationDelayedFailsafeStart) > (MILLIS_PER_SECOND * (uint16_t)MAX(failsafeConfig()->failsafe_gps_fix_estimation_delay,7))) {
failsafeSetActiveProcedure(FAILSAFE_PROCEDURE_RTH);
failsafeActivate(FAILSAFE_RETURN_TO_HOME);
activateForcedRTH();
}
} else
failsafeState.wpModeGPSFixEstimationDelayedFailsafeStart = 0;
}
} else {
// When NOT armed, show rxLinkState of failsafe switch in GUI (failsafe mode)
if (!receivingRxDataAndNotFailsafeMode) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/flight/failsafe.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef struct failsafeConfig_s {
uint16_t failsafe_min_distance; // Minimum distance required for failsafe procedure to be taken. 1 step = 1 centimeter. 0 = Regular failsafe_procedure always active (default)
uint8_t failsafe_min_distance_procedure; // selected minimum distance failsafe procedure is 0: auto-landing, 1: Drop it, 2: Return To Home (RTH)
int16_t failsafe_mission_delay; // Time delay before Failsafe triggered when WP mission in progress (s)
int16_t failsafe_gps_fix_estimation_delay; // Time delay before Failsafe triggered when GPX Fix estimation is applied (s)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tabbed indentation ? https://github.com/iNavFlight/inav/blob/master/docs/development/Development.md

Thought the checking system complained about this ?

} failsafeConfig_t;

PG_DECLARE(failsafeConfig_t, failsafeConfig);
Expand Down Expand Up @@ -149,6 +150,7 @@ typedef struct failsafeState_s {
timeMs_t receivingRxDataPeriod; // period for the required period of valid rxData
timeMs_t receivingRxDataPeriodPreset; // preset for the required period of valid rxData
timeMs_t wpModeDelayedFailsafeStart; // waypoint mission delayed failsafe timer start time
timeMs_t wpModeGPSFixEstimationDelayedFailsafeStart; // waypoint mission delayed failsafe timer start time on GPS fix estimation
failsafeProcedure_e activeProcedure;
failsafePhase_e phase;
failsafeRxLinkState_e rxLinkState;
Expand Down
3 changes: 2 additions & 1 deletion src/main/flight/wind_estimator.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ void updateWindEstimator(timeUs_t currentTimeUs)
if (!STATE(FIXED_WING_LEGACY) ||
!isGPSHeadingValid() ||
!gpsSol.flags.validVelNE ||
!gpsSol.flags.validVelD) {
!gpsSol.flags.validVelD ||
STATE(GPS_ESTIMATED_FIX)){
return;
}

Expand Down
125 changes: 125 additions & 0 deletions src/main/io/gps.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,33 @@
#include "fc/runtime_config.h"
#endif

#include "fc/rc_modes.h"

#include "sensors/sensors.h"
#include "sensors/compass.h"
#include "sensors/barometer.h"
#include "sensors/pitotmeter.h"

#include "io/serial.h"
#include "io/gps.h"
#include "io/gps_private.h"

#include "navigation/navigation.h"
#include "navigation/navigation_private.h"

#include "config/feature.h"

#include "fc/config.h"
#include "fc/runtime_config.h"
#include "fc/settings.h"

#include "flight/imu.h"
#include "flight/wind_estimator.h"
#include "flight/pid.h"
#include "flight/mixer.h"

#include "programming/logic_condition.h"

typedef struct {
bool isDriverBased;
portMode_t portMode; // Port mode RX/TX (only for serial based)
Expand Down Expand Up @@ -137,6 +149,117 @@ void gpsSetProtocolTimeout(timeMs_t timeoutMs)
gpsState.timeoutMs = timeoutMs;
}


bool canEstimateGPSFix(void)
{
return positionEstimationConfig()->allow_gps_fix_estimation && STATE(AIRPLANE) && sensors(SENSOR_GPS) && sensors(SENSOR_BARO) && sensors(SENSOR_MAG) && ARMING_FLAG(WAS_EVER_ARMED) && STATE(GPS_FIX_HOME);
}

void updateEstimatedGPSFix(void) {

static uint32_t lastUpdateMs = 0;
static int32_t estimated_lat = 0;
static int32_t estimated_lon = 0;
static int32_t estimated_alt = 0;

uint32_t t = millis();
int32_t dt = t - lastUpdateMs;
lastUpdateMs = t;

static int32_t last_lat = 0;
static int32_t last_lon = 0;
static int32_t last_alt = 0;

if (LOGIC_CONDITION_GLOBAL_FLAG(LOGIC_CONDITION_GLOBAL_FLAG_DISABLE_GPS_FIX))
{
gpsSol.fixType = GPS_NO_FIX;
gpsSol.hdop = 9999;
gpsSol.numSat = 0;

//freeze coordinates
gpsSol.llh.lat = last_lat;
gpsSol.llh.lon = last_lon;
gpsSol.llh.alt = last_alt;

DISABLE_STATE(GPS_FIX);
}
else
{
last_lat = gpsSol.llh.lat;
last_lon = gpsSol.llh.lon;
last_alt = gpsSol.llh.alt;
}

if (STATE(GPS_FIX) || !canEstimateGPSFix()) {
DISABLE_STATE(GPS_ESTIMATED_FIX);
estimated_lat = gpsSol.llh.lat;
estimated_lon = gpsSol.llh.lon;
estimated_alt = posControl.gpsOrigin.alt + baro.BaroAlt;
return;
}

ENABLE_STATE(GPS_ESTIMATED_FIX);

gpsSol.fixType = GPS_FIX_3D;
gpsSol.hdop = 99;
gpsSol.flags.hasNewData = true;
gpsSol.numSat = 99;

gpsSol.eph = 100;
gpsSol.epv = 100;

gpsSol.flags.validVelNE = 1;
gpsSol.flags.validVelD = 0; //do not provide velocity.z
gpsSol.flags.validEPE = 1;

float speed = pidProfile()->fixedWingReferenceAirspeed;

#ifdef USE_PITOT
if (sensors(SENSOR_PITOT) && pitotIsHealthy())
{
speed = getAirspeedEstimate();
}
#endif

float velX = rMat[0][0] * speed;
float velY = -rMat[1][0] * speed;
// here (velX, velY) is estimated horizontal speed without wind influence = airspeed, cm/sec in NEU frame

if (isEstimatedWindSpeedValid()) {
velX += getEstimatedWindSpeed(X);
velY += getEstimatedWindSpeed(Y);
}
// here (velX, velY) is estimated horizontal speed with wind influence = ground speed

if (STATE(LANDING_DETECTED) || ((posControl.navState == NAV_STATE_RTH_LANDING) && (getThrottlePercent() == 0)))
{
velX = 0;
velY = 0;
}

estimated_lat += (int32_t)( velX * dt / (DISTANCE_BETWEEN_TWO_LONGITUDE_POINTS_AT_EQUATOR * 1000 ) );
estimated_lon += (int32_t)( velY * dt / (DISTANCE_BETWEEN_TWO_LONGITUDE_POINTS_AT_EQUATOR * 1000 * posControl.gpsOrigin.scale) );
estimated_alt = posControl.gpsOrigin.alt + baro.BaroAlt;

gpsSol.llh.lat = estimated_lat;
gpsSol.llh.lon = estimated_lon;
gpsSol.llh.alt = estimated_alt;

gpsSol.groundSpeed = (int16_t)fast_fsqrtf(velX * velX + velY * velY);

float groundCourse = atan2_approx(velY, velX); // atan2 returns [-M_PI, M_PI], with 0 indicating the vector points in the X direction
if (groundCourse < 0) {
groundCourse += 2 * M_PIf;
}
gpsSol.groundCourse = RADIANS_TO_DECIDEGREES(groundCourse);

gpsSol.velNED[X] = (int16_t)(velX);
gpsSol.velNED[Y] = (int16_t)(velY);
gpsSol.velNED[Z] = 0;
}



void gpsProcessNewSolutionData(void)
{
// Set GPS fix flag only if we have 3D fix
Expand All @@ -154,6 +277,8 @@ void gpsProcessNewSolutionData(void)
// Set sensor as ready and available
sensorsSet(SENSOR_GPS);

updateEstimatedGPSFix();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be conditional on allow_gps_fix_estimation setting or canEstimateGPSFix being true surely ? No point calling this if use option not set, isn't a plane, has no mag etc.


// Pass on GPS update to NAV and IMU
onNewGPSData();

Expand Down
Loading