Advertisement
sumguytwitches

Dragonfly Eve RPM Prop Control

Jun 10th, 2023 (edited)
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. set steeringmanager:rollcontrolanglerange to 180.
  2. set proprad to 5.8.
  3. set rotormods to ship:modulesnamed("ModuleRoboticServoRotor").
  4. set rotors to list().
  5. for rm in rotormods {
  6. local rotor to lexicon().
  7. set rotor["part"] to rm:part.
  8. set rotor["mod"] to rm.
  9. set rotor["blades"] to list().
  10. for bm in rm:part:ModulesNamed("ModuleControlSurface") {
  11.  
  12. set bladepart to bm:part.
  13. local blade to lexicon().
  14. set blade["mod"] to bm.
  15. set blade["offset"] to vdot(-bladepart:Facing:starvector, bladepart:position - bladepart:parent:position).
  16. set blade["proprad"] to proprad.
  17.  
  18. bm:setfield("deploy", true).
  19.  
  20. rotor["blades"]:add(blade).
  21. }
  22.  
  23. rotors:add(rotor).
  24. //preflight checks
  25. if rotor:part:parent:name:contains("bay") {
  26. set baymod to rotor:part:parent:getmodule("ModuleAnimateGeneric").
  27. if baymod:hasevent("open") baymod:doevent("open").
  28. }
  29. rm:setfield("rpm limit",0).
  30. rm:setfield("brake",0).
  31. rm:setfield("motor",1).
  32. rm:setfield("torque limit(%)", 100).
  33.  
  34. }
  35.  
  36. set first to true.
  37. set tarbladeaoa to 4.5.
  38. set deploycopy to 9.
  39. Fuelcells on.
  40.  
  41. //Lock Vars
  42. set rpmtarget to min(459,max(0, throttle * 460)).
  43.  
  44. //Control Loop
  45. set LoopHz to 10.
  46. on round(time:seconds * LoopHz ) {
  47. set rpmtarget to min(459,max(0, throttle * 460)).
  48. set rpmcopy to rpmtarget.
  49. for rotor in rotors {
  50. local currrpm to rpmcopy.
  51. rotor:mod:setfield("rpm limit", rpmcopy ).
  52. set calcAirspeed to (2 * constant:pi * (rotor:blades[0]:proprad + rotor:blades[0]:offset) * currrpm/60).
  53. set deploycopy to max(3, tarbladeaoa + arctan2(airspeed, calcAirspeed)).
  54. for blade in rotor:blades {
  55. blade:mod:setfield("deploy angle", deploycopy).
  56. }
  57. }
  58.  
  59. return first.
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement