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

multicopter land detector ground contact fixes #15083

Merged
merged 6 commits into from
Aug 2, 2020

Conversation

dagar
Copy link
Member

@dagar dagar commented Jun 10, 2020

Opening this for discussion/testing of possible fixes for #13124, #11683, #13507.

https://logs.px4.io/plot_app?log=4b65cf44-80cb-4910-bc2a-151028afe9da

@BazookaJoe1900
Copy link
Member

Thanks for applying this issue!
there are few things about land detector fixes I can suggest:

  1. By parameter, add condition that in order to detect ground the drone must be on landing mode. Currently if the operator will descend to ground, the ground contact will detect the ground and turn off motors. its nice feature, but it cause many false detection, and losses of drones. as seen in few issues.
    I made such change in my repo, and it helps me a lot. instead of being exposed to false detection during all flight, I am exposed to it only on landing.
  2. shut down the motors gradually in case of ground detection. it can be ~2 seconds. it will ensure quick enough shutdown. but will robust how the drone behave on false detection.
  3. (this is more advanced feature, and has a lot of potential hols on it). if there is range sensor, use it. allow to turn off motors if the range sensor shows less then XXcm or so.
    the problem this that (from trying) is that the range sensors are not very reliable (at lease the LidarLite)

@dagar
Copy link
Member Author

dagar commented Jun 10, 2020

Thanks for applying this issue!
there are few things about land detector fixes I can suggest:

  1. By parameter, add condition that in order to detect ground the drone must be on landing mode.

I think acting on user intent like this is interesting. We've actually already discussed this idea in the context of a unified navigator + flight_tasks. How do you handle lower level manual modes or a crash?

  1. shut down the motors gradually in case of ground detection. it can be ~2 seconds. it will ensure quick enough shutdown. but will robust how the drone behave on false detection.

@MaEtUgR thoughts?

  1. (this is more advanced feature, and has a lot of potential hols on it). if there is range sensor, use it. allow to turn off motors if the range sensor shows less then XXcm or so.
    the problem this that (from trying) is that the range sensors are not very reliable (at lease the LidarLite)

Yes this has come up before, especially with the cheap vl53l1x sensors that have a very low minimum range. We'd mainly need to get the architecture sorted so we can automatically use the appropriate sensor.

@BazookaJoe1900
Copy link
Member

Thanks for applying this issue!
there are few things about land detector fixes I can suggest:

  1. By parameter, add condition that in order to detect ground the drone must be on landing mode.

I think acting on user intent like this is interesting. We've actually already discussed this idea in the context of a unified navigator + flight_tasks. How do you handle lower level manual modes or a crash?

I currently don't handle lower level manual modes or a crash, but it can be added to conditions that "allows" ground contacts.

@dagar dagar force-pushed the pr-land_detector_mc_ground_contact branch 2 times, most recently from 40e6224 to 7dc9ca8 Compare June 11, 2020 14:47
@dagar dagar changed the title [WIP] multicopter land detector ground contact fixes multicopter land detector ground contact fixes Jun 11, 2020
@nrogelio
Copy link
Contributor

nrogelio commented Jul 3, 2020

@dagar @mrpollo

Flew in Stabilized, Altitude hold, position hold, loiter without issues, to finish the flight I activated RTL, the vehicle returned and landed, but it didn't disarm, even when going minimum throttle, minimum yaw. I kept minimum throttle and minimum yaw and eventually it disarmed.

Vehicle: S500 with Pixhawk 4.

Log: https://review.px4.io/plot_app?log=a19cdf1a-c113-4cd0-a5e1-15161446cdbb

@dagar dagar force-pushed the pr-land_detector_mc_ground_contact branch 2 times, most recently from fad8673 to 6a61932 Compare July 15, 2020 20:57
@dagar
Copy link
Member Author

dagar commented Jul 15, 2020

The changes I made should address the problem @nrogelio encountered (MPC published a local position setpoint with NAN). I've also reviewed some of the older problematic logs.

Needs more testing + careful log review.

@dagar dagar force-pushed the pr-land_detector_mc_ground_contact branch from 6a61932 to 10d5c42 Compare July 16, 2020 13:54
@dagar
Copy link
Member Author

dagar commented Jul 16, 2020

I'm not sure if this makes sense because it means that the _get_ground_contact_state now depends on _maybe_landed and _landed, however, these are handled "outside" as I understand it:

@julianoes yes it's a bit weird, but I think of it as "handing off" from ground contact -> maybe_landed -> landed where we can relax the ground contact requirements as soon as maybe_landed (or if already landed). Structurally I really don't like the interplay between these states, but that line has already been crossed with things like the _landed_time set by _get_landed_state() and used in _get_ground_contact_state() and _get_maybe_landed_state().

@nrogelio
Copy link
Contributor

nrogelio commented Jul 16, 2020

Successful tests, vehicle landed and disarmed the motors as expected, no issues in loiter or any other mode.
Vehicle: S500 with Holybro Pixhawk 4

Stabilized, Altitude, Position, RTL
https://review.px4.io/plot_app?log=6dd08a70-26b1-4fdf-a3d7-37e7aa590f91
https://review.px4.io/plot_app?log=b25ab283-a541-4261-896d-8d10ba3ebdbb

Mission, RTL (activated by RC)
https://review.px4.io/plot_app?log=8789345f-9e2c-4989-9dbf-92e6050a830c

Mission with RTL
https://review.px4.io/plot_app?log=efb77ad5-3408-48bf-a631-9684247fb547
https://review.px4.io/plot_app?log=833c35f9-76a6-490c-88f2-51ee0efe9adb

Takeoff, Loiter, Goto, RTL
https://review.px4.io/plot_app?log=542af54b-2a36-41cb-9f00-8f188d965d4e

Takeoff, Loiter, Land
https://review.px4.io/plot_app?log=f177ccef-bc45-46c9-8e1c-b982221ac436
https://review.px4.io/plot_app?log=d967fb71-b4a1-4ccb-a7eb-e53849c31bde
https://review.px4.io/plot_app?log=41132631-6904-4ff4-a3e6-ec3a3ae93eeb
https://review.px4.io/plot_app?log=c6df5f9b-9d3d-442d-9b8a-5b4c950fd6b1
https://review.px4.io/plot_app?log=cc8e0f64-e3c1-4c4a-ae4f-53add35b69ca

Takeoff, Position, RTL
https://review.px4.io/plot_app?log=39e899eb-4dbb-4697-abc5-fea573a76335
https://review.px4.io/plot_app?log=25aa2a96-67bd-446a-86dc-ff406d8d6657
https://review.px4.io/plot_app?log=384df783-557b-4f72-a1e3-f6e141b5bd35

Takeoff, Loiter, Goto, Position, Altitude, RTL
https://review.px4.io/plot_app?log=aee38c5e-05f6-429b-9aef-ac59d43a1fe6

Stabilized, manual landing
https://review.px4.io/plot_app?log=7763062b-4bad-4eb3-9f83-0e9f0ccc5548

Altitude, manual landing
https://review.px4.io/plot_app?log=1c1f2d78-69ed-45b7-9f62-562fa8cc3c61

Position, manual landing
https://review.px4.io/plot_app?log=bda87fa0-fa54-4a62-bc3f-ca32f84863bb

Takeoff, Loiter, Position, RTL
https://review.px4.io/3d?log=f4d252bf-2194-4470-8712-1f3e810bdb13

Takeoff, Loiter, Position, Altitude, Stabilized, Land
https://review.px4.io/plot_app?log=2f8438e5-ccda-4e18-9b3e-eb90a3eaaff8

Takeoff, Position, Orbit, RTL
https://review.px4.io/plot_app?log=16411529-d0d2-43fe-8868-f229eab7a2e6

Note: The previous flight session I was using a Drotek RTK GPS, this time I needed to use another GPS (The one included with the Pixhakw 4) because the vehicle won't warm with Drotek RTK GPS due to compasses inconsistent error. More details here

Copy link
Member

@BazookaJoe1900 BazookaJoe1900 left a comment

Choose a reason for hiding this comment

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

I left some comments.
still my main issue that the throttle goes to 0% on the first step of ground detect. even if there is no certainty that ground really found

@dagar
Copy link
Member Author

dagar commented Jul 21, 2020

still my main issue that the throttle goes to 0% on the first step of ground detect. even if there is no certainty that ground really found

Thanks @BazookaJoe1900, and I do agree about the throttle going to 0 immediately, that's just a slightly more intrusive change that needs to be introduced in the multicopter position controller.

Copy link
Member

@MaEtUgR MaEtUgR left a comment

Choose a reason for hiding this comment

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

I had a closer look and although the code makes sense and the cleanup and logic improvements seem to make sense I cannot predict for all cases what it changes. Since we at some point need to overcome this uncertainty I suggest we progress when we have tested it.

@@ -113,6 +113,14 @@ void MulticopterLandDetector::_update_params()
param_get(_paramHandle.minManThrottle, &_params.minManThrottle);
param_get(_paramHandle.landSpeed, &_params.landSpeed);

if (_param_lndmc_z_vel_max.get() > _params.landSpeed) {
Copy link
Member

Choose a reason for hiding this comment

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

Minor thought: A buffer between the two parameters might be desired.
Might not be necessary because of const float land_speed_threshold = 0.9f * math::max(_params.landSpeed, 0.1f);.

Copy link
Member Author

Choose a reason for hiding this comment

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

LNDMC_Z_VEL_MAX is actually another parameter I suspect we could live without.

Typically it's the land speed threshold constraining the max climb rate. max_climb_rate = math::min(land_speed_threshold * 0.5f, _param_lndmc_z_vel_max.get());

The other case is for 2 seconds (LAND_DETECTOR_LAND_PHASE_TIME_US) after landed the max_climb_rate is set to 2.5 x LNDMC_Z_VEL_MAX. Wouldn't the land speed threshold work here as well?

Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't the land speed threshold work here as well?

Probably, honestly that was there since before I first did any changes and I only preserved it.

@dagar dagar force-pushed the pr-land_detector_mc_ground_contact branch from 286bf3c to 35466aa Compare July 28, 2020 16:32
@dagar dagar force-pushed the pr-land_detector_mc_ground_contact branch 2 times, most recently from f707ab3 to 321037f Compare July 28, 2020 17:03
@dagar dagar requested a review from MaEtUgR July 28, 2020 17:59
@dagar dagar force-pushed the pr-land_detector_mc_ground_contact branch 3 times, most recently from cb69a60 to 2cde99f Compare July 28, 2020 19:16
 - if "landed" and "maybe_landed" states are false then both the "hit_ground" and the "low_thrust" condition need to be true in order to detect landing
 - ground contact MC NAN setpoint workaround
 - ground contact additionally check acceleration setpoint
 - schedule with vehicle_local_position updates (most updates require valid local position)
 - don't allow LNDMC_Z_VEL_MAX to exceed MPC_LAND_SPEED
 - ground contact horizontal and vertical movement checks default to
failed if estimates aren't available
@dagar dagar force-pushed the pr-land_detector_mc_ground_contact branch from 2cde99f to 0c8a759 Compare July 28, 2020 19:37
Copy link
Member

@MaEtUgR MaEtUgR left a comment

Choose a reason for hiding this comment

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

@dagar Very nice cleanup and improvements! Thanks for taking the time to go through this! 👍
Sorry that I put so many comments. Since I invested time into reviewing I wanted to capture my thoughts such that as many potential surprises as possible can be catched early.

I think there was no major issue. Let's do final testing.

matrix::Vector3f _acceleration{};

bool _armed{false};
bool _previous_armed_state{false}; ///< stores the previous actuator_armed.armed state
Copy link
Member

Choose a reason for hiding this comment

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

Tabs to indent, spaces to align right?

Suggested change
bool _previous_armed_state{false}; ///< stores the previous actuator_armed.armed state
bool _previous_armed_state{false}; ///< stores the previous actuator_armed.armed state

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but also trying to maintain consistency by default. In this case the entire line was moved from below.
Something like clang-format could probably help get us there overall.


// TODO: we need an accelerometer based check for vertical movement for flying without GPS
return (_has_low_thrust() || hit_ground) && (!_horizontal_movement || !_has_position_lock())
&& (!vertical_movement || !_has_altitude_lock());
return ground_contact && !_horizontal_movement && !vertical_movement;
Copy link
Member

Choose a reason for hiding this comment

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

Summary of the big changes:

  • The switch to the acceleration setpoint is handled correctly
  • No vertical movement via velocity estimate is a requirement (even in case it's not available, see comment above) while before low thrust was enough


// Determine the system min throttle based on flight mode
if (!_flag_control_climb_rate_enabled) {
sys_min_throttle = (_params.minManThrottle + 0.01f);
Copy link
Member

Choose a reason for hiding this comment

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

Needs to be tested if that's reachable with crappy stick input. Also isn't there a failsafe case where there's no link and no vertical velocity so you have to emergency descend with constant acceleration and hence no climb rate control?

Copy link
Member Author

Choose a reason for hiding this comment

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

That entire case really needs to be tested at some point. At the moment I wouldn't bet on it functioning properly at multiple levels. It's rare because we virtually always have vertical velocity and position with baro.

Copy link
Member

Choose a reason for hiding this comment

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

*inproperly

I agree. So the only thing to test for this change is if you get land detection in stabilized, that's it.

// Ground contact, no thrust and no movement -> landed
return _ground_contact_hysteresis.get_state() && _has_minimal_thrust() && !rotating;
// Otherwise, landed if the system has minimum thrust (manual or in failsafe) and no rotation for at least 8 seconds
return (_min_thrust_start > 0) && (hrt_elapsed_time(&_min_thrust_start) > 8_s);
Copy link
Member

Choose a reason for hiding this comment

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

Summary of the big changes:

  • low thrust threshold is mode/control_climb_rate_enabled dependent
  • only rotation around body roll and pitch are considered, rotation around yaw gets ignored now
  • freefall detection is considered

Copy link
Contributor

@julianoes julianoes left a comment

Choose a reason for hiding this comment

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

Couldn't spot anything obviously wrong.

@nrogelio
Copy link
Contributor

nrogelio commented Aug 1, 2020

Flight session, no issues related to landing, but found some issues with take-off mode and mission.
Vehicle used: S500 with Pixhawk 4 and Drotek GPS.

Stabilized: Take off, hover or small flight, manual landing
https://review.px4.io/plot_app?log=c64927e5-b89e-4de2-8921-bd1d99089433
https://review.px4.io/plot_app?log=121f4f0c-1077-4bdf-be80-81aca3c3322a
https://review.px4.io/plot_app?log=4cc383b5-79a4-4a55-9a1f-860ea4773134
https://review.px4.io/plot_app?log=b2871a12-282d-4bed-bf2f-e5c1b0235d3d
https://review.px4.io/plot_app?log=4bfd2154-b954-40ea-80a2-89bcc2e48714

Altitude: Take off, hover or small flight, manual landing
https://review.px4.io/plot_app?log=34fe5522-9e5e-4020-ab48-ad00ce35024f
https://review.px4.io/plot_app?log=4c652083-3dce-449d-afba-0f894358642e
https://review.px4.io/plot_app?log=256b2fcb-dcbd-4b24-945a-5e263fdbf2c2
https://review.px4.io/plot_app?log=bac7b39b-4f9c-4cc0-8657-1fa7e92ed474
https://review.px4.io/plot_app?log=023ea3cf-46a8-4b83-a430-5573aecbe3a6

Position: Take off, hover or small flight, manual landing
https://review.px4.io/plot_app?log=150487be-62f4-41eb-ba26-d1787899592b
https://review.px4.io/plot_app?log=1998298b-0fdc-4683-942f-5c540bc008e0
https://review.px4.io/plot_app?log=846a4de1-0616-4563-90c6-0523f7796b6e
https://review.px4.io/plot_app?log=ffe878a5-42b5-49ac-ac98-2f68987892c9
https://review.px4.io/plot_app?log=bf2ca24f-d02c-4cb4-b40d-48316e780042

Auto-Takeoff, land
The vehicle reached the set altitude, but it didn't change the flight mode, it was hovering but the flight mode was Takeoff, I think it should change to hold once the altitude is reached.
https://review.px4.io/plot_app?log=67696e3d-6f7e-4ead-b937-87b72e993e50
https://review.px4.io/plot_app?log=2ee744c4-0266-478b-a117-f8d7f1fec15c
https://review.px4.io/plot_app?log=e33902f0-a5c8-4f1a-9306-8102616d39ac
https://review.px4.io/plot_app?log=babae7b8-7415-47a6-9d4f-ed1c10b1650b
https://review.px4.io/plot_app?log=1d419e4d-82ae-4e97-a8a7-d7f1e88f85b3

Mission with RTL
In 4/5 missions the vehicle tookoff and didn't went to the next waypoint, I think is related to the issue of the auto-takeoff, land flights. I needed to pause the mission or switch different flight mode and then click continue mission.
https://review.px4.io/plot_app?log=d2dc82d7-0024-4562-b8dc-2edf5e4bbf22
https://review.px4.io/plot_app?log=b1762b52-0ce7-4231-8f66-004e334ccdf2
https://review.px4.io/plot_app?log=7d6db655-f099-4d24-9de9-878498a6cace
https://review.px4.io/plot_app?log=dbb8da1c-8f3f-4e56-91a3-ee9ed80b6585
https://review.px4.io/plot_app?log=936188a2-8917-4c4e-9820-a519e949d8ba

Other flights, no issues
https://review.px4.io/plot_app?log=0f98ac25-df15-44a0-8c1b-f6684e0c43fa
https://review.px4.io/plot_app?log=0c0422e4-290b-4711-8c8a-7a94ff486def
https://review.px4.io/plot_app?log=f5a96499-d6a2-491c-8faf-2414a205419f
https://review.px4.io/plot_app?log=804b5e8e-7614-48e3-8ecc-104695a08046

@dagar
Copy link
Member Author

dagar commented Aug 2, 2020

Overall it looks good, although a bit delayed in triggering ground_contact relative to master.

After the minor hover thrust estimate changes and validity flag (#15370) merge I'll take another pass in the MC land detector to raise the ground_contact thrust threshold (currently 30% between min and hover).

@dagar
Copy link
Member Author

dagar commented Aug 2, 2020

Thanks for thorough testing @nrogelio. Let's create a separate issue to followup with the failure to transition from TAKEOFF -> MISSION.

@mrpollo
Copy link
Contributor

mrpollo commented Aug 5, 2020

IT'S DONE

IT'S DONE

@pjdewitte
Copy link

I noticed the documentation wasn't up to date, so I started a pull request.

To further improve the documentation, I wonder:

  • _in_descend is calculated but not used, which means the condition "or velocity setpoint is 0.9 of land speed" no longer applies. Was this intentional?
  • an acceleration setpoint of 100 m/s^2 (ca 10g) is also considered ((vehicle_local_position_setpoint.acceleration[2] >= 100.f) but I don't know why, so I wonder whether it should be added to the user guide, or maybe just as a comment in the code.

@junwoo091400
Copy link
Contributor

junwoo091400 commented Dec 3, 2023

  1. Currently if the operator will descend to ground, the ground contact will detect the ground and turn off motors. its nice feature, but it cause many false detection, and losses of drones. as seen in few issues.

I am still surprised that the land detection doesn't take into account such high level modes, and yes false positive landings have led to drones disarming mid-air. We will def have to address this.

Edit: Ah no, actually the _flag_control_climb_rate_enabled will consider autonomous descents, but still doesn't affect the land detection logic behavior 🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants