Advertisement
blacke00

tgps

Nov 24th, 2012
2,836
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getturtlepos()
  2. local ch -- sets a var for the direction the turtle is facing
  3. rednet.open("right") -- opens the modem
  4. local cx,cy,cz = gps.locate(10) -- gets the turtles position
  5. turtle.forward() -- moves the turtle forward 1 space
  6. local fx,fy,fz = gps.locate(10) -- gets the turtles position
  7. turtle.back() -- moves the turtle back to its original position
  8. rednet.close("right") -- closes the modem
  9. if fx > cx then --if final X is Greater than original X  turtle is facing East
  10. ch = 3 --East
  11. elseif fx < cx then --if final X is Less than original X  turtle is facing West
  12. ch = 1 --West
  13. elseif fz > cz then --if final Z is Greater than original Z  turtle is facing South
  14. ch = 4 --South
  15. elseif fz < cz then --if final Z is Less than original Z  turtle is facing North
  16. ch = 2 --North
  17. end
  18. return cx , cy , cz , ch -- returns position and heading info
  19. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement