Code Hints Sought: Scaling pitch gains and open-loop pitch input w.r.t. wingtilt

I’ve been working with ArduPlane 4.1 in SITL for a tiltwing project that is slightly more challenging than conventional quadplanes. I am trying to improve the transition by way of simultaneously adding an open-loop offset to the pitch controller and modulating the overall pitch gains as a function of wing tilt value.

So far my code understanding skills have completely failed me as far as working out how to implement something like this, despite staring at many .cpp and .h files for waaay too long with no results. I have hacked things about enough in SITL to understand that the closed-loop controller can’t be tuned fast enough to cope with the transition, so adding in an open-loop correction would certainly help. The controller also goes unstable in pitch with any wing tilt so I want to dial at least some of the gains back as a function of wing tilt.

Is there any kind soul out there who understands what I’m trying to do that could post some code hints?

Which simulator are you using for flight physics?
And by open-loop offset do you mean feedforward gain?

I’m working with X-Plane 11 for my sim.

I don’t want to use the current feed forward as it’s a function of pitch angle demand which stays at zero for this case. The transition, if stopped part way and allowed to stabilize, shows a large integrator step which I want to approximate with a feed forward/open loop offset as a function of wing tilt

I haven’t used Xplane in several years, and I’m not sure I understand the concept of a

Can you point me to any references for that?

Hi Mark,

Nothing to do with SITL or X-Plane - that’s just my simulation environment.

In the PIDs they all have a feedforward term which arrives in AP_Motors_Class as _pitch_in_ff in this case. This is proportional to target pitch angle and governed by it’s feed forward gain Q_A_RAT_PIT_FF

What I want to do is add in another similar term but that is proportional to wing tilt (and also range limited)

Also, I want to add an additional compensation gain factor in pitch only that is applied similar to the battery/altitude compensation in AP_MotorsMatrix.cpp that is also a factor of wing tilt.

I thought I could just modify the base ArduPlane code but I think I will have to add features into the library files to add an additional motors->set_pitch_tilt_ff function that I can access from tiltrotor.cpp to contain the new factor and then apply that to the pitch_thrust calculation in AP_MotorsMatrix.cpp. Likewise for the compensation gain.

Is this making any sense?

I get a bit nervous ripping into the library functions!

That sounds right to me. But you’ll be modifying the PID control loop in an interesting way and I thought you might have read some academic papers on the stability of such mods.

I did something similar with QuadPlane::tailsitter_speed_scaling in tailsitter.cpp, but it just attenuates the overall gain of the control loop by reducing the magnitude of actuator outputs as a function of attitude and thrust demand. But its purpose is to prevent instability by reducing gain, and I don’t know if that’s all you need to do.

It’s part of what I need to do. I don’t fully understand why my pitch gain needs to change so much during transition but that’s for later on.

Also as I mentioned earlier, my I term needs to move a lot during transition because the effective centre of gravity moves relative to the motors as the wing tilts. I want to mop this up rather than waiting for an error to develop to drive the integrator.

Have you been following the tailsitter thread? Issues like this one might be of interest to you:

Interesting, Mark! I’ll have a read and digest. Thanks!