· 9 years ago · Oct 15, 2016, 09:10 PM
1var {loop, move, motor, read, sleep, out} = require('robot-loop')
2loop(main, '192.168.1.122', {
3 teamName: 'Penguin',
4 teamColor: 'magenta',
5 game: `zyvd`
6})
7
8var steer = move()
9
10function 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 === `fB`) {
20 forwardBack()
21 }
22}
23
24function forward (rot) {
25 out('moving forward')
26 steer.rotations(rot, 40, 0)
27 out('done')
28}
29
30function back (rot) {
31 out('moving back')
32 steer.rotations(-rot, 40, 0)
33 out('done')
34}
35
36function left (rot) {
37 out('turning left')
38 steer.rotations(1, 40, -rot)
39 out('done')
40}
41
42function right (rot) {
43 out('turning right')
44 steer.rotations(1, 40, rot)
45 out('done')
46}
47
48function forwardBack () {
49 forward(5.30)
50 back(1)
51 left(45)
52}