-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
DzikuVx
merged 83 commits into
iNavFlight:master
from
RomanLut:submit-gps-fix-estimation
Dec 8, 2023
Merged
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 00b5085
Update GPS_fix_estimation.md
RomanLut ccfa58e
included fixed USER3 BOX ID collision
RomanLut 2272b6e
Merge branch 'submit-gps-fix-estimation' of https://github.com/RomanL…
RomanLut b276d26
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut ffa28d8
updated documentation
RomanLut 7de16ff
retrigger checks
RomanLut 2f6a192
retrigger checks
RomanLut 9f0489e
retrigger checks
RomanLut e93145e
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut e4ff863
fixed rename getAirspeedEstimate()
RomanLut ccad410
retrigger checks
RomanLut bd5a92c
retrigger checks
RomanLut 2b83b16
Update GPS_fix_estimation.md
RomanLut cb2d448
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut 1ed4c3e
Merge branch 'submit-gps-fix-estimation' of https://github.com/RomanL…
RomanLut a439e29
adjusted docs
RomanLut 3ade7e2
fixed typo in comment
RomanLut 01ada27
added failsafe_gps_fix_estimation_delay
RomanLut 731b16c
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut dfd9dff
Update GPS_fix_estimation.md
RomanLut 064a8ee
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut bf3a857
Update GPS_fix_estimation.md
RomanLut 637f072
Merge branch 'submit-gps-fix-estimation' of https://github.com/RomanL…
RomanLut dc71194
show pitot failure status on osd
RomanLut 7591ed5
enable possibility to simulate GPS sensor timeout, mag failure and pi…
RomanLut e602707
fix GPS timeout display on OSD
RomanLut ce9cbd1
estimate GPS Fix only if compass and barometer are healthy
RomanLut 12cb0c5
support GPS Fix estimation on sensor timeout
RomanLut a62bc74
Update GPS_fix_estimation.md
RomanLut 6e7dafb
fixed compilation error
RomanLut caa048c
Merge branch 'submit-gps-fix-estimation' of https://github.com/RomanL…
RomanLut f0d5358
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut 064c6e2
Merge branch 'submit-simulator-sensor-failures' of https://github.com…
RomanLut 7afaa0d
fixed indentation
RomanLut 69a1220
fixed indentation
RomanLut f9e078f
fixed indentation
RomanLut 4c39d77
removed debug code
RomanLut 2ce2904
attempt to fix failsafe_gps_fix_estimation_delay bug
RomanLut a10b7ce
enable ground course estimation
RomanLut 20cdfc8
fixed landing detection with GPS fix estimation
RomanLut ec5e0c8
fixed: forced RTH is not activated on GPS Fix estimation event during…
RomanLut 0fb2c1e
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut 44fea0e
fixed merge conflict
RomanLut cc39912
fixed: groundspeed is not sent in mavlink telemetry
RomanLut 9796bbb
use any wind estimator value with gps fix estimation
RomanLut 55fdeae
improved course hold with GPS Fix estimation
RomanLut 46150ad
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut 4d888e4
fixed gpsSol access race conditions
RomanLut 8c933ed
fixed HITL HW sensors failure simulation
RomanLut 7d007a5
use wind vector for course correction on estimation on gps timeout
RomanLut cdd299f
fixed gps fix estimation on gps timeout
RomanLut 3040cd7
return 99 satellites for logic condition on estimation
RomanLut daac5b5
removed redundand code
RomanLut f18b5a0
allow course correction on estimation with gps sensor timeout
RomanLut 7e777fa
Update GPS_fix_estimation.md
RomanLut 221d300
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut d5187ed
Merge branch 'submit-gps-fix-estimation' of https://github.com/RomanL…
RomanLut ff1cd25
fixed compilation error
RomanLut 8778980
Update GPS_fix_estimation.md
RomanLut 2b9a5a6
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut 5eb46f5
Update GPS_fix_estimation.md
RomanLut 8b1330c
Update GPS_fix_estimation.md
RomanLut ee66d0f
Update GPS_fix_estimation.md
RomanLut ae5c144
Update GPS_fix_estimation.md
RomanLut 599e45c
added USE_GPS_FIX_ESTIMATION
RomanLut 9e6df5f
Merge branch 'submit-gps-fix-estimation' of https://github.com/RomanL…
RomanLut 4602a83
fixed unit test error
RomanLut dc1d2e8
ignore project file
RomanLut 86b875d
allow gps fix estimation without compass
RomanLut 6168348
Update GPS_fix_estimation.md
RomanLut 713b521
Update GPS_fix_estimation.md
RomanLut 0829ef6
Update GPS_fix_estimation.md
RomanLut 3ee200d
Update GPS_fix_estimation.md
RomanLut f05dcc1
Update GPS_fix_estimation.md
RomanLut 9cd68b1
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut 8a1dd1c
Merge branch 'submit-gps-fix-estimation' of https://github.com/RomanL…
RomanLut b7745af
fixed compilation error
RomanLut e4453c3
Merge branch 'master' of https://github.com/RomanLut/inav into submit…
RomanLut a08e8c4
Merge branch 'master' of https://github.com/iNavFlight/inav into subm…
RomanLut 9a633d1
Merge branch 'master' of https://github.com/iNavFlight/inav into subm…
RomanLut f3359ef
Update GPS_fix_estimation.md
RomanLut 229eac4
Update GPS_fix_estimation.md
RomanLut File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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 | ||
|
@@ -154,6 +277,8 @@ void gpsProcessNewSolutionData(void) | |
// Set sensor as ready and available | ||
sensorsSet(SENSOR_GPS); | ||
|
||
updateEstimatedGPSFix(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be conditional on |
||
|
||
// Pass on GPS update to NAV and IMU | ||
onNewGPSData(); | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 ?