Skip to content

Conversation

@breadoven
Copy link
Collaborator

Been using this for a while now so issuing as a draft for discussion. Updates landing detection for multirotor and adds detection for fixed wing.

Detects when flying and activates landing detection from that point. However, final detection routines are only active when basic flight criteria are met.

Multirotor detection added for non autonomous landing as well as RTH.

Fixed wing detection based on velocity, axis rates and finally absolute movement in roll and pitch (so probably wouldn't work if stuck in a tree being blown around by the wind).

The conditions used to detect flying and landing are relatively basic but are structured as much as possible to make it easier to improve/add to the conditions to increase reliability. #7068 would be useful for flight detection on fixed wing.

Been used for a few months with no false landings detected although the conditions that might cause false detection, e.g. gale hanging etc, weren't encountered. RTH landing detection on multirotors works as before. Fixed wing detection takes some time to trigger, > 6s + disarm delay, probably due to horizon drift moving the roll/pitch axis after landing. However, detection tolerances haven't been optimised so could be relaxed reducing detection time but with increased risk of false triggers.

Things that could be improved:

  • Scheduling
  • Trigger condition complexity
  • averageAbsGyroRates
  • Fixed wing absolute movement axis check

@avsaase
Copy link
Member

avsaase commented Jul 15, 2021

Awesome! I've been thinking about doing something like this for a while. I can't test or review the code right now but I'll be sure to do that once I'm back from vacation.

@stale
Copy link

stale bot commented Jan 9, 2022

This issue / pull request has been automatically marked as stale because it has not had any activity in 60 days. The resources of the INAV team are limited, and so we are asking for your help.
This issue / pull request will be closed if no further activity occurs within two weeks.

@stale stale bot added the Inactive label Jan 9, 2022
@DzikuVx DzikuVx removed the Inactive label Jan 9, 2022
@DzikuVx
Copy link
Member

DzikuVx commented Jan 10, 2022

@breadoven do you think we should merge it for 5.0?

@breadoven
Copy link
Collaborator Author

@breadoven do you think we should merge it for 5.0?

Well I've been using it for a while and it hasn't produced any false landings whilst still detecting landings when it should. I was hoping for some feedback but since there hasn't been any I guess it should be OK to include in 5.0. I'll add in something related to #7068 and remove Draft status.

Probably needs a warning though initially to be careful using it with Disarm on landing set, at least until you're happy it isn't throwing up "LANDED" in the OSD when it hasn't.

@breadoven breadoven marked this pull request as ready for review January 18, 2022 23:13
@DzikuVx DzikuVx added this to the 5.0 milestone Feb 22, 2022
@DzikuVx
Copy link
Member

DzikuVx commented Feb 22, 2022

@breadoven please resolve conflicts and we should merge it to 5.0

@DzikuVx DzikuVx merged commit 75ae659 into iNavFlight:master Mar 13, 2022
@breadoven breadoven deleted the abo_landing_detection branch March 13, 2022 21:48
@Jetrell
Copy link

Jetrell commented Mar 14, 2022

@breadoven I ran some multi-rotor tests today, with a build containing this PR.
Unfortunately auto disarm by the Nav system would not occur after a landing.
I tested it 4 times. And waited up to 30s, before I manually disarmed.
I also tested it by landing on grass and on a firm surface.. The outcome was the same, no disarming.

I then load a firmware I had from the master a week ago.
It disarmed by the Nav system within a few seconds. I ran that test twice, and it disarmed both times.

@breadoven
Copy link
Collaborator Author

@breadoven I ran some multi-rotor tests today, with a build containing this PR. Unfortunately auto disarm by the Nav system would not occur after a landing. I tested it 4 times. And waited up to 30s, before I manually disarmed. I also tested it by landing on grass and on a firm surface.. The outcome was the same, no disarming.

I then load a firmware I had from the master a week ago. It disarmed by the Nav system within a few seconds. I ran that test twice, and it disarmed both times.

I take it this was a RTH landing ?

Was there any indication landing had been detected, motors returned to idle or a message in the OSD "LANDING DETECTED" ?

What size quad was it ?

Should be able to test myself in the next few days with some better weather for a change.

@Jetrell
Copy link

Jetrell commented Mar 14, 2022

Yes, it was landing after RTH.

Once it completed the landing slowdown and touchdown, the motors did return to idle.
And LANDING still remained as the OSD message. I never seen LANDING DETECTED appear.

The quad would try to move on the pitch and roll axis's while on the grass, trying to detect flight.
And it was also evident that it was trying to do the same on the cardboard. Even though Auto Throttle was showing 0%, it was getting lite enough to slide along the cardboard.

This is a 3"quad I use for testing.

@breadoven
Copy link
Collaborator Author

@Jetrell So I tested this by "hand flying" and it was detecting landing with a quad both for RTH and otherwise. For RTH it correctly enters and follows the routine used previously, waits a second for the throttle to stabilise and then checks the throttle during descent so the logic and timings all work as before (I had to rejig the code a bit to account for some constants that had been added which could have caused some basic error but that isn't the case in fact, all works OK) . I'll check again during flight but I don't see that anything will change other than it being more reliable than simulating a landing by hand.

Only thing I can think of is the landing detector isn't initialising after take off. It needs the throttle to exceed nav_mc_hover_thr and some gyro movement (just a bit more than static sitting on the ground).

I'll add a LANDING debug which should help understand what's happening.

@breadoven
Copy link
Collaborator Author

breadoven commented Mar 15, 2022

You should be able to use the hex from the run for the PR adding a LANDING debug:

https://github.com/iNavFlight/inav/actions/runs/1986047348

@Jetrell
Copy link

Jetrell commented Mar 15, 2022

Sorry.. I hadn't noticed that you'd already made a fix 👍

@breadoven
Copy link
Collaborator Author

The debug fields for Landing are:

0 - landing detector active
1 - landing detected
2 - horizontal and vertical velocities low
3 - gyro movement low
4 - position in landing detection routine (0 = not detecting, 1 = RTH landing, 2 = non auto landing)
5 - landing criteria met
6 - rcCommandAdjustedThrottle
7 - average descent throttle less detection margin

Landing detected when 6 < 7 for RTH landing (maintained for set safety time delay)

@Jetrell
Copy link

Jetrell commented Mar 16, 2022

I set debug_mode = LANDING in the CLI... It was excepted, but the 8 debug RAW and DECODED values came back as zero in the logs and on the sensor page. Tried twice after flashing again.. same outcome.

I tested RTH landing again a few times. Both with the debug addition and the original landing detection.

These log images are when the quad is on the ground, after landing.

Original, at the point of disarm.
Original_disarming

New, trying to disarm.
New_NO_disarm

@breadoven
Copy link
Collaborator Author

breadoven commented Mar 16, 2022

Right the answer is very simple, the landing detector routine isn't running at all because there is a USE_NAV still defined for the initial call to run the landing detector:

https://github.com/breadoven/inav/blob/2d622c10f5b7e2e2696d97f184abd92495452c96/src/main/fc/fc_core.c#L939

The USE_NAV define was removed from INAV a short time ago but this must have still been in the original landing detection branch and got carried over on merging. I noticed it my custom build yesterday in fact but there was a duplicate call without the define so landing detection worked in my case. Quick fix required.

@Jetrell
Copy link

Jetrell commented Mar 17, 2022

@breadoven Just to confirm, MR nav auto disarm works again as expected.
With OSD stats showing Disamed by : Landing

Can I ask you a little more of what to expect from the Landing detector, for both MR and FW.
I have read your opening explanation and the comments in the code.
But I did some ground testing, by walking around outside with both types of aircraft, and haven't been able to get them to disarm.
I did notice that it needs to detect flight first.
I simulated a throw for the fixed wing and faked the autolaunch. Then started walking around with the craft, keeping the planes attitude in line with control surface motion. (Not sure if that was enough to enable the detector?) Then turned off the radio to get a FS. Then placed the plane on the ground, then waited.

  • Does it only work in Failsafe on a fixedwing?

  • Will it detect a CRASH (not a classic landing), if both types of aircraft went down in FS with no RC link or possibility to manually disarm?

  • Under what conditions will it detect a MR landing in non autonomous modes? Should I be able to land in Acro with Airmode idle active, and it will disarm after a time?

  • Fixed wing obviously requires a GPS lock. Can I assume a MR does not?

Thank you. I appreciate your efforts to write this feature... Any information you can give me to help understand its operation better, would help me with testing it.

@breadoven
Copy link
Collaborator Author

breadoven commented Mar 17, 2022

The landing detector needs to detect flight before it becomes active. Flight is detected on a FW based on speed, valid heading and throttle > cruise throttle OR a successful auto launch. It's detected on a MR just based on throttle > hover throttle and gyro movement,

Once active the detector only starts checking for a landing when certain basic criteria have been met which are:

  • Nav state is landing or emergency
  • Failsafe is active*
  • Nav isn't controlling throttle and throttle is low

*On a multirotor if WP mode is active and failsafe_mission is OFF landing detection won't try and detect a landing because there is a risk that a hold WP might trigger false landing detection if the MR was stable enough to meet the gyro and low velocity criteria for a non autonomous landing. Probably overkill but a possibility. This isn't really an issue for a fixed wing since it always needs speed to fly.

If the basic criteria are met to start checking for a landing then the following specific checks are made:
Fixed wing

  1. Check horizontal and vertical velocities and gyro movements are low enough
  2. If 1 met then capture roll and pitch angles and check to see if they remain within a 0.5 degree tolerance for a period of >2s + an optional additional "safety" time period. This will work in most circumstances but probably not if stuck in a tree branch getting moved by the wind or even after landing on the ground when it's windy if the model is easily blown about.

Multirotor

  1. If Nav state is landing then the existing landing check based on average throttle during descent is used.
  2. Otherwise a basic check is used based on horizontal and vertical velocities and gyro inputs being low enough.
  3. The detection criteria in both cases must be maintained for a period of >2s + an optional additional "safety" time period.

If not in autonomous flight or Failsafe the throttle needs to be low in order to start detecting a landing so if you land manually you need to cut the throttle to detect the landing.

You can active the landing detector on a fixed wing for ground test by doing a dummy launch otherwise it needs to fly because it requires a valid heading. Once active it should detect a landing simply by cutting the throttle and placing it on the ground so it's not moving. It can take up to 8s or so to trigger after flight mainly because even minimal horizon drift causes the pitch/roll axes to continue moving even when the plane is static.

The issue with multirotors and a manual landing is they tend to be a bit skittish sitting on the ground after landing with airmode active which makes it harder to achieve the velocity and gyro limits although from tests it does get there eventually but may take up to 8s again. Land on a slope though with horizon active and it probably won't work, too much movement with one end effectively still flying.

No GPS lock required for FW or MR, landing should be detected flying manually.

@Jetrell
Copy link

Jetrell commented Mar 18, 2022

@breadoven Thanks mate for all the information. It was very useful.

I ran some more MR tests. It disarms perfectly on grass or a firm surface in Angle or Horizon modes, when the throttle is stopped.
As you stated, with Airmode motor idle throttle set higher, its a little hit and miss, as expected. But with its set to a 3% or lower. It works every time when on a few cm's of grass.

I did a fair amount of elaborate ground testing with a fixed wing.... All worked well, with no false disarming, even at very low forward ACC X axis movements... It practically required it to be almost stationary on the ground, before it detected landing.
In the air its all good.
I think it would require very unique conditions to fool it into disarming while flying.

All in all, my results are the same as yours 💯

Once more I would like to say a big thanks for your addition of this feature..
You've done a brilliant job in striking the right balance between detecting flight and detecting landing 👍

It may be helpful to include the information you wrote me in your last post, in the Wiki, to help others?
And it also may be good to inform users that it requires - nav_disarm_on_landing = ON. For this feature to work on a fixed wing. Many users will leave it at Default OFF, because it was considered a MR feature before this PR.

@DzikuVx I think this feature is the general fulfillment of this #2331?

@breadoven breadoven added the Release Notes Add this when a PR needs to be mentioned in the release notes label May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Release Notes Add this when a PR needs to be mentioned in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants