🚀 Alguni Start learning

Unit 8: Missions

Fetch, carry, and write the plan once.

Unit 8 of 8 in Robotics coding for kids. Its 4 lessons are Pick It Up, Deliver, Write It Once and The Warehouse — below is everything each one explains, and a question or two from it to try.

Every program on this page was driven round the simulated room before it shipped, and prints exactly what it says it prints.

This unit opens with a fortnight’s trial of everything — no card needed — or with a family plan, bought in the iPhone app. The first two units of every track are free for ever. Try it in the app.

🦾 Pick It Up

The gripper

Bolt can pick up a crate that is within 20 cm of it. robot.grab() tries, and tells you whether it managed: True if it got one, False if there was nothing close enough.

robot.carrying() is True for as long as it is holding something.

Python

robot.forward(90)
robot.say(robot.grab())
robot.say(robot.carrying())

It prints

True
True

Try it yourself

The crate is 95 cm away and the robot only drives 40. What does this print?

Python

robot.forward(40)
robot.say(robot.grab())

What does robot.grab() give back when there is nothing in reach?

  • False
  • True
  • The distance to the nearest crate
  • It stops the program

Answer them in the app

📦 Deliver

Putting it down again

A carried crate travels with the robot. robot.drop() leaves it exactly where the robot is standing — so to deliver something, drive to the circle first and drop it there.

Python

robot.forward(90)
robot.grab()
robot.right(90)
robot.forward(90)
robot.drop()
robot.say(robot.carrying())

It prints

False

Try it yourself

Where does the crate end up after robot.drop()?

  • Wherever the robot was standing when it dropped it
  • Back where it was picked up
  • In the goal circle, always
  • Just in front of the robot

Answer it in the app

🧰 Write It Once

A job with a name

Fetching the second crate is the same four steps as the first, with one number changed. def gives those four steps a name and a blank to fill in.

fetch(60) runs the whole errand for the crate 60 cm away. fetch(120) runs it again for the far one — same lines, different number.

Python

def fetch(distance):
    robot.forward(distance)
    robot.grab()
    robot.back(distance)
    robot.drop()

fetch(60)
fetch(120)
robot.say("Both home")

It prints

Both home

Try it yourself

What is distance inside def fetch(distance):?

  • A blank that gets filled in with whatever number you call fetch with
  • The distance to the nearest wall
  • A fixed number set once
  • The name of the crate

Answer it in the app

🏆 The Warehouse

Try it yourself

Three crates, three errands that differ only in which way to turn and how far to go. What is the tidiest program?

  • One function taking a turn and a distance, called three times
  • Three copies of the same six lines
  • One very long line
  • A while loop that never ends

Answer it in the app