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

Use return INFINITY for FixedwingLandDetector::_get_max_altitude(). #12343

Merged
merged 1 commit into from
Oct 15, 2019

Conversation

mcsauder
Copy link
Contributor

@mcsauder mcsauder commented Jun 26, 2019

Describe problem solved by the proposed pull request
This PR adds a return value to the LandDetector _get_max_altitude() method declaration so that implementations can be deleted from the FixedWingLandDetector and RoverLandDetector classes. (Updated by #11874)

This PR simplifies the FixedwingLandDetector _get_max_altitude() logic by using the LandDetector base class logic return default. A few #includes in the land_detector module that can be deleted are also removed.

Please let me know if you have any questions on this PR. Thanks!

-Mark

@mcsauder mcsauder changed the title Add return INFINITY; to the LandDetector class _get_max_altitude() method Add return INFINITY; to the LandDetector class _get_max_altitude() method declaration Jun 27, 2019
@dagar
Copy link
Member

dagar commented Jun 29, 2019

I believe the reason it was done this way was so that the land detector publications would be throttled. On publishing on change or every second. https://github.com/PX4/Firmware/blob/02b92674aeba3a76f7e3e852182a9efe50fba40b/src/modules/land_detector/LandDetector.cpp#L105

@mcsauder
Copy link
Contributor Author

Hi @dagar, I've submitted this because it reflects work accomplished in your vehicle_imu PR, #9756. How would you like me to proceed?

@mcsauder mcsauder force-pushed the land_detector_max_altitude branch from 02b9267 to 866563b Compare June 29, 2019 16:43
@mcsauder
Copy link
Contributor Author

Hi @dagar , I will attempt to outline the direct impacts of this PR to help evaluate if it should be used or not:

FLT_EPSILON 1.1920929e-07F

No impacts in the case of Rover/LandDetector.
const float alt_max = 0.0 > 0.0f ? _get_max_altitude() : INFINITY; = INFINITY
if (fabsf(_land_detected.alt_max - alt_max) > FLT_EPSILON)) = FALSE

Taking into account previous _land_detected.alt_max value could be set; so if previously set = INFINITY - INFINITY = 0 = FALSE

If any of the other criteria are satisfied, the result is unchanged with this PR:
_land_detected.alt_max = alt_max; = INFINITY

Impacts in the case of FixedWing/LandDetector:
const float alt_max = roundf(-_vehicle_local_position.z + 10000) > 0.0f ? _get_max_altitude() : INFINITY;
if (fabsf(_land_detected.alt_max - alt_max) > FLT_EPSILON))

We can place real numbers into the code for examining. Assume that the current local position is a small value, using -1m (negative Z direction for positive altitude) is sufficient for illustration:
const float alt_max = 10001 > 0.0f ? _get_max_altitude() : INFINITY; = 10001
if (fabsf(_land_detected.alt_max - 10001) > FLT_EPSILON)) = FALSE until the aircraft descends below the previous value, (positive Z displacement).

If any of the other criteria are satisfied,
_land_detected.alt_max = 10001; = 10001

Iterate after positive Z displacement has occurred:
const float alt_max = 9999 > 0.0f ? _get_max_altitude() : INFINITY; = 9999
if (fabsf(10000 - 9999) > FLT_EPSILON)) = TRUE
_land_detected.alt_max = 9999; = 9999

For all practical purposes, the value will always stick somewhere close to 10,000.
If this PR is accepted, the value will get pushed to infinity.
const float alt_max = INFINITY > 0.0f ? _get_max_altitude() : INFINITY; = INFINITY
if (fabsf(INFINITY) > FLT_EPSILON)) = TRUE
_land_detected.alt_max = INFINITY; = INFINITY

Hopefully this is useful.

@mcsauder mcsauder force-pushed the land_detector_max_altitude branch 2 times, most recently from 14a2d8e to 481aa3e Compare July 16, 2019 18:21
@mcsauder mcsauder force-pushed the land_detector_max_altitude branch from 481aa3e to 02a0723 Compare July 25, 2019 22:57
@mcsauder mcsauder force-pushed the land_detector_max_altitude branch from 02a0723 to dd97073 Compare August 7, 2019 17:01
@mcsauder mcsauder force-pushed the land_detector_max_altitude branch from dd97073 to a794f88 Compare August 19, 2019 03:17
@mcsauder mcsauder force-pushed the land_detector_max_altitude branch from a794f88 to 3e48603 Compare August 28, 2019 06:37
@mcsauder mcsauder force-pushed the land_detector_max_altitude branch from 3e48603 to fb01338 Compare September 2, 2019 05:06
@mcsauder mcsauder force-pushed the land_detector_max_altitude branch from fb01338 to 37d4460 Compare September 26, 2019 03:28
@mcsauder mcsauder force-pushed the land_detector_max_altitude branch 2 times, most recently from 57c0c4e to 3c6a488 Compare October 3, 2019 02:21
@julianoes
Copy link
Contributor

@mcsauder

INFINITY - INFINITY = 0 = FALSE

Really? Not NaN? Did you test it? I'm mostly curious.

@mcsauder
Copy link
Contributor Author

mcsauder commented Oct 7, 2019

Hi @julianoes , thanks!

@mcsauder

INFINITY - INFINITY = 0 = FALSE

Really? Not NaN? Did you test it? I'm mostly curious.

You are right about that! (Luckily, the logic impact is the same.) Here is supporting data and test code for convenience:

image

#include <stdio.h>
#include <math.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>

int main()
{
	float result = INFINITY - INFINITY;
	uint64_t result_uint64 = 0;
	memcpy(&result_uint64, &result, sizeof result);
	printf("result:   %f %" PRIx64 "\n", result, result_uint64);
}

result: nan 7fc00000

image

@mcsauder mcsauder force-pushed the land_detector_max_altitude branch from 3c6a488 to d3b4204 Compare October 7, 2019 18:29
@mcsauder
Copy link
Contributor Author

mcsauder commented Oct 7, 2019

Rebased on current master.

@julianoes
Copy link
Contributor

julianoes commented Oct 8, 2019

@mcsauder thanks for laying that all out!

Ah, so Inf - Inf is NaN and NaN > Epsilon is False and thus no publication. I think this is sane then but so abstract!

julianoes
julianoes previously approved these changes Oct 8, 2019
@mcsauder mcsauder force-pushed the land_detector_max_altitude branch from d3b4204 to fb936af Compare October 14, 2019 20:59
@mcsauder mcsauder changed the title Add return INFINITY; to the LandDetector class _get_max_altitude() method declaration Use return INFINITY for FixedwingLandDetector::_get_max_altitude(). Oct 14, 2019
@julianoes julianoes merged commit 0cbb693 into PX4:master Oct 15, 2019
@mcsauder
Copy link
Contributor Author

Thanks @julianoes !

@mcsauder mcsauder deleted the land_detector_max_altitude branch October 15, 2019 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants