Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var {loop, move, motor, read, sleep, out} = require('robot-loop')
- loop(main, '192.168.1.159', {
- teamName: 'Battle Bots',
- teamColor: 'red',
- game: '5zlN'
- })
- var steer = move()
- function main (input, rot) {
- if (input === 'forward') {
- forward(rot)
- } else if (input === 'back') {
- back(rot)
- } else if (input === 'left') {
- left(rot)
- } else if (input === 'right') {
- right(rot)
- }else if (input === `stop`) {
- stop()
- }else if (input === `step1`) {
- step1()
- }else if (input === `step2`) {
- step2()
- }else if (input === `step3`) {
- step3()
- }
- }
- function forward (rot) {
- out('moving forward')
- steer.rotations(rot, 40, 0)
- out('done')
- }
- function back (rot) {
- out('moving back')
- steer.rotations(-rot, 40, 0)
- out('done')
- }
- function left (rot) {
- out('turning left')
- steer.rotations(1, 40, -rot)
- out('done')
- }
- function right (rot) {
- out('turning right')
- steer.rotations(1, 40, rot)
- out('done')
- }
- function stop () {
- out(`stop`)
- steer.stop()
- out(`done`)
- }
- function step1 () {
- forward(6)
- back(1)
- right(30)
- }
- function step2 () {
- forward (7)
- back(7)
- right (50)
- }
- function step3 () {
- forward(2)
- left(50)
- forward(5)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement