Advertisement
sumguytwitches

SG-22 Control x

Jun 6th, 2023 (edited)
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. for i in range(terminal:height-3) Print "":padright(terminal:width).
  2.  
  3.  
  4. //////////////////// VARS //////////////////
  5.  
  6.  
  7. set taralt to 100.
  8. set currheading to body:geopositionof(ship:facing:vector):heading.
  9. lock x to currheading.
  10. lock p to 15.
  11. lock throttle to 1.
  12. lock steering to heading(x,p).
  13.  
  14. lock sl to 0.
  15.  
  16. set steeringmanager:rollcontrolanglerange to 180.
  17.  
  18.  
  19. set servos to ship:modulesnamed("ModuleRoboticRotationServo").
  20.  
  21. set proprad to 5.8.
  22. set rotormods to ship:modulesnamed("ModuleRoboticServoRotor").
  23. set rotors to list().
  24. for rm in rotormods {
  25.  
  26. local rotor to lexicon().
  27. set rotor["part"] to rm:part.
  28. set rotor["mod"] to rm.
  29. set rotor["job"] to choose "push" if rm:part:parent:tag:contains("push") else "vtol".
  30. print "Found rotor module for job of " + rotor:job.
  31. set rotor["mode"] to "flight".
  32.  
  33. set rotor["blades"] to list().
  34. for bm in rm:part:ModulesNamed("ModuleControlSurface") {
  35. local b to bm:part.
  36.  
  37. local blade to lexicon().
  38. set blade["mod"] to bm.
  39. set blade["offset"] to vdot(-b:Facing:starvector, b:position - b:parent:position).
  40. set blade["proprad"] to proprad.
  41. set blade["angleratio"] to 2 * constant:pi * (blade:proprad + blade:offset)/60.
  42.  
  43. bm:setfield("deploy", true).
  44.  
  45. rotor["blades"]:add(blade).
  46. }
  47.  
  48. rotors:add(rotor).
  49. }
  50. print "rotors setup".
  51.  
  52. set deploycopy to 9.
  53.  
  54. brakes on.
  55. gear on.
  56. set flightmode to "plane".
  57.  
  58. function SetAngle {
  59. parameter targetangle.
  60. if flightmode = "debug" print targetangle at (0,0).
  61. for s in servos if s:hasfield("target angle") s:setfield("target angle", targetangle).
  62. }
  63.  
  64.  
  65. function save {
  66. print "waiting for valid save state".
  67. when (ship:Status = "Landed" or ship:status = "Splashed") and ship:velocity:surface:mag < 0.1 then {
  68. print "saving".
  69. kuniverse:quicksaveto(ship:name).
  70. print "saved to '" + ship:name + "'".
  71. }
  72. }
  73. lock torque to throttle * 100.
  74. lock deploy to 9.
  75. when true then {
  76. set torquecopy to torque.
  77. set deploycopy to deploy.
  78.  
  79. for rotor in rotors {
  80. rotor:mod:setfield("torque limit(%)", torquecopy).
  81. for blade in rotor:blades {
  82. blade:mod:setfield("deploy angle", deploycopy).
  83. }
  84. }
  85.  
  86. return true.
  87. }
  88.  
  89.  
  90. set loop to true. when true then { set dv to airspeed - oldairspeed. set oldairspeed to airspeed. }
  91.  
  92. autoblade off. wait 0. autoblade on. set dvwiggle to 0.002. when abs(dv) < dvwiggle then { set deploy to deploy + 0.05. return autoblade. } when true then { set dv to airspeed - oldairspeed. set oldairspeed to airspeed. return true. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement