Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.21 KB | None | 0 0
  1. local gpsConfig = "config/gps"
  2. local currentF = 0
  3. local currentX = 0
  4. local currentY = 0
  5. local currentZ = 0
  6. local gpsConfig = {}
  7. local FileVersion = "Alpha 1.0"
  8.  
  9. function gotoPos(targetX,targetY,targetZ,targetF)
  10. print("Loading GPS-Data")
  11. Position = filesystem.loadFile("config/gps")
  12. if Position == nil then
  13. error("GPS-config Datei nicht gefunden: "..gpsConfig)
  14. else
  15. currentF = tonumber(Position["f"])
  16. currentX = tonumber(Position["x"])
  17. currentY = tonumber(Position["y"])
  18. currentZ = tonumber(Position["z"])
  19. print("loaded Position")
  20. print(currentX.." "..currentY.." "..currentZ)
  21. travelHigh = tonumber(Position["travelHigh"]
  22. print("loaded TravelHigh "..travelHigh)
  23. print("Going to Road")
  24. goRoad(currentY)
  25. print("Finished")
  26. print("Fixing X-Coord")
  27. goX(targetX)
  28. print("Finished")
  29. print("Fixing Z-Coord")
  30. goZ(targetZ)
  31. print("Finished")
  32. print("Facing the right direction")
  33. faceTo(targetF)
  34. print("Finished")
  35. print("Going down to right Position")
  36. goY(targetY)
  37. print("Ziel erreicht")
  38. end
  39. saveGPS()
  40. end
  41.  
  42. function getPos()
  43. aktPos = filesystem.loadFile(config/gps)
  44. return aktPos
  45. end
  46.  
  47. function faceTo(direction)
  48. print("FaceTo "..direction)
  49. while currentF ~= direction do
  50. right()
  51. end
  52. end
  53.  
  54. function goX(targetX)
  55. if targetX > currentX then
  56. faceTo(3)
  57. while targetX ~= currentX do
  58. print(" X-not in POS")
  59. print(" must go EAST")
  60. forward()
  61. end
  62. elseif targetX < currentX then
  63. faceTo(1)
  64. while targetX ~= currentX do
  65. print(" X-not in POS")
  66. print(" must go WEST")
  67. forward()
  68. end
  69. end
  70. end
  71.  
  72. function goY(targetY)
  73. while currentY ~= targetY do
  74. print(" Y-not in POS")
  75. if currentY > targetY then
  76. print(" must go down")
  77. down()
  78. elseif currentY < targetY then
  79. print(" must go up")
  80. up()
  81. end
  82. end
  83. end
  84.  
  85. function goZ(targetZ)
  86. if targetZ > currentZ then
  87. faceTo(0)
  88. while currentZ ~= targetZ do
  89. print(" Z-not in POS")
  90. print(" must go SOUTH")
  91. forward()
  92. end
  93. elseif targetZ < currentZ then
  94. faceTo(2)
  95. while currentZ ~= targetZ do
  96. print(" Z-not in POS")
  97. print(" must go NORTH")
  98. forward()
  99. end
  100. end
  101. end
  102.  
  103. function up()
  104. moved = false
  105. while not(moved) do
  106. moved = turtle.up()
  107. end
  108. currentY = currentY + 1
  109. saveGPS()
  110. end
  111.  
  112. function down()
  113. moved = false
  114. while not(moved) do
  115. moved = turtle.down()
  116. end
  117. currentY = currentY - 1
  118. saveGPS()
  119. end
  120.  
  121. function left()
  122. turtle.turnLeft()
  123. currentF = currentF - 1
  124. if currentF < 0 then
  125. currentF = 3
  126. end
  127. saveGPS()
  128. end
  129.  
  130. function right()
  131. turtle.turnRight()
  132. currentF = currentF + 1
  133. if currentF > 3 then
  134. currentF = 0
  135. end
  136. saveGPS()
  137. end
  138.  
  139. function forward()
  140. moved = false
  141. if currentF == 0 then
  142. currentZ = currentZ + 1
  143. while not(moved) do
  144. moved = turtle.forward()
  145. end
  146. elseif currentF == 1 then
  147. currentX = currentX - 1
  148. while not(moved) do
  149. moved = turtle.forward()
  150. end
  151. elseif currentF == 2 then
  152. currentZ = currentZ - 1
  153. while not(moved) do
  154. moved = turtle.forward()
  155. end
  156. elseif currentF == 3 then
  157. currentX = currentX + 1
  158. while not(moved) do
  159. moved = turtle.forward()
  160. end
  161. end
  162. saveGPS()
  163. end
  164.  
  165. function back()
  166. moved = false
  167. if currentF == 0 then
  168. currentZ = currentZ - 1
  169. while not(moved) do
  170. moved = turtle.back()
  171. end
  172. elseif currentF == 1 then
  173. currentX = currentX + 1
  174. while not(moved) do
  175. moved = turtle.back()
  176. end
  177. elseif currentF == 2 then
  178. currentZ = currentZ + 1
  179. while not(moved) do
  180. moved = turtle.back()
  181. end
  182. elseif currentF == 3 then
  183. currentX = currentX - 1
  184. while not(moved) do
  185. moved = turtle.back()
  186. end
  187. end
  188. saveGPS()
  189. end
  190.  
  191. function saveGPS()
  192. gpsConfig["x"] = tonumber(currentX)
  193. gpsConfig["y"] = tonumber(currentY)
  194. gpsConfig["z"] = tonumber(currentZ)
  195. gpsConfig["f"] = tonumber(currentF)
  196. gpsConfig["travelHigh"] = tonumber(travelHigh)
  197. filesystem.writeFile("config/gps",gpsConfig)
  198. print(" X= "..currentX.." Y= "..currentY.." Z= "..currentZ)
  199. end
  200.  
  201.  
  202. function goRoad()
  203. print("move from current High "..currentY)
  204. print("to travelHigh "..travelHigh)
  205. while currentY ~= travelHigh do
  206. if currentY > travelHigh then
  207. down()
  208. elseif currentY < travelHigh then
  209. up()
  210. end
  211. end
  212. end
  213.  
  214. function init()
  215. print("Loading GPS-Data")
  216. Position = filesystem.loadFile("config/gps")
  217. if Position == nil then
  218. error("GPS-config Datei nicht gefunden: "..gpsConfig)
  219. else
  220. currentF = tonumber(Position["f"])
  221. currentX = tonumber(Position["x"])
  222. currentY = tonumber(Position["y"])
  223. currentZ = tonumber(Position["z"])
  224. print("loaded Position")
  225. print(currentX.." "..currentY.." "..currentZ)
  226. travelHigh = tonumber(Position["travelHigh"]
  227. print("loaded TravelHigh "..travelHigh)
  228. end
  229. end
  230.  
  231. function loadWaypoint(filename)
  232. Waypoint = filesystem.loadFile("waypoints/"..filename)
  233. if Waypoint == nil then
  234. error("Datei nicht gefunden: "..filename)
  235. else
  236. return Waypoint
  237. end
  238. end
  239.  
  240. function listWaypoints()
  241. WaypointList = fs.list("waypoints/")
  242. return WaypointList
  243. end
  244.  
  245. function createWaypoint(Waypoint)
  246. filesystem.writeFile("waypoints/"..Waypoint["name"],Waypoint)
  247. end
  248.  
  249. function deleteWaypoint(Waypoint)
  250. filesystem.delete(Waypoint)
  251. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement