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
Improve GPS Rescue Pitch smoothing and disarming #12343
Conversation
55c8d77
to
d24b7d4
Compare
This comment has been minimized.
This comment has been minimized.
d24b7d4
to
0d49ea2
Compare
This comment has been minimized.
This comment has been minimized.
AUTOMERGE: (FAIL)
|
Is this realy 150 m/s --> 540 km/h descent rate? (maybe 10-15 m/s?) |
|
Sorry, that was a typo, fixed. I should have said 1.00 -> 1.50 m/s descent rate (100 to 150 in CLI, cm/s), as pointed out above. Note that this is the terminal descent rate when close to the ground, the descent rate at higher altitude can be up to 3x quicker. |
0584565
to
6de0385
Compare
This comment has been minimized.
This comment has been minimized.
ed0bac5
to
deb8d7f
Compare
This comment has been minimized.
This comment has been minimized.
I installed betaflight_4.5.0_STM32F7X2_f0acc7c.hex, with option gps in the configurator enabled. But the feature gps cannot be enabled in the cli or config tab. A gps is configured in the ports tab. |
deb8d7f
to
76f616a
Compare
This comment has been minimized.
This comment has been minimized.
76f616a
to
b9981c2
Compare
This comment has been minimized.
This comment has been minimized.
Tested - works well. Much smoother. 100% reliable disarms whereas before I had a small percentage too early.Default of 7.5m/s (26kph) is nice and steady. I've tested returns at 15m/s (54kph) and at 22m/s (80kph) into 30kph headwind, no problem. For these I increased the filter cutoff to 200 to ensure brisk responses; was surprisingly smooth. If you do go fast, please give some distance for the quad to slow down in. Say 50m for 15m/s or 75m for 22m/s. Otherwise its easy to overshoot home and have to circle around, which gets scrappy. The code will pull about 1-1.5G's to slow down. |
This comment has been minimized.
This comment has been minimized.
17bf406
to
9dfba23
Compare
@@ -540,7 +556,7 @@ static void sensorUpdate(void) | |||
|
|||
if (rescueState.phase == RESCUE_LANDING) { | |||
// do this at sensor update rate, not the much slower GPS rate, for quick disarm | |||
rescueState.sensor.accMagnitude = (float) sqrtf(sq(acc.accADC[Z]) + sq(acc.accADC[X]) + sq(acc.accADC[Y])) * acc.dev.acc_1G_rec; | |||
rescueState.sensor.accMagnitude = (float) sqrtf(sq(acc.accADC[Z] - acc.dev.acc_1G) + sq(acc.accADC[X]) + sq(acc.accADC[Y])) * acc.dev.acc_1G_rec; |
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.
rescueState.sensor.accMagnitude = (float) sqrtf(sq(acc.accADC[Z] - acc.dev.acc_1G) + sq(acc.accADC[X]) + sq(acc.accADC[Y])) * acc.dev.acc_1G_rec; | |
// Warning: this line assumes that the gravity vector is perfectly aligned with the attitude vector at all times | |
rescueState.sensor.accMagnitude = (float) sqrtf(sq(acc.accADC[Z] - acc.dev.acc_1G) + sq(acc.accADC[X]) + sq(acc.accADC[Y])) * acc.dev.acc_1G_rec; |
This change looks dangerous (as in "mathematically dangerous" 🙂). It assumes that the quad is perfectly aligned with the horizon at all times. Since the quad should be pretty much level in the landing phase this is a somewhat good assumption. But at least there should be a comment that is warning about this assumption, imo.
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.
Better would just be to calculate the true non gravity acceleration that the drone is experiencing. That will be used to fuse gps and acc anyhow
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.
Good point. I'll add a warning.
This works much more reliably than the previous 'assumptions' :-)
I agree that a value that provided non-gravity acceleration would be much better; it would be great if that can be provided at some point in the future.
If, during landing phase the quad is on a steeper angle, that's likely part of an awkard landing, or it is rolling over, and if that outcome in the existing code results in a greater sensitivity to disarm, this 'peculiarity' is, of itself, not so bad.
This comment has been minimized.
This comment has been minimized.
1d6b478
to
b7f44af
Compare
This comment has been minimized.
This comment has been minimized.
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.
Did testing today for this PR, everything seems to be ok.
Maybe need to do something with the jumping from the ground (end of video)
https://youtu.be/0weHCToij9E
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Hi ctzsnooze! |
…rm threshold GPS Rescue: use gpsTaskInterval in gpsRescueUpdate() to set durations lock duration with a HACK that must be improved exponential velocity target for smooth start PT2 on velocityD only, not PT3 on sum increase climb and return rates to 7.5m/s increase max angle to 70 degrees take 1G off yaw acc for disarm trigger calc disarm threshold returned to 20 VelocityiTerm limit set to half max angle higher GPS max angle rename sampleTimeS to gpsRescueTaskIntervalSeconds use gpsRescueTaskIntervalSeconds for timers get getGpsDataIntervalSeconds from gps.c remove unnecessary failsafeOnValidDataFailed() check remove unused parameters MAX_PITCH_RATE MAX_ITERM_VELOCITY re-named 'angle' to 'max_rescue_angle' and maxRescueAngle GPS use gpsDataIntervalSeconds not gpsGetSampleRateHz NOTE: this time interval is too noisy to be useful! remove gpsVerticalSpeed; not used Failsafe: re-name failsafe switch booleans for clarity clarify boxGpsRescue events remove unnecessary checks and conditions get gpsDataInterval from gps.c, in seconds, less math add many clarifications and update comments fixes for BoxGpsRescue to retain iTerm on low throttle
668c902
to
d0b7b7a
Compare
Do you want to test this code? Here you have an automated build: |
User benefits of this PR:
gps_rescue_pitch_cutoff
, can be very smooth or very fastgps_rescue_disarm_threshold
to raise threshold if a noisy build tends to disarm earlyChanges:
gps_rescue_disarm_threshold
value. Default is 20, as before. A lower value will disarm more readily, and a higher value may cause the auto-disarm-detection to fail. If the quad does not disarm on landing, it will time-out and disarm after 10s, so this isn't a big problem.-User-adjustable pitch smoothing using
gps_rescue_pitch_cutoff
in CLI. Default is 100 or 1.0Hz. Larger values make the velocity control more precise, but pitch angle will jitter more. Lower values, eg 50, make the pitch changes smoother, but will delay velocity control and may cause pitch to wobble slowly or take time to settle. Higher values may be useful for very high speed returns where lag is unhelpful.gps_rescue_pitch_cutoff
frequency, and remove the 2 point moving average. This is possible now that the velocity data is better. With less noise and less delay, default D value can be set lower and still be very effective.gps_rescue_pitch_cutoff
cutoff, which gives a fairly good compromise between smoothness and lag.gps_rescue_pitch_angle_max
togps_rescue_max_angle
Setting
gps_rescue_pitch_cutoff
For faster than default rescues, eg more than 10m/s, don't set
gps_rescue_pitch_cutoff
value below default. Too much smoothing (lower cutoff values) will cause lag that may cause pitch wobble. Most likely the cutoff will need to be increased, eg to 200.For greater smoothness, and a slightly 'vague' or 'delayed' feel to the return, try
set
gps_rescue_pitch_cutoff = 50`. and perhaps choose a return velocity that is a little bit lower.Choose a smoothness value that suits your needs. The default should be good for most purposes.
Note that when higher levels of smoothness are required, overall precision will become worse, and on windy days, some corrections may be slower than optimal. When the smoothing is too strong, the quad will wallow around, or wobble, especially at the start, or on windy days.
If the GPS unit has an unstable position value, with a low sat count, or is constantly gaining or dropping satellites, the quad may abruptly jump around during a return. This is not due to a code problem, but to erratic data from the GPS.
Setting
gps_rescue_disarm_threshold
gps_rescue_disarm_threshold
is high, false disarms while in the final landing phase will be less likely, but a gentle landing may not have enough impact energy to reliably disarm the quad.Increase the
gps_rescue_disarm_threshold
to say 25 or 30 (2.5G or 3G) if:Decrease the
gps_rescue_disarm_threshold
if:Limitations / cautions
gps_rescue_max_angle
andgps_rescue_pitch_cutoff
should not be any lower than default. The quad will need to quickly adjust the pitch angle, perhaps to very high angles, at times. Expect to see rapid and substantial adjustments in pitch angle.Other technical changes
angle
tomaxRescueAngle
, to make it much easier to find this value in the codesampleTimeS
togpsRescueTaskIntervalSeconds
for claritysensorUpdate()
function use thegpsRescueTaskIntervalSeconds
value, not 0.01fGPS_verticalSpeedInCmS
code, which is not used anymoreGPS_RESCUE_MAX_PITCH_RATE
is removed because it not used to smooth velocity dataGPS_RESCUE_MAX_ITERM_VELOCITY
is removed because the velocity iTerm is now limited to half the max user-configured angle (half the velocity pidSum limit).boxFailsafeSwitchWasOn
, to make them easier to find when searching forboxfailsafe
.GPS_RESCUE MODE
, including ensuring reliable exit with sticks.failsafeOnValidDataFailed()
in failsafe.c; this had previously been flagged as likely not necessary, and testing shows it is not.detectAndApplySignalLossBehaviour
. This would have had the effect of not checking Rx packets for validity while disarmed, which doesn't seem sensible. The failsafe code handles failsafe behaviour in relation to arm status.GPS_verticalSpeedInCmS
since not used and duplicated the various function