Advertisement
sumguytwitches

Hathi Vtol to Target

Aug 23rd, 2023 (edited)
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. ship:dockingports[0]:controlfrom().
  2. rcs on.
  3. set steeringmanager:rollcontrolanglerange to 180.
  4. set servos to ship:modulesnamed("ModuleRoboticRotationServo").
  5. function tilt { parameter tlt is 0. for s in servos if s:hasfield("target angle") s:setfield("target angle", tlt). }
  6.  
  7. for en in ship:engines en:shutdown().
  8. set vectors to ship:partsdubbedpattern("vector").
  9. for vec in vectors vec:activate().
  10. function vertThrust {
  11. set vth to 0. for e in vectors set vth to vth + vdot(up:vector, e:facing:vector) * e:availablethrust.
  12. return max(1,vth).
  13. }
  14. on round(time:seconds * 5) {
  15. set twr to vertThrust()/ship:mass/body:mu*body:position:sqrmagnitude.
  16. return true.
  17. }.
  18.  
  19. set twr to 1.
  20. lock terAlt to max(0,max(ship:geoposition:terrainheight, body:geopositionof(velocity:surface * 15):terrainheight)).
  21. lock talt to 50 + terAlt.
  22. lock vs to max(-30,min(100,((talt^0.8) - (max(0.1,altitude)^0.8)) / 2)).
  23. set tpid to pidloop(2,0.6, 0.3, -0.75, 4).
  24. lock mul to 1 + tpid:update(time:seconds,verticalspeed - vs).
  25.  
  26.  
  27. set steeringmanager:rollpid:kp to 0.4.
  28. for s in servos if s:hasfield("tranverse rate") s:setfield("traverse rate", 10).
  29. set tltpid to pidloop(10,0.5, 15, -30, 65).
  30.  
  31. if not (defined tar) set tar to target.
  32.  
  33. lock tarpos to choose tar if tar:istype("vector") else tar:position.
  34.  
  35. Lock steering to lookdirup(up:vector, -tarpos).
  36.  
  37.  
  38. lock throttle to mul/twr.
  39. lock maxspeed to 0.
  40. lock tv to tarpos:normalized * min(min(maxspeed, (airspeed + 1)* 2),(tarpos:mag/6) ^ 0.85).
  41.  
  42.  
  43. when true then {
  44. set relVelVec to vxcl(up:vector, tv - velocity:surface) / 3.5.
  45. set relVelVec:mag to min(10,relVelVec:mag).
  46. tilt(tltpid:update(time:seconds, vdot(facing:topvector, relVelVec))).
  47. return true.
  48. }
  49.  
  50. lock steering to lookdirup(up:vector * 10 + vxcl(vxcl(up:vector,facing:topvector),relVelVec),-tarpos).
  51. clearscreen.
  52. Print "set maxspeed to continue".
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement