Chapter 2 Personal Robots
-------------------------

Scribbler Robot: Movement commands

(1) motors(LEFT,RIGHT)

LEFT (Wheel) and RIGHT (Wheel) can be any value in the range [-1.0,...,1.0]
Positive value: move forward
Negative value: move backward

motors(1.0,1.0)

will move robot forward at full speed and

motors(0.0, 1.0)

will make robot turn left! left motor stopped and right motor
moves forward at full speed.

(2) Easy to remember commands

forward(SPEED)
backward(SPEED)
turnLeft(SPEED)
turnRight(SPEED)
stop()

another version of these

forward(SPEED, SECONDS)
backward(SPEED, SECONDS)
turnLeft(SPEED, SECONDS)
turnRight(SPEED, SECONDS)

Example of a sequence of commands to make robot move in a square:

forward(1,1)
turnLeft(1,0.3)
forward(1,1)
turnLeft(1,0.3)
forward(1,1)
turnLeft(1,0.3)
forward(1,1)
turnLeft(1,0.3)

There is no direct way to ask the robot to turn exactly 90 degrees!
Also, there is no way to specify it to travel a particular distance
say 2.5 feet!

(3) translate, rotate, move

translate(SPEED)
  Positive SPEED = forward
  Negative SPEED = backward

rotate(SPEED)
  Positive SPEED = anti-clockwise
  Negative SPEED = clockwise

move(TRANSLATE_SPEED, ROTATE_SPEED)
  combination of translate and rotate!

Do This:

motors(1,1)
motors(0,0)

vs

move(1.0,0.0)
stop()

What is the difference? None.

The following three commands will make the robot move backwards
at FULL SPEED:

motors(-1,-1)
move(-1,0)
backward(1)

Defining New Commands:
----------------------

def yoyo():
	forward(1)
	backward(1)
	stop()

yoyo()

A slightly better version of yoyo():

def yoyo():
	forward(1,1)
	backward(1,1)

another equivalent version (using wait(SECONDS)):

def yoyo():
	forward(1)
	wait(1)
	backward(1)
	wait(1)
	stop()

Adding Parameters to Commands
-----------------------------

def yoyo1(speed)
	forward(speed,1)
	backward(speed,1)

yoyo1(0.5)

def yoyo2(waitTime)
	forward(1,waitTime)
	backward(1,waitTime)

yoyo2(1)

def yoyo3(speed,waitTime)
	forward(speed,waitTime)
	backward(speed,waitTime)

yoyo3(0.5,1.5)

Saving New Commands in Modules
------------------------------

###########################################################
# File: moves.py
# Purpose: Two useful robot commands to try out as a module.

# First import myro and connect to the robot

from myro import *
init("simulator")

# Define the new functions...

def yoyo(speed, waitTime):
    forward(speed)
    wait(waitTime)
    backward(speed)
    wait(waitTime)
    stop()
    
def wiggle(speed, waitTime):
    rotate(-speed)
    wait(waitTime)
    rotate(speed)
    wait(waitTime)
    stop()

def dance():
	yoyo(0.5,0.5)
	yoyo(0.5,0.5)
	wiggle(0.5,1)
	wiggle(0.5,1)
	
###########################################################

Do This:

Within IDLE, New Window, Save in a file called moves.py
(it saves in same folder as where Python Start icon is saved!)

from moves import *
yoyo(1,1)