Skip to content

Please, correct error in climb rate calculation. #10660

Open
@and-sh

Description

Current Behavior

Manual climb rate does not match the one specified in the configurator.

Steps to Reproduce

Turn on althold. Measure climb rate. Check settings.

Expected behavior

Correct climb rate.

Suggested solution(s)

The problem is that on rcCommand deadband is applied twice.
First time in line 140
https://github.com/iNavFlight/inav/blob/master/src/main/navigation/navigation_multicopter.c#L140
second time in lines 149 and 153
https://github.com/iNavFlight/inav/blob/master/src/main/navigation/navigation_multicopter.c#L149
https://github.com/iNavFlight/inav/blob/master/src/main/navigation/navigation_multicopter.c#L153

You can fix it like this, for example.
Image
It is tested and work well.

Removing deadband from lines 151 and 149 is not correct, since applyDeadbandRescaled changes ThrottleIdleValue in rcCommand. And it again produce a mess.

Additional context

This problem was in all versions since 3.0.0. I didn't look further.

Activity

breadoven

breadoven commented on Jan 31, 2025

@breadoven
Collaborator

I think you might be right looking at it again. Probably explains why its sluggish to climb but drops abruptly when descending. This is when hover throttle is < 1500. The opposite is probably true with hover throttle > 1500.

and-sh

and-sh commented on Jan 31, 2025

@and-sh
Author

Well, yes, that's why I started to figure it out #10547. I've only just figured out how to fix it completely.

and-sh

and-sh commented on Jan 31, 2025

@and-sh
Author
breadoven

breadoven commented on Jan 31, 2025

@breadoven
Collaborator

Your solution above isn't right because it'll always be adjusting if there's no deadband applied, which you don't want. The issue is the way the adjustment is converted into a climb rate. Would need to check the numbers but it doesn't appear that max throttle gives you max_manual_climb_rate and min throttle -max_manual_climb_rate ... you get something else.

Fixed wing is probably OK because it doesn't use a variable altHoldThrottleRCZero factor.

breadoven

breadoven commented on Jan 31, 2025

@breadoven
Collaborator

Actually checking this with debugs shows that the actual climb rate is just a bit higher than it should be but is consistent up and down. e.g. max_manual_climb_rate set to 700 actually results in +770 up and -770 down at max throttle stick deflections with altHoldThrottleRCZero set to 1320. So not exactly correct but not different up and down as I thought originally.

and-sh

and-sh commented on Jan 31, 2025

@and-sh
Author

Yes, it is. But I don't understand anything again. Why is the tgtVel correct in this case?
The deaband was applied somewhere else. Need more time to check

Image

Image

and-sh

and-sh commented on Jan 31, 2025

@and-sh
Author

I found my mistake. I restricted max climb rate to 1m/s.

I guess that correct math will be like this
`
const int16_t rcThrottleAdjustment = rcCommand[THROTTLE] - altHoldThrottleRCZero;

    if ((abs(rcThrottleAdjustment)>rcControlsConfig()->alt_hold_deadband)) {
        // set velocity proportional to stick movement
        float rcClimbRate;

        // Make sure we can satisfy max_manual_climb_rate in both up and down directions
        if (rcThrottleAdjustment > 0) {
            // Scaling from altHoldThrottleRCZero to maxthrottle
            rcClimbRate = rcThrottleAdjustment * navConfig()->mc.max_manual_climb_rate / (float)(getMaxThrottle() - altHoldThrottleRCZero);
        }
        else {
            // Scaling from minthrottle to altHoldThrottleRCZero
            rcClimbRate = rcThrottleAdjustment * navConfig()->mc.max_manual_climb_rate / (float)(altHoldThrottleRCZero - getThrottleIdleValue());
        }

`

and-sh

and-sh commented on Feb 1, 2025

@and-sh
Author

But. This is incorrect too, because velocity starts not from zero.
May be this will be correct:
const int16_t rcThrottleAdjustment = applyDeadbandRescaled(rcCommand[THROTTLE] - altHoldThrottleRCZero, rcControlsConfig()->alt_hold_deadband, -500+getThrottleIdleValue(), 500);

and-sh

and-sh commented on Feb 1, 2025

@and-sh
Author

Although even so, perhaps
const int16_t rcThrottleAdjustment = applyDeadbandRescaled(rcCommand[THROTTLE] - altHoldThrottleRCZero, rcControlsConfig()->alt_hold_deadband, getThrottleIdleValue()-altHoldThrottleRCZero, getMaxThrottle() - altHoldThrottleRCZero);

breadoven

breadoven commented on Feb 1, 2025

@breadoven
Collaborator

I have a fix for this. I'll do a PR when I have time.

linked a pull request that will close this issue on Feb 1, 2025
and-sh

and-sh commented on Feb 1, 2025

@and-sh
Author

Ok. I already fix this for myself.
On my setup difference in descent vel was more then three times.
max_manual_climb_rate was about 150

Image

and-sh

and-sh commented on Feb 1, 2025

@and-sh
Author

Fix this too, please, because errors tend to accumulate, and after some time everything stops working.

Max value of rcAdjustment is 500, but not 500-deadband.

Image

and-sh

and-sh commented on Feb 7, 2025

@and-sh
Author

It works fine, but I changed code a little for clarity
int16_t rcClimbRate = rcThrottleAdjustment * navConfig()->mc.max_manual_climb_rate / ABS(limitValue);

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Please, correct error in climb rate calculation. · Issue #10660 · iNavFlight/inav