← Robotics challenges

Drive and stop

Set the speed of each wheel, drive for a time, turn, and stop.

A parade float, a warehouse trolley and a robot lawn mower all start the same way: two wheels, each told how fast to turn, and for how long.

This robot has two wheels, one on each side, each with its own motor. In blocks, robot motor tank sets the speed of the left and right wheel, from −100 (full speed backwards) to 100 (full speed forwards). You find it in Robot.

Every robot program starts with a block that picks the robot: here, an Elecfreaks Cutebot.

PredictRead the code and say what it will do before you run anything. A wrong guess is fine: it shows you what to look for.

Predict

The program as blocks
Show as code
drive.ts
robot.elecfreaksCuteBot.start()
robot.motorTank(50, 50, 1000)
robot.motorTank(50, -50, 500)

The for … ms part of a motor block (click its + to show it) is a time: the robot keeps that speed for that long, then the program moves on to the next block. 1000 ms is one second.

The robot drives forward for 1 second, then turns for half a second. What happens next?

RunRun it and compare the result with your prediction.

Run

Watch the robot in the simulator. If it drives off the edge or into a box, drag it back to the middle and restart the simulator.

The program as blocks
Show as code
drive.ts
robot.elecfreaksCuteBot.start()
robot.motorTank(50, 50, 1000)
robot.motorTank(50, -50, 500)
Try it yourselfYour edits are saved in this browser.
It opens full screen, so the robot simulator has room, and takes a few seconds to load. Esc comes back. Your work in this step is kept.

InvestigateTrace how each line of code connects to what you see.

Investigate

This version adds robot motor stop at the end, so the robot stops after its turn.

The program as blocks
Show as code
drive.ts
robot.elecfreaksCuteBot.start()
robot.motorTank(50, 50, 1000)
robot.motorTank(50, -50, 500)
robot.motorStop()

Match each pair of wheel speeds with the move it makes. Try any you are unsure of in the simulator.

Ava's program:

The program as blocks
Show as code
robot.elecfreaksCuteBot.start()
robot.motorTank(50, 50, 1000)
robot.motorTank(-50, 50, 500)
robot.motorTank(50, 50, 1000)

Match each pair of wheel speeds with what the robot does.

left 50, right 50
left 50, right −50
left 50, right 20
left −50, right −50

Ava wants her robot to drive, turn, drive again, and then stop. Her robot never stops. Why?

ModifyChange the code on purpose and check the result.

Modify

After the turn, make the robot drive backwards for one second before it stops.

Need a hint?

Add another robot motor tank before robot motor stop.

Another hint

Make both speeds −50. Click the + on the block to add a time, and set it to 1000 ms.

Add a gentle curve before the stop: left wheel 50, right wheel 20, for 2 seconds. Which way does it curve?

Need a hint?

Add a robot motor tank before robot motor stop.

Another hint

Left 50, right 20, for 2000 ms.

Try it yourselfYour edits are saved in this browser.
It opens full screen, so the robot simulator has room, and takes a few seconds to load. Esc comes back. Your work in this step is kept.

After the turn, drive backwards for 1 second, then stop.

This ticks by itself when your blocks do what is asked.

Before stopping, curve to the right: left 50, right 20, for 2 seconds.

This ticks by itself when your blocks do what is asked.

MakeBuild something new using what you have learned. Expect a few tries; that is normal.

Make

Make the robot drive a square, like a delivery trolley going round the four sides of a room:

The turn's time decides the angle. Start with 400 ms and change it until the corners look square.

Try it yourselfYour edits are saved in this browser.
It opens full screen, so the robot simulator has room, and takes a few seconds to load. Esc comes back. Your work in this step is kept.
Need a hint?

repeat is in Loops. Put one drive and one turn inside it, and set it to 4.

Another hint

Drive with 50 50 for 1000 ms; turn with 50 −50. Change the turn's time until each corner looks square. Put robot motor stop after the repeat.

A square: drive and turn, repeated 4 times, then stop.

This ticks by itself when your blocks do what is asked.

Info

On a real robot

The square program runs on a real Cutebot too. Put it on the floor with room to move. Things to notice:

For teachers

Students set each wheel's speed with robot motor tank, drive and turn for a time, and find that a timed move does not stop the motors by itself; they finish by driving a square. About 45 minutes.

Open the teacher guide: answers, solutions, slides and a worksheet.

Students will be able to

Before class

The robot has two wheels, each with its own motor. robot motor tank sets the left and right speeds from −100 to 100: equal speeds drive straight, opposite speeds spin on the spot, and unequal speeds curve. The optional for … ms box is a time: the robot keeps that speed for that long, then the program moves on. The surprise in this lesson is that a time does not stop the motors: they keep doing what they were last told until another motor block changes them. So every program that should end needs robot motor stop.

Every program starts with a block that picks the robot (Elecfreaks Cutebot here). Schools with another supported robot change only that block. Kitronik MOVE Motor is not yet supported by the robot extension: MOVE Motor classes can use the Kitronik blocks on the real robot (move Forward at speed, spin Left at speed, stop, each with a pause), with the same ideas.

The simulator robot also smooths its speed, so starts and stops are gentle. Turns by time are not exact angles: students tune the turn time until a square looks square, which is what they will do on a real robot too.

Running the lesson

  1. Predict: most expect it to stop. Ask: which block told it to stop?
  2. Run: if it disappears off the edge, drag it back and restart the simulator.
  3. Investigate: let students test the match pairs in the simulator. Ava's robot is the lesson's key idea: a time is not a stop.
  4. Modify: −50 −50 drives backwards. The curve goes right because the right wheel is slower.
  5. Make: repeat is in Loops. The turn time for a right angle depends on speed; about 400 ms at 50 is a starting point, then tune.
  6. Real robot (optional): expect drift. robot set motor drift corrects a robot that pulls to one side.

The hard part (on purpose)

A time on a motor block is not a stop. When the robot keeps spinning, ask what the last block tells the motors.

When students get stuck

Stretch and support

Stretch: Drive a triangle (three sides, a bigger turn) and a figure of eight (two curves, one each way).

Support: Give the square's repeat block with one drive inside; students add the turn and the stop.

Where it leads

Next: give each move a name with functions, and build a dance routine. Class ideas: tape a square on the floor and see whose real robot finishes closest to its start.

What each step is for

Now you can
Next lesson2. Moves as functionsName each dance move as a function, then build a routine by calling them.