SHOW:
|
|
- or go back to the newest paste.
1 | - | //VTOL hover script with side translation - Ozin |
1 | + | |
2 | - | // !runscript xeNy4xmv |
2 | + | set menu to gui(200, 30). Set menu:x to -30. set menu:y to 300. menu:show. |
3 | menu:addlabel("<b><color=yellow>VTOL 2-axis script</color></b>"). | |
4 | - | core:doaction("open terminal",true). |
4 | + | |
5 | - | clearvecdraws(). |
5 | + | |
6 | - | clearguis(). |
6 | + | |
7 | - | sas off. |
7 | + | |
8 | - | HUDTEXT("Running script: VTOL hover for jets & propellers",20,2,22,white,false). |
8 | + | |
9 | set m5 to menu:addlabel("vsOverride:"). | |
10 | - | //===[Setup shitload of vars]=== A lot of these get updated in triggers and functions but need to be delcared here first with initial values. |
10 | + | |
11 | - | if not(defined places) and exists("0:/json/" + body:name + ".json") set places to readjson("0:/json/" + body:name + ".json"). |
11 | + | |
12 | set m8 to menu:addlabel("alignTerrainHeight:"). | |
13 | - | if vang(up:vector,facing:vector) > 60 toggle ag2. |
13 | + | |
14 | set m10 to menu:addlabel("Localport:"). | |
15 | - | set props to false. |
15 | + | set mLast to menu:addlabel("Functions: <color=white>goToTarget(), goToPosition(<geopos or position>), resetSteering()</color>"). |
16 | - | if ship:partsnamedpattern("blade"):length >= 4 { |
16 | + | |
17 | - | //toggle ag3. |
17 | + | set mLast3 to menu:addlabel(""). |
18 | - | set props to true. |
18 | + | set mLast4 to menu:addlabel(""). |
19 | - | print "Detected propellers. Throttle will control blade authority, with a fixed RPM.". |
19 | + | |
20 | - | set rotors to list(). |
20 | + | for txt in menu:widgets { set txt:style:fontsize to 10. set txt:style:padding:v to 1. } |
21 | - | for m in ship:modulesnamed("ModuleRoboticServoRotor") { |
21 | + | |
22 | - | set rotorList to list(m:part). //index 0: part, 1: bool for flipped, 2+: individual blade partmodules |
22 | + | |
23 | - | for p in m:part:children { |
23 | + | |
24 | - | if p:hasmodule("ModuleControlSurface") { |
24 | + | |
25 | - | if rotorList:length = 1 rotorList:add(choose -1 if vang(m:part:facing:vector, p:facing:topvector) > 92 else 1). |
25 | + | |
26 | - | rotorList:add(p:getmodule("ModuleControlSurface")). |
26 | + | |
27 | - | } |
27 | + | |
28 | - | } |
28 | + | set m3:text to (choose "<color=#222>Height: </color>" if vsOverride <> 0 or tAltOverride <> 0 else "Height: ") + "<color=white>" + height + "</color> (priority #3)". |
29 | - | rotors:add(rotorList). |
29 | + | set m4:text to (choose "<color=#222>tAltOverride: </color>" if vsOverride <> 0 or tAltOverride = 0 else "tAltOverride: ")+ "<color=white>" + tAltOverride + "</color> (priority #2 if <> 0)". |
30 | - | }. |
30 | + | set m5:text to (choose "<color=#222>vsOverride: </color>" if vsOverride = 0 else "vsOverride: ") + "<color=white>" + vsOverride + "</color> (priority #1 if <> 0)". |
31 | - | //set rotor1 to ship:modulesnamed("ModuleRoboticServoRotor")[0]:part. |
31 | + | |
32 | - | //set ship:control:pilotmainthrottle to 0.5. |
32 | + | |
33 | - | for s in ship:modulesnamed("ModuleRoboticServoRotor") s:setfield("torque limit(%)", 1). |
33 | + | |
34 | set m9:text to "tiltOutwards: <color=white>" + tiltOutwards + "</color>". | |
35 | set m10:text to "Localport: <color=white>" + localport + "</color>". | |
36 | - | set estNeutral to 0. |
36 | + | |
37 | - | set tarAOA to 0. |
37 | + | |
38 | when true then { | |
39 | - | set mathThingy to 2 * constant:pi * 5.8 * 460/60. |
39 | + | |
40 | - | function bladeAOA { parameter ang. |
40 | + | |
41 | - | set tarAOA to ang. |
41 | + | set mLast4:text to "mul: " + round(mul,2) + ", tpid:iterm: " + round(tpid:iterm,4). |
42 | - | for rotor in rotors { |
42 | + | |
43 | - | set relSpd to vdot(rotor[0]:facing:vector * rotor[1], vel). |
43 | + | |
44 | - | set estNeutral to arctan(abs(relSpd)/mathThingy) * relSpd/abs(relSpd). |
44 | + | |
45 | - | for i in range(2,rotor:length) { |
45 | + | |
46 | - | rotor[i]:setfield("deploy angle",estNeutral + ang). |
46 | + | |
47 | - | } |
47 | + | |
48 | - | } |
48 | + | |
49 | ||
50 | ||
51 | - | set vtol to true. |
51 | + | // [Camera steering, uncomment to enable] |
52 | - | set steeringmanager:rollcontrolanglerange to 180. |
52 | + | //showVD(). |
53 | - | set steeringmanager:rollpid:kp to 0.4. |
53 | + | //trackcam off. |
54 | - | set steeringmanager:rollpid:ki to 0.04. |
54 | + | //when true then { |
55 | - | set steeringmanager:rollpid:kd to 0.25. |
55 | + | // set sl to max(0,sl + (cam:distance - bnds:size:mag) * -3). |
56 | - | set steeringmanager:yawpid:kd to 0.15. |
56 | + | // set cam:distance to bnds:size:mag. |
57 | - | set steeringmanager:maxstoppingtime to 6. |
57 | + | // set m1:text to "SL: <color=white>" + round(sl,2) + "m/s</color> (" + round(tvCopyMag,1) + ")". |
58 | // return lights. | |
59 | - | set flipSteering to false. |
59 | + | //} |
60 | - | set face to facing. |
60 | + | //lock hdg to cam:heading. trackCam off. |
61 | - | set bnds to ship:bounds. |
61 | + |