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.194', {
- teamName: 'MAzebot',
- teamColor: 'CornflowerBlue',
- game: 'xVvj'
- })
- 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 === `ultraRight`){
- ultraRight()
- }
- }
- 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 ultraRight() {
- while (true){
- var devices = read()
- if (devices.sonic(1) <= 50){
- right (45)
- break
- } else {
- steer.forever(45,0)
- }
- }
- }
- function stop () {
- out (`wheels stop moving`)
- steer.stop()
- out (`done`)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement