@name Hover Autoleveling
@inputs HoverController [FL FR AR AL]:wirelink
#@outputs FL FR AR AL #Forward Left/Right and Aft Right/Left hoverballs
@outputs 
@persist 
@trigger 
interval(10)

E=entity()
#HoverController=0 #This is the user's input replace this
rangerFilter(E:getConstraints())
rangerDefaultZero(0)
Sky=rangerOffset(100,E:pos(),E:up()):distance()


Scale=4
Toll=3.5 #Tollerance
Roll=E:angles():roll()
Pitch=E:angles():pitch()
PC=(Pitch>-Toll)-(Pitch<Toll)
RC=(Roll>-Toll)-(Roll<Toll)
Ha=!PC & !RC
Flip=Sky <40 
Hover=Ha * HoverController + Flip
I= -((90<Roll)|(-90>Roll))
I= ((90>Roll)|(-90<Roll))
Flipover= Roll>170 | Roll<-170
if(Flipover){F=6}else{F=0}
D=15 #Distance
FL["ZVelocity",number]=sign(PC-RC*I)/Scale+Hover-F #Forward Left
FR["ZVelocity",number]=sign(PC+RC*I)/Scale+Hover+F #Forward Right
AR["ZVelocity",number]=sign(-PC+RC*I)/Scale+Hover+F #Aft Right
AL["ZVelocity",number]=sign(-PC-RC*I)/Scale+Hover-F #Aft Left
