Difference between revisions of "Tutorial:Motors"

From IPRE Wiki
Jump to: navigation, search
m
Line 10: Line 10:
  
 
==Example==
 
==Example==
<nowiki>
 
## This code will turn the robot in a circle to the left in place for 3 seconds,
 
## then stop
 
  
from myro import *
+
<nowiki></nowiki>This code will turn the robot in a circle to the left in place for 3 seconds,<br>then stop, turn in place to the right for 3 seconds, then go backward for<br>10 seconds and stop.
initialize()
+
  
    motors(-1,1)
+
def goRobotGo():
 +
<br><nowiki>    </nowiki>from myro import *
 +
<br><nowiki>    </nowiki>initialize()
 +
<br><nowiki>    </nowiki>motors(-1,1)
 +
<br><nowiki>    </nowiki>wait(3)
 +
<br><nowiki>    </nowiki>stop()
 +
<br><nowiki>    </nowiki>motors(1,-1)
 +
<br><nowiki>    </nowiki>wait(3)
 +
<br><nowiki>    </nowiki>backward(1,10)
 +
<br>goRobotGo()
  
    wait(3)
 
 
    stop()
 
 
    motors(1,-1)
 
 
    wait(3)
 
 
    backward(1,10)
 
 
</nowiki>
 
 
[[Category:Tutorials]]
 
[[Category:Tutorials]]

Revision as of 19:50, 4 December 2007

How to use Myro Motors

motors(leftWheelPower,rightWheelPower)

The motors(lWP,rWP) function is used to move the robot forward or backward with variable power to the two wheels.

The leftWheelPower & rightWheelPower parameters are between -1 (for full speed backward) and 1 (full speed forward).

Motors(lWP,rWP) does not take in a time parameter, so the robot will continue to run until it encounters a stop() or other incompatible command.

Example

This code will turn the robot in a circle to the left in place for 3 seconds,
then stop, turn in place to the right for 3 seconds, then go backward for
10 seconds and stop.

def goRobotGo():

from myro import *
initialize()
motors(-1,1)
wait(3)
stop()
motors(1,-1)
wait(3)
backward(1,10)
goRobotGo()