← Computer Science
1 / 1
← → move  F fullscreen  Esc read

Robotics · Lesson 1

RoboMaster: Navigate the Room

Make a robot drive a loop, read a card, and draw a figure 8 with nobody touching the controls

A parade starts and ends in the same place, and a robot can do that too, if you tell it exactly how. Over three days you will program a RoboMaster S1 to loop the whole room and stop on the spot where it began, change its lights to match whichever number card you hold up, and drive a figure 8 around two tables. You write every instruction. The robot follows every one of them, including the wrong ones, with total confidence.

What you'll learn

What you need

You never sign in to anything. The robots are already activated on Mr. Krigger's account. Do not create a DJI account and do not type a password into the app.

Safety rules, read before you start

These are non-negotiable. Breaking them on purpose means you lose access to the robots and earn a 0 for the day.

Your crew and the plan

You work in your competition crew, three or four people sharing one robot. Pass the iPad around. Every person writes and runs part of every program, because every person turns in their own code.

DayMissionYou finish with
Day 1The Circle: loop the room and come backA robot that starts in one light color, drives around the room, and stops on the start spot in a different color
Day 2Number Lights: show a card, change the colorNumbers 1 to 5 each turn the robot a different color
Day 3The Figure 8: around two tablesA figure 8 that touches neither table and ends back on the start spot
What is fixed: the three missions, the safety rules, and what you turn in. What moves: how you build each one. There is never just one right program. If the Circle takes you into Day 2, finish it first. Day 2 is built so you can.

Day 1

The Circle

Day 1 start
  1. Pick up your crew's robot and iPad from Mr. Krigger. Do not turn the robot on yet.
  2. Say the safety rules out loud as a crew, then pick who holds the Stop button first.
  3. Find the tape X on the floor. That is the start spot for every crew.

Goal: by the end of today your robot has started in one light color, driven a full loop around the room, and stopped back on the X in a different color.

Step 1: Wake it up and drive it

  1. Press the button on the battery to power on the robot.
  2. Open the RoboMaster app on the iPad and connect to the robot's own Wi-Fi network. It shows up in the iPad's Wi-Fi settings, and it is not the school network.
  3. You should see the robot's camera on the screen.
  4. Drive it with the on-screen joysticks. Forward, backward, turn, and then push sideways. That one is different.
Why does it go sideways? The wheels are mecanum wheels, which have small rollers set at an angle. Spin the four wheels in the right pattern and the robot slides in any direction without turning. A shopping cart cannot do that.
Checkpoint: you can see through the robot's camera and you have driven it forward, back, around, and sideways.

Step 2: Open the code editor

  1. In the app, go to Lab, then create a new Scratch program. Scratch is code you build by snapping blocks together.
  2. Find the Chassis blocks. The chassis is the body that moves.
  3. Find the LED blocks. We will use these in a minute.

These are the blocks you will use most. The exact wording is how DJI's app writes them.

BlockWhat it does
set chassis to translate at (0)° for (1) mDrives a set distance in the direction of the angle. 0° is forward. Longest allowed is 5 m.
set chassis to translate at (0)° for (1) sSame, but for an amount of time instead of a distance
set chassis to rotate (right) at (0)°Turns by that many degrees. Pick left or right in the block.
set chassis translation speed to (0.5) m/sSets how fast it drives. Start slow.
set chassis (all) LED color to (green) and effect to (solid)Lights the robot in a color you choose
wait (1) sPauses the program

Step 3: Find out how it behaves

Before you plan a route, learn your robot. Build each test, run it, and write down what you saw. Mark the floor with tape so you can measure.

TestQuestion it answers
Translate at 0° for 1 mDid it go one meter? Measure it. Run it three times. Does it land in the same place?
Rotate right 90°Is it a right angle? Which way does a right turn go?
Translate at 90° for 1 mWhich way does 90° send it, left or right? Try −90° too.
Translate at 0° for 2 sHow far does two seconds take you? Is that the same as a distance block would give?
Several ways to do everything. You can move by distance or by time. You can turn the whole robot, or slide it sideways without turning. You can drive an angled line with a single translate block. Nobody on this page is telling you which is best. Try more than one and keep the one that works for you.
Checkpoint: you know which way 90° goes, how far a 1 m block really drives, and what a right turn does.

Step 4: The Circle mission

Here is the job. Your program must:

  1. Start with the robot sitting on the tape X, with its LED set to a color you pick.
  2. Drive a complete loop around the room, around the furniture and the open floor Mr. Krigger marks out. The route is your design.
  3. Stop on the X. As close as you can get.
  4. End in a different color than you started. Set the LED to the new color as the last thing the program does.
  5. Run on its own. Nobody touches the joysticks.
Before any code: walk the route yourself. Count your steps between the turns, and sketch a map on paper with the distance of each side and which way you turn. Programming a robot is giving directions to someone who follows them exactly. If you say 3 meters and the real answer is 4, it stops short and does not complain.

Step 5: Build it a piece at a time

  1. Start the program by setting the starting color.
  2. Add the first side of the route. Run it. Where did the robot end up?
  3. Add the first turn. Run it again from the X. Did it turn where you wanted?
  4. Add the next side and repeat. Do not build the whole loop and then test it. You will not know where it went wrong.
  5. Last block: set the finish color.

A translate block drives at most 5 meters, so a long wall needs two blocks back to back. Here is the shape of a program for a rectangular room. Your numbers will be different, because your room is not a perfect rectangle.

set chassis (all) LED color to (green) and effect to (solid)
set chassis translation speed to (0.5) m/s
set chassis to translate at (0)° for (3) m
set chassis to rotate (right) at (90)°
set chassis to translate at (0)° for (4) m
set chassis to rotate (right) at (90)°
... more sides, until you are back at the X ...
set chassis (all) LED color to (red) and effect to (solid)

Step 6: It missed. Now fix it.

Your first run will not be perfect. That is normal. Every run tells you something, so use it.

What happenedTry this
It turned too farLower the angle a little, like 87° instead of 90°
It did not turn enoughRaise the angle a little
It stopped short of the cornerMake that side a bit longer
It drives past the cornerMake that side a bit shorter
It drifts to one side on a straight runSlow it down, or add a small correction turn after the straight part
It ends near the X but not on itAdjust the last side. This is the hardest one, because every earlier error is in it.
Change one thing, then run it again. If you change five things and it gets better, you will not know which one did it. If you want to test whether a short wait block between a move and a turn helps, test that and nothing else, and keep it only if it does.

Check yourself: what do you fix first?

Your robot finishes the loop but stops about 40 cm past the X. The corners all look fine. What do you try first?

Mini lesson: why a robot drifts

Your robot has no map. It cannot see the room and decide where the wall is. It knows what you told it and roughly how far its wheels have turned, and that is all.

Wheels slip a little on a smooth floor and grip a little on a rough one. Each move is off by a small amount. The next move starts from that wrong spot and adds its own small error, so the errors pile up. That is why the last side of a long loop is the hardest to get right, and why your robot lands closer to the X when the route is shorter. Navigating by counting how far you have gone, with no map, is called dead reckoning. Sailors did it for centuries before anyone had GPS.

Before you leave today

A progress check, not the hand-in. The full list is in the Turn in tab.

This is also a competition event. The Circle is Precision Return, one of the Open Events your crew can enter in the RoboMaster Competition. A better run now means a better entry later.

Day 2

Number Lights

Day 2 start
  1. Finish the Circle first if it is not done. Number Lights is a separate program, so you can come back to the Circle after.
  2. Collect your robot, iPad, and the number cards 1 to 5. Say the safety rules again. Someone new holds the Stop button.
  3. Start a new Scratch program. Do not build this one on top of the Circle.

Goal: by the end of today you can hold up a number card from 1 to 5 and the robot lights up a different color for each one.

Step 1: A robot that can read

The RoboMaster has a camera and it can recognize vision markers: printed cards with a symbol on them. Number cards are one kind. Show it a card and it knows which one you showed it, with no joystick and no one telling it. The robot is not reading the word. It is matching a pattern, the same way a store scanner matches a barcode.

It is switched off by default. The robot will not look for markers until your program tells it to. If you build everything else correctly and nothing happens, this is the first suspect.

Step 2: Turn on marker detection

Build the first piece. You are looking for these blocks:

BlockWhat it does
(enable) (vision marker) identificationTurns on the robot's marker recognition. Put this first in your program.
set vision marker identification distance to (1) mHow far away the robot looks. It works between 0.5 and 3 meters. One meter is a good start.
when ___ identifiedAn event block. The blocks inside it run when the robot sees that marker. Open the dropdown and choose a number marker.

Build one when event for the number 1, and inside it set the chassis LED to a color. Run the program and hold up the 1 card about a meter in front of the camera.

Checkpoint: you hold up the 1 and the robot's LED changes color. If it does not, check the Troubleshooting under the Help tab.

Step 3: All five numbers

Now do the rest. Numbers 1 through 5 each get their own color. You pick the colors. They only have to be five different ones, so that you can tell them apart from across the room.

Show this cardThe robot turns this color
1Your choice
2Your choice
3Your choice
4Your choice
5Your choice

Test each one by itself, and then flip through all five quickly. Does the robot keep up? Does the color change when you switch cards, and not before?

Checkpoint: five cards, five different colors, every time.

Step 4: Make it hard to fool

Real sensors fail in boring ways. Find your robot's limits before someone else does.

Your five blocks are all right, but the robot never reacts to any card. What did you most likely forget?

Mini lesson: how a robot sees

A camera gives the robot a picture, which to a computer is a grid of tiny colored dots. Looking for a marker means searching that grid for a pattern the robot already knows. When it finds one, it tells your program, and your program decides what to do. That is the same path a self-checkout scanner, a license plate reader, and a phone's face unlock all follow. It is also why a dim room or a crooked card can fool it: the pattern in the picture stops matching the pattern in its memory.

Before you leave today

A progress check, not the hand-in. The full list is in the Turn in tab.

Day 3

The Figure 8

Day 3 start
  1. Mr. Krigger has set two tables on the floor. Do not move them. Everyone runs the same course.
  2. Collect your robot and iPad. Say the safety rules. Someone new holds the Stop button.
  3. Open your Circle program. You have already built half of what you need.

Goal: by the end of today your robot drives a figure 8 around the two tables, touches neither one, and ends back on the start spot.

Step 1: The mission

A figure 8 is two loops joined at a crossing. The robot goes around one table one way, passes back through the middle, and goes around the other table the opposite way.

table table X

Step 2: Why this is harder

In the Circle, every turn went the same direction. Here the robot turns one way on the first loop and the other way on the second. It also passes through the same spot twice, so any drift on loop one ruins the crossing and then loop two. Mistakes pile up in both directions at once.

Plan before you code. Sketch the figure 8 on paper. Mark where the robot turns, which way, and how far each side is. Then walk the robot's path yourself, heel to toe.

Build it in four pieces and run each one before you add the next: loop one, the crossing, loop two, the finish. Your Circle program already knows how to loop. That is your starting point. You will change the turn directions for the second loop.

Step 3: Build and tune it

  1. Build loop one. Run it from the X. Does it clear the first table?
  2. Add the crossing. Run it. Is the robot lined up for the second loop?
  3. Add loop two with the opposite turns. Run it.
  4. Adjust until it finishes on the X without touching a table.
Same rule as Day 1: change one thing, then run it again. If it drifts into a table, find the first piece where it went wrong and fix that piece. Do not fix the last piece first. It only looks wrong because the earlier errors are in it.

Your robot clears the first table, then clips the second one on its way around. Where do you look first?

Bonus task: Rainbow

Figure 8 done early, or just want a victory lap? Make the robot cycle through colors like a rainbow. This one is not graded. It is a bonus task you can do for the fun of it, and for the pleasure of showing Mr. Krigger.

The job: the robot's light changes through at least 4 colors in a row, one after another, in an order you choose. You pick the colors. Red, orange, yellow, green, blue, purple is a classic. Nobody is stopping you from doing something stranger.
Checkpoint: four or more colors, in order, and you can see each one.

Before you leave today

A progress check, not the hand-in. The full list is in the Turn in tab.

This is also a competition event. The Figure 8 is the autonomous division of the Figure 8 Grand Prix, the other Open Event in the RoboMaster Competition.

Base and Stretch

Base · everyone

All three missions working. The Circle: starts in one color, loops the room, stops on the X in a different color. Number Lights: cards 1 to 5 each give a different color. The Figure 8: around both tables, touching neither, ending on the X. Your own code for each, and a reflection.

Stretch · required for HS, bonus for MS

Pick two. Reverse Circle: make the Circle run the other way around the room by changing as little as you can, and say what you changed. Number moves: card 5 also makes the robot spin once, as well as changing the color. Card chooses the course: show a 1 before the Figure 8 to loop the left table first, or a 2 to loop the right table first, and the robot decides on its own.

What you turn in

Everything on this list comes out of something you already built. Your own work, from your own turn on the iPad.

Tick the boxes as you go. This page remembers them on your own device. The next screen shows exactly how to hand it in.

Handing it in

Two things to hand in, not one

1 · The assignment

Your code screenshots and your reflection go here, as file uploads.

  1. Open RoboMaster: Navigate the Room in Schoology
  2. Click Submit Assignment
  3. Click Upload
  4. Select all your files at once, then Submit
Do not click "Create". Create is for typing text and will not let you attach a screenshot. Upload is the one you want. This is the most common way work gets lost.

2 · The exit ticket

A separate item in Schoology, taken in class. It is a short quiz on this lesson, and it is graded on its own.

You can do the assignment and the exit ticket in either order, but both have to be done.

Name your files so they make sense. figure8_code.png tells Mr. Krigger what he is opening. A file called IMG_4417.png does not.

What comes next

You just built two of the entries for the RoboMaster Competition. The Circle is Precision Return. The Figure 8 is the Figure 8 Grand Prix, autonomous division. Every crew has to enter at least one autonomous event, and these two are guaranteed to be on the board.

So keep your programs. A crew that tunes its Circle again before the competition lands closer to the X, and the Number Lights work is the start of a robot that reacts to what it sees. Next up is RoboMaster Competition: Design the Game, where your crew designs an event of its own.

Vocabulary

TermWhat it means
AutonomousThe robot runs on its program with nobody touching the controls
ChassisThe body of the robot that moves, wheels included
Mecanum wheelsWheels with angled rollers that let the robot slide sideways and diagonally
ScratchCode you build by snapping blocks together instead of typing it
TranslateMove in a straight line, in any direction, without turning
RotateTurn in place
Dead reckoningWorking out where you are by counting how far you have gone, with no map or GPS
Vision markerA printed card with a symbol or number on it that the robot's camera recognizes
Event blockA block that waits for something to happen, like seeing a card, and then runs the blocks inside it
DebuggingFinding and fixing what is wrong with your program
IterationTest, change one thing, test again, until it works

When it goes wrong

The app will not connect to the robot.
Check that the robot is powered on and that the iPad is on the robot's own Wi-Fi network, not the school network. If it still will not connect, ask Mr. Krigger before you try anything else. The robots are activated on his account.
My program runs but the robot barely moves.
Check the distance and the speed. A tiny distance like 0.5 m is about one big step. A route around a room needs several meters.
It turns too far or not far enough.
Floors change how a turn comes out. Adjust the angle a few degrees at a time and run it again. Change nothing else.
It turned left when I wanted right.
Check the left or right choice in the rotate block. For sideways movement, run the 90° test from Day 1 Step 3 to see which side it sends you to.
It does not end on the X.
Errors pile up over a long route, and the last side holds all of them. Fix the first place the robot goes wrong, then work toward the end.
The LED does not change color.
Make sure the LED block is set to the chassis you are looking at, with the effect set to solid. A color block placed after a long drive will not light up until the drive is done.
My rainbow flashes by too fast to see.
Make the wait block between colors longer. One second per color is easy to see. A tenth of a second is a blur.
It never reacts to a number card.
Three suspects. Did the program enable marker identification first? Is the card within the distance you set, which is at most 3 meters? Is the room bright enough that the camera can see the card clearly? Fix them in that order.
It reacts to the wrong number.
Open each when block and check which marker is chosen in its dropdown. It is easy to build two blocks for the same number.
It hit a table.
Press Stop, tell Mr. Krigger if anything is scratched, and move it back to the X. Then find the first piece of the program where the robot went off course. That is the piece to fix.