Left, Right, Scribble!

From IPRE Wiki
Jump to: navigation, search

Chapter 2: Left, Right, Scribble!

Things You Will Learn

  • How commands are written - the syntax of Python
  • How to move the robot using commands (without using the gamepad!)
  • How to draw shapes using your robot.


Syntax
Computer commands have their own format. These may seem strange to you at first, since it is quite different from conversational English, but you will get used to it soon. :o)

We will be familiarizing you with a programming language called Python. Python is a relatively simple programming language and exposure to it will help you learn other programming languages easily.

Get Set...Move!
Make sure you remember to type in the following before we start:

>>> from myro import *
>>> init()

Now we will learn how to move your robot in different directions! First let us make your robot move forward.

>>> forward(speed, time)

Note: Whenever you notice underlined text in these handouts, remember to put in numerical values in place of the underlined text.

You need to specify the speed and the amount of time you want your robot to move. The speed can vary from 0 to 1, while the time is measured in seconds. For example, if you write

>>> forward(0.5, 3)

your robot will move forward for 3 seconds at a speed of 0.5. Try it out! Can you guess the commands for moving backwards?
Now let's try some different directions:

>>> turnLeft(speed, time)
>>> turnRight(speed, time)
>>> rotate(speed)

For example, if you want your robot to turn left for 5 seconds at a speed of 0.2, you can type:

>>> turnLeft(0.2, 5)

If you want your robot to turn right for 2 seconds at a speed of 0.4, you can type:

>>> turnRight(0.4, 2)

For example, if you want your robot to rotate at a speed of 0.1, you can type:

>>> rotate(0.1)

Is your robot still rotating? To make it stop, type in:

>>> stop()

Activity: Guard, Scribble, Dance!

Your robot can make shapes! Take a marker from your robot kit and place it upside down in the middle of your robot. Make sure your robot is on the paper that is spread out on the floor (please don’t draw on the floor!).

The watchman has caught the flu and has personally asked your robot to guard your house. You will have to make your robot walk from one end of the gate to the other 5 times. How will you do this?

Suppose you have to walk from point A to B:



First, you will have to type in the forward command to move from A to B:

>>> forward(time, speed)

Remember, you will have to figure out how long it takes at a certain speed and put in those values for time and speed.

Once you reach B, you will have to make a U-turn. You will have to tell your robot to turn right at a certain speed for the amount of time it takes to make a U-turn. An approximate speed and time that allows such a turn is:

>>> turnRight(0.6, 1)

Now can you make it go from B to A? When you reach A, repeat these two commands 5 time, and voila – your robot is now a great guard!

How would you make a square?
Remember, a square has 4 sides of equal length, so use the same speed and amount of time to draw all the sides. In the last activity, you had to make a complete U-turn. For a square, each turn will be half of what you had to do previously. Can you think of an appropriate speed and time for that? How many times do you think you have to turn to make a complete square?





Don't get too frustrated if your robot does not move in a straight line. Even robots are not perfect!

When you are done, you can play around with the commands and make your robot dance! :o)



Chapter 1.
Chapter 3.
Chapter 4.
Chapter 5.
Chapter 6.
Chapter 7.
Chapter 8.

CREU Project Home.