HvrdlS

Autopilot Tesla V2

Jun 25th, 2021
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. set done to false.
  2. until done {
  3. clearscreen.
  4. main().
  5.  
  6. function main {
  7. print "Welcome to Tesla AutoPilot V2!".
  8. print "1 - Drive to Target with targeted speed".
  9. print "2 - Call a car to you".
  10. print "Press 9 for exit".
  11. on ag9 {
  12. print "Goodbye!".
  13. }
  14.  
  15. wait until ag1 or ag2.
  16. if ag1 {
  17. if brakes {
  18. toggle brakes.
  19. } else {
  20. print "There isnt brakes!".
  21. }
  22.  
  23. drive().
  24. } else {
  25. if brakes {
  26. toggle brakes.
  27. } else {
  28. print "There isnt brakes!".
  29. }
  30.  
  31. call().
  32. }
  33. }
  34.  
  35.  
  36. function tpid {
  37. set throttp to pidloop(1, 1, 1, -1, 1).
  38. set throttp:setpoint to ts.
  39. set thrott to throttp:update(time:seconds, ship:groundspeed).
  40. }
  41.  
  42. function drive {
  43. set ts to 10.
  44. print "Going".
  45. set tp to latlng(0.2,-74.7).
  46. lock distancelng to (-tp:lng - -ship:geoposition:lng) * 10452.
  47. lock distancelat to (-tp:lat - -ship:geoposition:lat) * 10452.
  48. if tp:lng > ship:geoposition:lng {
  49. lock distancelng to (-ship:geoposition:lng - -tp:lng) * 10452.
  50. }
  51.  
  52. if tp:lat > ship:geoposition:lat {
  53. lock distancelat to (-ship:geoposition:lat - -tp:lat) * 10452.
  54. }
  55.  
  56. lock distance to tp:distance.
  57. until distance < 20 {
  58. print distance.
  59. tpid().
  60. lock wheelthrottle to thrott.
  61. lock wheelsteering to tp.
  62. }
  63.  
  64. toggle brakes.
  65. lock wheelthrottle to 0.
  66. wait until ship:groundspeed < 1.
  67. unlock wheelsteering.
  68. unlock wheelthrottle.
  69. print "Done".
  70. toggle ag1.
  71. main().
  72. }
  73.  
  74. function call {
  75. set ts to 5.
  76. set k to vessel("Валентина Керман"):geoposition.
  77. lock distancelng to (-k:lng - -ship:geoposition:lng) * 10452.
  78. lock distancelat to (-k:lat - -ship:geoposition:lat) * 10452.
  79. if k:lng > ship:geoposition:lng {
  80. lock distancelng to (-ship:geoposition:lng - -k:lng) * 10452.
  81. }
  82.  
  83. if k:lat > ship:geoposition:lat {
  84. lock distancelat to (-ship:geoposition:lat - -k:lat) * 10452.
  85. }
  86.  
  87. lock distance to k:distance.
  88. until distance < 10 {
  89. print distance.
  90. tpid().
  91. lock wheelthrottle to thrott.
  92. lock wheelsteering to k.
  93. }
  94.  
  95. toggle brakes.
  96. lock wheelthrottle to 0.
  97. wait until ship:groundspeed < 1.
  98. unlock wheelsteering.
  99. unlock wheelthrottle.
  100. print "Done".
  101. toggle ag2.
  102. main().
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment