Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. var {loop, move, motor, read, sleep, out} = require('robot-loop')
  2. loop(main, '192.168.1.159', {
  3. teamName: 'Battle Bots',
  4. teamColor: 'red',
  5. game: '5zlN'
  6. })
  7.  
  8. var steer = move()
  9.  
  10. function main (input, rot) {
  11. if (input === 'forward') {
  12. forward(rot)
  13. } else if (input === 'back') {
  14. back(rot)
  15. } else if (input === 'left') {
  16. left(rot)
  17. } else if (input === 'right') {
  18. right(rot)
  19. }else if (input === `stop`) {
  20. stop()
  21. }else if (input === `step1`) {
  22. step1()
  23. }else if (input === `step2`) {
  24. step2()
  25. }else if (input === `step3`) {
  26. step3()
  27. }
  28. }
  29.  
  30. function forward (rot) {
  31. out('moving forward')
  32. steer.rotations(rot, 40, 0)
  33. out('done')
  34. }
  35.  
  36. function back (rot) {
  37. out('moving back')
  38. steer.rotations(-rot, 40, 0)
  39. out('done')
  40. }
  41.  
  42. function left (rot) {
  43. out('turning left')
  44. steer.rotations(1, 40, -rot)
  45. out('done')
  46. }
  47.  
  48. function right (rot) {
  49. out('turning right')
  50. steer.rotations(1, 40, rot)
  51. out('done')
  52. }
  53.  
  54. function stop () {
  55. out(`stop`)
  56. steer.stop()
  57. out(`done`)
  58. }
  59.  
  60. function step1 () {
  61. forward(6)
  62. back(1)
  63. right(30)
  64. }
  65.  
  66. function step2 () {
  67. forward (7)
  68. back(7)
  69. right (50)
  70. }
  71.  
  72. function step3 () {
  73. forward(2)
  74. left(50)
  75. forward(5)
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement