Profile image

PID G limiter help

3,225 Oyasumi  1.7 years ago

So I'm trying to mod @tomlin5412's G limiter code for use on my fighter. I'll refer to this chunk of code as 'PCtrl' since it's stored in a named variable in my build:

clamp((smooth(PID(smooth(Pitch,10)-
smooth(clamp01(abs(VerticalG)>11),clamp01(0.5/(TAS/50))*clamp01(abs(11-
abs(VerticalG)))+clamp01(abs(VerticalG)-11.5))*abs(smooth(Pitch,10))*sign(Pitc
hRate),PitchRate*
(pi/180)*TAS/(1.1*98.0665)*clamp01(smooth(Pitch,10)!=0),2.5,0,0.25),1)+clamp
(PID(Trim/20*clamp01(smooth(Pitch,10)=0),PitchRate/100*clamp01(smooth(Pit
ch,10)=0),1,1,0),-1,1))/clamp(((IAS-200)/100)+1,1,2),-1,1)

AG1 toggle is used to switch between PCtrl and PSM mode (PSM code is external and works completely fine)

For the most part it does the job of strictly limiting G's to 11G, altho it behaves a bit weirdly specifically when transitioning from PSM to PCtrl mode, particularly after doing smt like a post-stall Immelmann maneuver and transitioning back to PCtrl mode while the aircraft is still flying backwards. Basically the issue is PCtrl's reaction to switching back from PSM mode after doing high AoA PSM stuff

These are the parameters of the two PID's being used in my current PCtrl expression

t1

smooth(Pitch,10)-
smooth(clamp01(abs(VerticalG)>11),clamp01(0.5/(TAS/50))*clamp01(abs(11-
abs(VerticalG)))+clamp01(abs(VerticalG)-11.5))*abs(smooth(Pitch,10))*sign(Pitc
hRate)

c1

PitchRate*(pi/180)*TAS/(1.1*98.0665)*clamp01(smooth(Pitch,10)!=0)

p1 2.5

i1 0

d1 0.25


t2

Trim/20*clamp01(smooth(Pitch,10)=0)

c2

PitchRate/100*clamp01(smooth(Pitch,10)=0)

p2 1

i2 1

d2 0

so variable notation becomes:

clamp((smooth(PID1{t1,c1,p1,i1,d1},1)+clamp(PID2{t2,c2,p2,i2,d2},-1,1))/clamp
(((IAS-200)/100)+1,1,2),-1,1)

pid1 (lowercase)

PID(smooth(Pitch,10)-
smooth(clamp01(abs(VerticalG)>11),clamp01(0.5/(TAS/50))*clamp01(abs(11-
abs(VerticalG)))+clamp01(abs(VerticalG)-11.5))*abs(smooth(Pitch,10))*sign(Pitc
hRate),PitchRate*
(pi/180)*TAS/(1.1*98.0665)*clamp01(smooth(Pitch,10)!=0),2.5,0,0.25)

pid2 (lowercase)

PID(Trim/20*clamp01(smooth(Pitch,10)=0),PitchRate/100*clamp01(smooth(Pit
ch,10)=0),1,1,0)

I'm noticing now that pid2 behaves weirdly specifically after transitioning from PSM to PCtrl mode after doing some PSM stuff, as in the value of c2 doesn't seem to approach t2 and continues to hold its own value or move away from t2 for a few seconds.

t2 is normally always 0 if Trim has neutral input. c2 should depend on PitchRate/100, and will only return to 0 if there is nonzero Pitch input. Even if c2 is 0 (PitchRate is 0) at the instant that the toggle switches from PSM to PCtrl, the pid2 code will still do weird stuff instead of not moving as would be expected

It's a bit too specific to explain on a forum post so I'll @ anyone who wishes to help on my current unlisted build link

thanks in advance to anyone willing to help w this very specific issue