Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. var {loop, move, motor, read, sleep, out} = require('robot-loop')
  2. loop(main, '192.168.1.194', {
  3. teamName: 'MAzebot',
  4. teamColor: 'CornflowerBlue',
  5. game: 'xVvj'
  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 === `ultraRight`){
  22. ultraRight()
  23. }
  24. }
  25.  
  26. function forward (rot) {
  27. out('moving forward')
  28. steer.rotations(rot, 40, 0)
  29. out('done')
  30. }
  31.  
  32. function back (rot) {
  33. out('moving back')
  34. steer.rotations(-rot, 40, 0)
  35. out('done')
  36. }
  37.  
  38. function left (rot) {
  39. out('turning left')
  40. steer.rotations(1, 40, -rot)
  41. out('done')
  42. }
  43.  
  44. function right (rot) {
  45. out('turning right')
  46. steer.rotations(1, 40, rot)
  47. out('done')
  48. }
  49. function ultraRight() {
  50. while (true){
  51. var devices = read()
  52. if (devices.sonic(1) <= 50){
  53. right (45)
  54. break
  55. } else {
  56. steer.forever(45,0)
  57. }
  58. }
  59. }
  60. function stop () {
  61. out (`wheels stop moving`)
  62. steer.stop()
  63. out (`done`)
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement