Profile image

some codes I made

262 tomlin5412  one year ago

I don't like building planes but I like writing funky trees codes to make some planes flies well
here are some codes I've made:
Fighter
Pitch & Auto Trim Control(5deg/s max)-0 pitch input to make it auto trim:
clamp(((smooth(Pitch,1)+clamp(PID(Trim/20*clamp01(Pitch=0),PitchRate/100*clamp01(Pitch=0),1,15,0),-1,1))/clamp((((IAS-100)/100)*clamp01(IAS>100)+1),-100,100)),-1,1)

New version(Gforce control)
clamp(((smooth(smooth(Pitch,1)-smooth(clamp01((abs((PitchRate*(pi/180)*TAS)/9.80665)+abs(rate((PitchRate*(pi/180)*TAS)/9.80665)/20))>9),1/clamp(TAS/50,1,20)+
clamp01(abs(PitchRate*(pi/180)*TAS/9.80665)-9))*abs(smooth(Pitch,1))*sign(PitchRate),1)+clamp(PID(Trim/20*clamp01(Pitch=0),PitchRate/100*clamp01(Pitch=0),1,15,0),-1,1))
/clamp((((IAS-100)/100)*clamp01(IAS>100)+1),-100,100)),-1,1)

Roll 360deg/s:
clamp(PID(Roll,-RollRate/360,1,0,0),-1,1)

VTOL(AG1,Throttle&Brake to control,5m/s max)
clamp01(PID(smooth((Throttle-Brake)*clamp01(Activate1),0.25),rate(Altitude)/5*clamp01(Activate1),1,1,0)*clamp01(Activate1)+Throttle*clamp01(-Activate1))

Bomber / Transport Autopilot(height/pitchangle)-must be use on rotators and use with auto level together
Climb Rate 30m/s max/Pitch Angle 30deg max(AG1 to switch):
clamp(PID(clamp(PID(smooth((Trim*2+Pitch)*clamp01(Activate1),0.2),-rate(Altitude)/10*clamp01(Activate1),0.5,1,0),-2,2),-PitchAngle/15,0.5,0,0)*clamp01(Activate1)
+PID(smooth((Pitch+Trim/2)*clamp01(-Activate1),1),-PitchAngle/20,1,0,0)*clamp01(-Activate1),-1,1)-PitchRate/20

Auto Wing Level(60deg max):
clamp(PID(smooth(Roll,0.2),-RollAngle/60,2.5,1,0),-1,1)

Helicopter Auto/Manual Hover(AG1,10m/s max)-use this on collective pitch:
clamp(PID(smooth(VTOL*clamp01(Activate1),0.25),rate(Altitude)/10*clamp01(Activate1),1,1,0)*clamp01(Activate1)+(VTOL+1)/2*clamp01(Activate1=0),-1,1)

Pitch Axis(LG activate,brake to hover):
PID(clamp(smooth(Pitch,0.5)-smooth(Brake*clamp01(GS)*cos(AngleOfSlip)*abs(cos(AngleOfAttack)),0.5)/4,-1,1)*clamp01(LandingGear),-PitchAngle/30*clamp01(LandingGear),1,1,0)

Roll Axis(LG activate,brake to hover):
PID(clamp(smooth(Roll,0.5)-smooth(Brake*clamp01(GS)*sin(AngleOfSlip)*abs(cos(AngleOfAttack)),0.5)/4,-1,1)*clamp01(LandingGear),-RollAngle/30*clamp01(LandingGear),1,1,0)

Turret:
Range adjustment(max 10km,90deg range of hinge,1500m/s muzzle velocity)-use cockpit to aim or this code will not work correctly
(asin(((10000*cos(PitchAngle)+((10000*sin(PitchAngle))/(10000*cos(PitchAngle))))*Throttle*9.80665)/(pow(1500,2)))/2)/90

Horizontal(no limited (yes the shortest one)):
sum(Roll/2)

Horizontal(no limited+5x slower turning(AG1 to slow down)):
sum(Roll/(2+8*clamp01(Activate1)))

Horizontal(limited):
smooth(clamp(sign(Roll),-1,1)*clamp01(Roll!=0),0.5*abs(Roll))

Horizontal(limited+5x slower turning(AG1 to slow down)):
smooth(clamp(sign(Roll),-1,1)*clamp01(Roll!=0),(0.5-0.4*clamp01(Activate1))*abs(Roll))

Vertical(limited):
smooth(clamp(sign(Pitch),-1,1)*clamp01(Pitch!=0),0.5*abs(Pitch))

Vertical(limited+5x slower elevating(AG1 to slow down)):
smooth(clamp(sign(Pitch),-1,1)*clamp01(Pitch!=0),(0.5-0.4*clamp01(Activate1))*abs(Pitch))

Auto turret(1.10 update):
horizontal:(rotor:150deg,muzzle velocity:1500m/s)
smooth(clamp(TargetSelected?(deltaangle(Heading,TargetHeading)+rate(TargetHeading)*(((1500*sin(asin((TargetDistance*9.81)/(pow(1500,2)))/2))/9.81)*2))/180:0,-1,1),0.3)

vertical:(rotor:10deg,muzzle velocity:1500m/s)
smooth(clamp(TargetSelected?(TargetElevation+rate(TargetElevation)*(((1500*sin(asin((TargetDistance*9.81)/(pow(1500,2)))/2))/9.81)*2))/10:0,-0.5,6.5),4)

just copy and paste on your craft and test. These codes should be work on almost all crafts

  • Log in to leave a comment
  • Profile image
    30 ConnorB

    Do you know of a way to use funky trees code to switch the assigned rotational axis on rotators by pressing an activation group? I have a mechanically controlled vtol craft and I want to be able to toggle activation group one for example to switch the thrusters from pointing downwards to forwards so that in forward flight it is more efficient and fast. The issue is that if I do that the controls get screwed up

    yesterday
  • Profile image
    462 YourAlly

    @tomlin5412 ok but do you have any FT codes to clamp a plane to stabilize a Yaw Movement i will put it on my Gyroscope i had a 4 rotors 2 of them are already in reversed rotating so it wont turn abnormaly but my work was abnormaly Produce Yaw Movements when i straight ahead using only pitch

    one month ago
  • Profile image

    @YourAlly no

    +1 one month ago
  • Profile image
    462 YourAlly

    Does the:" clamp(PID(Roll,-RollRate/360,1,0,0),-1,1) "works on Gyros as a Yaw?

    one month ago
  • Profile image
    21.5k BagelPlane

    Spotlight this if I could! Absolutely amazing! The auto trim is quite handy.

    2 months ago
  • Profile image

    very usefull. Thanks!

    3 months ago
  • Profile image

    new:G limited Pitch control

    +1 6 months ago
  • Profile image

    @LUFTWAFFALES thanks

    6 months ago
  • Profile image

    @tomlin5412 this is very good

    6 months ago
  • Profile image
    6,008 One2

    I don't think a lot of people are following this, why dont you copy everything and paste it into a new forum? More people will be able to see who may have missed it in the past

    +1 7 months ago
  • Profile image

    @LegendIndustries22 yes you can use these on your planes

    7 months ago
  • Profile image

    and whats the stuff for prop planes

    7 months ago
  • Profile image

    can I enter this stuff manually.

    7 months ago
  • Profile image

    NEW:Auto Turret

    7 months ago
  • Profile image
    31.9k CRJ900Pilot

    Hey, I have another question. Im building a custom wheel, and I want the rim to spin with the tire to make it look realistic. I need a code that allows a rotator to spin slowly above 1 mph, and get incrementally faster up until 115 mph, where it will then stop spinning. I also need it to do the same in reverse for landing

    +1 11 months ago
  • Profile image

    NEW:Heli hover

    11 months ago
  • Profile image

    NEW:VTOL engine control

    11 months ago
  • Profile image

    NEW : new version of range adjustment code. It should be more accurate on cannons

    one year ago
  • Profile image
    17.9k exosuit

    @tomlin5412 that's what i thought as well

    one year ago
  • Profile image

    @exosuit I'm still trying to find the way to make a stabilizer code its a little bit hard and different when you attach the cockpit on the gun or the hull

    one year ago
  • Profile image
    17.9k exosuit

    i have some question
    .
    how do you program PID to act as gun stabilizer?
    I used clamp((-PitchAngle / 20), -1, 1) + clamp(Trim, -1,1)
    .
    it only stabilizes the gun when the cockpit is attached to the hull and when the hull is pointing down, and it will overcompensates when i attach the cockpit to the gun itself
    .
    using gyro is more simple but you don't have much control since it's always on and you can't disable it

    one year ago
  • Profile image
    7,748 scratch

    @tomlin5412 oh, that's thoughtful!

    one year ago
  • Profile image

    @scratch that clamp is for the range of gun turning angle if it's -1,1 yes you can remove it if not it's required

    one year ago
  • Profile image
    7,748 scratch

    on the Vertical(limited) and Horizontal(limited) you can remove the clamp on clamp(sign(Pitch),-1,1) to make it shorter :)

    one year ago
  • Profile image
    24.6k Mustang51

    Man I wish there was a way to save/favourite forum posts. This is brilliant!

    one year ago
  • Log in to see more comments