-
Notifications
You must be signed in to change notification settings - Fork 16.8k
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
Readd output value limit #5819
Readd output value limit #5819
Conversation
@khancyr This needs to be parameter or API controlled, deepstall for example uses an explicit PWM that is outside the min/max of the SRV channel. |
@WickedShell hummm ok! I though there was a reason behind this change... it is kind of problematic I think, it is safer to limit the ouput by default ( for simple people like me) and add a way to bypass it on need rather than the opposite. |
@WickedShell How does that work? I mean, in my perspective min/max should be configured to the limit values the system should use. If those values aren't to be respected what are they used for? |
A deep stall is usually triggered by giving an extreme pitch command from the tail that moves it almost perpendicular which quickly drags the aircraft well below stall speed. You never want to do that during normal flight when really all you want to do is pitch up hard. A single spike of full pitch will end your flight. Sounds like what we need is an exception to give a boost of a certain pwm us or percent given certain conditions, such as during a land and the land type is deep stall... But I can't think of a good way to do that with params. |
I think that PWM min/max should never be output over the set limits. The limits are usually set at hardware max throws of servos and going beyond that will simply damage the plane. |
I agree with @WickedShell that we need a parameter. It should default to limiting to the specified range, but allow the user to ask for an "overdrive" for things like manual deepstall |
Or maybe the code itself could have functions that limit or do not limit the output? I think most parts of the code (Sprayer, etc) never want the outputs to be beyond the limits. If there are a few cases that we know of that we do want to allow going beyond the limits, those could use a special function perhaps. |
I think that there should be 1 (one) interface for accessing servos and ESC's. We already have 2 libraries that do that: SRV and Motors. It would be bad to have 3rd, 4th and so on places where there will be direct access. It breaks the structure and greatly complicates the support and adding new features. |
@EShamaev agreed. Maybe we could continue respecting the limits and if and only if/when doing deep stall, we reconfigure the library to allow temporarily going beyond that value. |
I try to look briefly at deepstall code, and I don't find extrem value. Here is what I understant : So what about changing the signature of void SRV_Channel::calc_pwm(int16_t output_scaled) to something like void SRV_Channel::calc_pwm(int16_t output_scaled, bool enforce_limits=false) and make the limitation inside this function. So we keep the limit by default as it was before the RC slipt and add a simple way to bypass the limitation |
What I am trying to say is that there are mechanical limits. No matter what happens, if you go beyond those - plane will be either damaged or servo get stuck or arm gets broken away. |
@EShamaev Agree ! But I think we can't force the extrem limit to always be 1000 - 2000 because off real PWM support ( don't remember exactly how it works here...). So limiting to servo out min/max to what is in parameters should be safe enough in most case (unless a user enter wrong value ...) Looking in deepstall code https://github.com/ArduPilot/ardupilot/blob/master/libraries/AP_Landing/AP_Landing_Deepstall.cpp#L303 , I don't think they try to outpass 1000 - 2000 or even the servo limit |
Alright so some summaries on the deepstall part for those following along. The specific scenario that is being covered with deepstall is that the normal flight envelope (with really agressive control) uses +/-10 degrees of servo movement, however to enter a stable deepstall I need ~35 degrees or more of elevator to stall the aircraft. The surface is massively effective however, and normal flight can't operate within that evelope. At the moment deepstall is managed by providing a target PWM to lock the elevator to which will then be held during the stall https://github.com/ArduPilot/ardupilot/blob/master/libraries/AP_Landing/AP_Landing_Deepstall.cpp#L290 So the core of the problem is I have a specific flight stage here that needs very different PWM values then any other flight stage of the aircraft and we don't have a logical split for them. Tridge and I have discussed implementing this as an overdrive percentage rather then a PWM value, but the initial implementation I pushed for sticking with a PWM as we knew that worked safely, and wanted to get it merged in. The easiest workaround is probably to have a set_output_pwm_unconstrained() call that allows the caller to bypass any range clamping on the surface and get the output PWM they requested (and then deepstall could call this instead). The other scenario where I absolutely need surfaces to not be constrained to the servo limits is when the overrides are active, as again I can manually deepstall (or manipulate flight surfaces in other ways) well outside the envelope the autopilot is allowed. The good news is unless you modify the PX4IO layer this behavior is already correct and present. If I ever have to fly a board that doesn't have a PX4IO (or equivelent) I will probably introduce a PR that has an optional flag to indicate that manual should be unconstrained as well. @EShamaev I'm very familiar with all the problems about servos out of range, this is actually something I've suffered from after the entire servos/rc split, as trimming out an aircraft is now much much more complicated if you ever transfer the pixhawk or attempt to recal servos at the moment. At least I haven't seen any good way to set new limits easily without using say the overrides, or a script to copy from the RC cal to servo cal as a one off... (This is a seperate topic however) |
@WickedShell Actually I find it much easier to trim and setup now when you have separate ranges for RCIn and RCOut. Anyway, I think this deepstall landing should be well documented for users as not every airframe is capable to do it regarding aerodynamics and also this out of band servo action. |
@EShamaev side note on deepstall I've only flown that code with a rudder only aircraft, aileron aircraft are hooked up there in theory but I haven't flight tested that yet. I do have an aircraft that has ailerons that can do deepstalls but it is hasn't been tested at all yet. The advantage of the overdrive percentage approach tridge mentioned is it would work for dual elevator aircraft, or possibly on vtails/elevons (although I think there may be some other problems on this type of airframe that I dont know the answerers to yet) |
I reread all this thread from beginning and still do not understand one thing. Why do we need to override limits at all? I propose following:
This way we will keep safety limits feature of PWM min/max and all logic for deepstall should work as well. |
I don't know much about planes so I can be missing things, but I share @EShamaev's view here. I look at this a bit like Copter's spin min, spin max, spin arm parameters. We have a PWM range for the ESCs but then we have parameters that limit that range further. |
@EShamaev That doesn't work. Either I give the plane the potential authority to blow through the mechanical limits on the one axis (including nonsensical PWM values), or I don't. For all the reasons outlined here that doesn't work. So lets give some numbers so that this makes more sense; So for me to do what you are proposing I would need to set the min PWM value to 600 which is completely out of spec. That just doesn't apply sanely. I very genuinely need a range for normal flight and a range for the deepstall mode. For now, without complicating everyone else's life that just means a way to move outside the servo range. I just don't see any way for that to ever be sane with what you proposed with manipulating the PID ranges. And even within the PID range stuff there is a difference in tuning if I max out a control surface for a period of time (rarely happens now but can) vs allowing it to continue onwards. |
I'd also like to point out that plane never had a hard limit before... Manual you got what you requested, and if you asked for a PWM out (the same call that deepstall uses) you got that PWM. If you call via the scaled functions you will be fine, this can only go wrong if you call set_output_pwm() which should rarely be used. As stated we can clamp that version if we provide an unclamped interface as well which nothing else really needs to use for now. |
@WickedShell Then this "unclamped" interface should be a part of SRV_Channel interface. And not be direct call that goes by it. |
I'd like to have code like this: |
@tridge @WickedShell Hello, does this solution suit you ? |
rebased and corrections from review |
@@ -202,3 +202,6 @@ uint16_t SRV_Channel::get_limit_pwm(LimitValue limit) const | |||
} | |||
} | |||
|
|||
void SRV_Channel::set_output_unlimited_once() { | |||
limited_pwm_mask &= (0U << ch_num); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation wrong.
This doesn't work. Zero left-shifted whatever number of times is still zero 🙂 It needs to be limited_pwm_mask &= ~(1U << ch_num);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok done!
@khancyr Yes, that was I suggested. I think it is fine not having any user of that API now, it allows to uniformize the static methods and class methods. By the way, this was talked in the dev call and @tridge asked for more time so he can check all usage of the unlimited method - it touches a lot of places in Plane. |
rebased and correct lastest error |
rebased, remove the first commit that was already merged with #6190 |
rebased on master |
Sorry Pierre, can you rebase ? |
rebase and fix conflict |
@tridge ping ! |
rebased and remove rover change that were already merged |
@khancyr what are the remaining use cases where this is needed? |
@tridge |
Hi, after #5519 , it seems that the limitation on output have disappeared leading in erroneous pwm output like in #5817
This PR thus relimit pwm calculated form angles, and limit all pwm between servo_min and servo_max