Advertisement
wirawafiy1

FIX SCRIPT

Jun 5th, 2023
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //This is for the JVO Bushwhacker 4x4.
  2. //------------------------------------
  3. //(S) = Settable is something you can set. (C) = Caution is something you can set, but shouldn't. (N) = Not Settable is calculated and dynamic.
  4. //------------------------------------
  5.  
  6. //Front Wheel Management
  7. //Front Wheel Speed Limiter
  8. set wheeldiameter to 4.1. //(C) Meters.
  9. set wheelcircumference to (2*constant:pi)*(wheeldiameter/2). //(C) Circumference.
  10. set frontwheelrpmminimum to 20. //(S) This makes it so it's never 0, otherwise you can't take off.
  11. set frontwheelrpmlimitmultiplier to 120. //(S) This is how much faster the wheel should go. Front wheels spin faster, and that helps with stability.
  12. set frontwheelrpmlimit to (groundspeed/wheelcircumference)*60. //(N) Setting the rpm limit for the first time, but at 0 speed, this is 0.
  13.  
  14. //Steering
  15. set steer to 0. // (N) This is the angle for all hinges.
  16. set yawsteer to 0. //(N) This is Yaw Control for the reaction wheels.
  17. set yawmultiplier to .5. //(S) Yaw Control Multiplier. This makes Yaw help us steer.
  18. set steeringmultiplier to 1.25. //(S) Steering Multiplier. This can keep you from wandering.
  19. set dz to 5. //(S) This is the Deadzone. If Desired Heading is within this number of degrees, it'll steer straight.
  20. set lim to 30. //(S) Steering Angle Clamp.
  21.  
  22. //Heading Management
  23. set tar to body:geopositionlatlng(0,0). //(S) Target to lock to with HDGLOCK.
  24. set hdg to 0. //(S) This is the Heading input.
  25. set hdgtrim to 0. //(S) Use this to navigate around obstacles without changing HDG or TAR values unnecessarily.
  26. set hdglock to false. //(S) Heading lock.
  27. set inverted to false. //(S) Turns off steering when flipped, to aid in not going all over the place.
  28. set inair to 5. //(S) This tells you whether it's off the ground or not. Probably should change that.
  29.  
  30. lock trueheading to body:geopositionof(ship:facing:forevector):heading. //(N) This is True Heading. By: numberless_tim
  31. set p to 0. //Pitch. This should be checked, maybe pitched up to 10 or something on smaller planets.
  32.  
  33. //Anomaly Loader
  34. set as to addons:scansat:getanomalies(body).
  35.  
  36. //Rear Wheel Management
  37. set maxrpm to 200. //(S) Maximum Wheel RPM for Rear Wheels. Front wheel RPM is managed by Groundspeed.
  38. //Torque Limit % Management for all 4 wheels
  39. set maxtorque to 40. //(S) Maximum Torque % at full throttle (Max RPM). Anything above 40 causes Brownout.
  40. set torquelim to 0. // (N) "Torque Limit %" value sent to Drive Rotors.
  41. set maxtorquesnap to 80. //(S) Maximum Torque % that gets snapped to 100% for high power, low speed driving.
  42. set minthrottletorquecutoff to .01. //(S) Minimum Throttle Level for Torque Cutoff. Below this, Torque % is 0, to allow for freewheeling.
  43.  
  44. //Spinny Things On.
  45. ship:partstagged("MR1")[0]:getmodule("ModuleRoboticServoRotor"):setfield("torque limit(%)",10). //This is the spinny thing in the middle.
  46. ship:partstagged("MR2")[0]:getmodule("ModuleRoboticServoRotor"):setfield("torque limit(%)",10). //It spins.
  47.  
  48. //Steering Stuff.
  49. //Per Physics Tick
  50. on time:seconds {
  51.     if hdglock {set hdg to tar:heading+hdgtrim.}.
  52.     if not inverted {set steer to ((body:geopositionof(heading(hdg,0):vector):bearing)*steeringmultiplier)+hdgtrim.} else {set steer to 0.}.
  53.     if steer > lim {set steer to lim.}.
  54.     if steer < -lim {set steer to -lim.}.
  55.     lock steering to srfprograde.
  56.     if (abs(steer) > dz) {set ship:control:yaw to (-(-steer/steer)*(steer/lim))*yawmultiplier.} else {set ship:control:yaw to 0.06.}.
  57.     if (inair < alt:radar) {set ship:control:yaw to 0. lock steering to srfprograde.}.
  58.  
  59.     //Set Front Hinges.
  60.     for hinges in ship:partsdubbedpattern("hinge") {hinges:getmodule("ModuleRoboticServoHinge"):setfield("target angle",steer*steeringmultiplier)}.
  61.  
  62.     //Front Wheel Management
  63.     set frontwheelrpmlimit to ((groundspeed/wheelcircumference)*60)*(frontwheelrpmlimitmultiplier/100).
  64.     ship:partstagged("LFR")[0]:getmodule("ModuleRoboticServoRotor"):setfield("rpm limit",max(frontwheelrpmminimum,frontwheelrpmlimit)).
  65.     ship:partstagged("RFR")[0]:getmodule("ModuleRoboticServoRotor"):setfield("rpm limit",max(frontwheelrpmminimum,frontwheelrpmlimit)).
  66.     return true.
  67. }
  68.  
  69. //End of Physics Tick Loop
  70.  
  71. //Throttle Trigger.
  72. on throttle {
  73.     set torquelim to max(100-(throttle*100),maxtorque).
  74.     if (torquelim > maxtorquesnap) {set torquelim to 100}
  75.     if (throttle < minthrottletorquecutoff) {set torquelim to 0}
  76.     ship:partstagged("LFR")[0]:getmodule("ModuleRoboticServoRotor"):setfield("torque limit(%)",torquelim).
  77.     ship:partstagged("RFR")[0]:getmodule("ModuleRoboticServoRotor"):setfield("torque limit(%)",torquelim).
  78.     ship:partstagged("LRR")[0]:getmodule("ModuleRoboticServoRotor"):setfield("torque limit(%)",torquelim).
  79.     ship:partstagged("RRR")[0]:getmodule("ModuleRoboticServoRotor"):setfield("torque limit(%)",torquelim).
  80.     ship:partstagged("LRR")[0]:getmodule("ModuleRoboticServoRotor"):setfield("rpm limit",maxrpm*throttle).
  81.     ship:partstagged("RRR")[0]:getmodule("ModuleRoboticServoRotor"):setfield("rpm limit",maxrpm*throttle).
  82.     return true.
  83. }
  84.  
  85. //End of Throttle Trigger.
  86.  
  87. wait 5. //This is for the display. It does weird things like tell you the throttle doesn't exist if you don't wait.
  88.  
  89. //Make tiny textbox with speed in KPH and MPH.
  90. set displayWid to gui(150).
  91. displayWid:show().
  92.     set mphSpeed to displayWid:addlabel("mph").
  93.     set kmhSpeed to displayWid:addlabel("kmh").
  94.     set ktsSpeed to displayWid:addlabel("kts").
  95.     set truHeading to displayWid:addlabel("truHeading").
  96.     set hdgdisplay to displayWid:addlabel("heading").
  97.     set hdgtrimdisplay to displayWid:addlabel("trim").
  98.     set throttledisplay to displayWid:addlabel("throttle").
  99.     set displayWid:x to -64.
  100.     set displayWid:y to -450.
  101.     set keep to true.
  102.  
  103. on time:seconds {
  104.     set mphSpeed:text to "<color=white><b>Speed: "+round((velocity:surface:mag*2.23694),2):tostring+" MPH</b></color>".
  105.     set kmhSpeed:text to "<color=white><b>Speed: "+round((velocity:surface:mag*3.6),2):tostring+" KMH</b></color>".
  106.     set ktsSpeed:text to "<color=white><b>Speed: "+round((velocity:surface:mag*1.94384),2):tostring+" KTS</b></color>".
  107.     set throttledisplay:text to "<color=white><b>Throttle Pos: "+round((throttle),2):tostring+"</b></color>".
  108.     set truHeading:text to "<color=white><b>True Heading: "+round(trueheading,2):tostring+"deg.</b></color>".
  109.     set hdgdisplay:text to "<color=white><b>Heading: "+round(hdg,2):tostring+"deg.</b></color>".
  110.     set hdgtrimdisplay:text to "<color=white><b>Heading Trim: "+hdgtrim+"deg.</b></color>".
  111.     return keep.
  112. }
  113.  
  114. //Put this stuff into a widget already.
  115. set posdata to true.
  116. on time:second {
  117.     print "<color>Lat: "+round(ship:latitude,2)+"</color>" at (0,0).
  118.     print "<color>Lng: "+round(ship:longitude,2)+"</color>" at (0,1).
  119.     print "<color>Biome: "+addons:scansat:currentbiome+"</color>" at (0,2).
  120.     print "<color>Dis: "+round(tar:distance)+"</color>" at (0,3).
  121.     print "<color>Time: "+round(tar:distance/groundspeed/60)+"m</color>" at (0,4).
  122.     print "<color>EC: "+round(ship:electriccharge)+"</color>" at (0,5).
  123.     return posdata.
  124. }
  125.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement