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

Please, correct error in climb rate calculation. #10660

Open
and-sh opened this issue Jan 30, 2025 · 12 comments · May be fixed by #10664
Open

Please, correct error in climb rate calculation. #10660

and-sh opened this issue Jan 30, 2025 · 12 comments · May be fixed by #10664

Comments

@and-sh
Copy link

and-sh commented Jan 30, 2025

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.

@breadoven
Copy link
Collaborator

breadoven commented Jan 31, 2025

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
Copy link
Author

and-sh commented Jan 31, 2025

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
Copy link
Author

and-sh commented Jan 31, 2025

It seems that fixedwing also suffers from this error
https://github.com/iNavFlight/inav/blob/master/src/main/navigation/navigation_fixedwing.c#L112

@breadoven
Copy link
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
Copy link
Collaborator

breadoven commented Jan 31, 2025

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
Copy link
Author

and-sh commented Jan 31, 2025

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
Copy link
Author

and-sh commented Jan 31, 2025

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
Copy link
Author

and-sh commented Feb 1, 2025

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
Copy link
Author

and-sh commented Feb 1, 2025

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

@breadoven
Copy link
Collaborator

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

@breadoven breadoven linked a pull request Feb 1, 2025 that will close this issue
@and-sh
Copy link
Author

and-sh commented Feb 1, 2025

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
Copy link
Author

and-sh commented Feb 1, 2025

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

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 a pull request may close this issue.

2 participants