Robot courier Lesson 6.1 All coursesFor teachersStudy in the app Student Arduino Uno + L298P motor shield
Topic 6 · Lesson 6.1

Robot courier: plan and program

Final task, part 1: choose a level, plan a route and assemble a program from proven parts.

2 × 45 min1–2 students per robotProject

Lesson result

The level of the final task has been selected, the route plan has been recorded and verified. The program goes through the entire route at least in a test run, working versions are saved.

You will learn

  • Select the level of the final task based on your completed tasks ●, ★ and ★★.
  • Break the problem into sections and write down a route plan before writing code.
  • Assemble a program from the functions of previous lessons and check it in parts.
  • Save the working version after each checked part.

Need to know

  • 2.1 Motors: driving and stopping
  • 2.2 Turns and U-turns
  • 3.1 Line sensors and first follow
  • 3.2 P-controller: smooth and fast
  • 4.1 Finding and counting intersections
  • 4.2 Turns at the intersection and route
  • 5.1 Ultrasound: we see the load
  • 5.2 Gripper: pick up and place

Will need

Ultrasonic distance sensorServo gripperLine sensor (analog, Trema) × 2

Your task

You are a delivery service engineer. Such robot couriers are already driving along sidewalks and warehouses: they find the road themselves, pick up the cargo and deliver it to the address. Your robot must leave the start itself, transport two loads to new places and stop at the finish line. During the race, no one helps him: everything is decided by your program.

There are no new commands here. You've already done everything you need to do: drive and turn, stay in line with the P-controller, find intersections, see the load with ultrasound and work with the gripper. Now we need to collect these skills into one program. Lesson 6.2 includes test runs.

Warm up · remember
  1. Than setup() is different from loop() and where should the route be completed so that the robot stands after the finish?
  2. How does the program understand that there is an intersection under the robot?
  3. What to do if the ultrasound does not receive an echo?
1
Lesson 1 · 45 min
Level and plan
1

Select level

6 min

What should a robot do. Now the robot must deliver two loads and finish at the finish line. We are not adding a new sensor: we combine the tested capabilities — movement, finding lines and intersections, ultrasonic approach and gripping.

What we use and how it works. A plan is a sequence of actions with completion conditions. For each section, write down what readings are needed, what action the motors or gripper perform, and what sign to move on to. Functions allow you to name these actions and test them individually; a function call passes control to its commands and then returns it to the route.

How to link a dimension to an action. Before assembling the route, test each function with your short experience. An empty function in a template does not perform an action, even if the program is built successfully. After the last section a clear stop is needed; repeating the route in the loop without the author's decision would start the delivery again.

The task has three levels. They have common rules and evaluation criteria, but the fields are different. The level is chosen based on which lesson tasks you have already completed: tasks ★ were prepared for the intermediate field, ★★ - for the advanced field.

Final task levelWhat lesson assignments are needed
Initial
S-shaped line, two intersections, the order of actions is known in advance.
● Basic 1.12.12.23.13.24.14.25.15.2
Average
Network of roads, four intersections, go straight and meet intersections again.
● Basic 1.12.12.23.13.24.14.25.15.2
★ Intermediate level 1.12.12.23.13.24.14.25.15.2
Advanced
Six intersections, steep S-arcs, you make up your own route according to the map.
● Basic 1.12.12.23.13.24.14.25.15.2
★ Intermediate level 1.12.12.23.13.24.14.25.15.2
★★ Advanced level 1.12.12.23.13.24.14.25.15.2
  1. Open the logbook and see what tasks ●, ★ and ★★ you got.
  2. Choose the level yourself and mark it below. If in doubt, start with the initial one: after the test you can try the next one.
It should work

Level selected and logged.

The task has three levels. They have common rules and evaluation criteria, but the fields are different. The field is selected based on which lesson tasks you have already completed.

Final task levelWhat lesson assignments are needed
Initial
S-shaped line, two intersections, the order of actions is known in advance.
● Basic 1.12.12.23.13.24.14.25.15.2
Average
Network of roads, four intersections, go straight and meet intersections again.
● Basic 1.12.12.23.13.24.14.25.15.2
★ Intermediate level 1.12.12.23.13.24.14.25.15.2
Advanced
Six intersections, steep S-arcs, you make up your own route according to the map.
● Basic 1.12.12.23.13.24.14.25.15.2
★ Intermediate level 1.12.12.23.13.24.14.25.15.2
★★ Advanced level 1.12.12.23.13.24.14.25.15.2
  1. Open the logbook. Write down which tasks ★ you did and in which lessons.
  2. Compare with the list needed for the middle field. What's missing?
  3. Select the field yourself. If you choose the average, but there is no task ★, write down how and when you complete it.
It should work

The field is selected, the log contains a list of completed tasks ★ and a plan for the missing ones.

The task has three levels. They have common rules and evaluation criteria, but the fields are different.

Final task levelWhat lesson assignments are needed
Initial
S-shaped line, two intersections, the order of actions is known in advance.
● Basic 1.12.12.23.13.24.14.25.15.2
Average
Network of roads, four intersections, go straight and meet intersections again.
● Basic 1.12.12.23.13.24.14.25.15.2
★ Intermediate level 1.12.12.23.13.24.14.25.15.2
Advanced
Six intersections, steep S-arcs, you make up your own route according to the map.
● Basic 1.12.12.23.13.24.14.25.15.2
★ Intermediate level 1.12.12.23.13.24.14.25.15.2
★★ Advanced level 1.12.12.23.13.24.14.25.15.2
  1. Write down from the journal the tasks ★★ that you got, and the reliability numbers from the lessons: turning error, how many times the robot passed a sharp arc, accuracy of stopping at the load, delivery reliability from lesson 5.2.
  2. For the advanced field, name the two weakest skills based on these numbers.
  3. Choose the field yourself and justify your choice with numbers. Write down what you will do with your weak skills before the test.
It should work

The field is selected and justified by numbers from the journal, two weak skills and a plan for them are written down.

2

Understand your level assignment

8 min
Starting field: start at the top right, S-shaped line with two intersections, cargo and delivery points at the branches, finish at the bottom left
Starting field.
  1. Leave the start area to the left and find the line.
  2. Follow the left arc along the line and get to the first intersection.
  3. Transport load 1 from the upper end of the branch to the lower end - to place 1.
  4. Get to the second intersection and transport load 2 from the lower end to the upper end - to place 2.
  5. Go through the right curve, exit the end of the line into the finish area and stop.

At the start and finish there are short sections without a line: there the robot drives directly according to your commands.

Intermediate field: a road network with four junctions А, Б, В, Г, start on the left, finish at the bottom right, two loads and two delivery locations
Intermediate field. The junctions are labelled А, Б, В, Г.

Weight 1 → place 1, weight 2 → place 2, then finish. The route is given at the intersections:

SiteThrough the intersections
Start → load 1А → В → Б
Load 1 → place 1Б → В
Place 1 → load 2В → Г
Cargo 2 → place 2G
Place 2 → finishG

You decide where to turn at each intersection - left, right or straight. The robot passes through some intersections several times. Branches that are not on the route are not used.

Advanced field: six junctions А–Е, a tight S-bend on the right, positions 1–6 at the line ends, start at the bottom left, finish at the top
Advanced field. Junctions А–Е, end positions 1–6. The diagram shows the arrangement for card 1.

The cans are in positions 1 and 5. Before planning, draw a card from the pile: it says in what order and where to transport them.

CardFirst deliverySecond delivery
11 → 45 → 3
21 → 35 → 4
35 → 31 → 4
45 → 41 → 3

There is no ready-made route: you choose the path along the intersections yourself, before starting. There are several correct ways. On the right side of the field there is a steep S-shaped link.

Make sure your robot passes the S-shaped connection with the load.

  1. Point your finger on the diagram: start, both loads, both delivery points, finish.
  2. Read the rubric at the end of the lesson. What do you get the most points for?
It should work

You can retell the task of your level in your own words.

3

Check skills individually

10 min
Security

After loading the old program, the robot can start driving immediately. Load programs with the motors power off, the first start is on the stand.

If at least one skill does not work, the entire program will not work. Test each one with a short experiment.

  1. Both wheels spin forward and backward; motors stop when turned off (lesson 2.1).
  2. The robot turns 90° and turns 180° (lesson 2.2).
  3. The robot travels along a line with a P-controller and passes the arcs of its field (lesson 3.2).
  4. The robot finds an intersection and turns from it onto the desired line (lessons 4.1, 4.2).
  5. Ultrasound sees the load at the required distance (lesson 5.1).
  6. The gripper takes, holds and releases the load (lesson 5.2).
It should work

All skills have been tested. What doesn’t work, you first fix it according to the “If it doesn’t work” section of your lesson.

If at least one skill does not work, the entire program will not work. Check each one three times short experience.

SkillLessonPassed from 3
Wheels forward, backward and stop2.1
Rotate 90° and rotate 180°2.2
Line and arcs of your field3.2
Intersection and turn from it4.1, 4.2
Stopping in front of the load5.1
Grab and release5.2
It should work

The table is full. You fix skills that pass less than three times out of three first.

Test your skills by their numbers: for each, write down which result you consider reliable and check it five times.

SkillMy criterionPassed from 5
Straight: 1 m offsetno more... cm
Rotate 90°error no more than …°
Steep arc of own fieldwithout moving
Intersection and turn from itto a new line
Stopping at the cargo… ± 1 cm
Capturethe load does not fall out when turning

Mark the skills that failed five times out of five - you will start working on them.

It should work

The criteria are written in numbers, each skill has a result from five trials.

4

Make a route plan

16 min

A good engineer plans first, then codes. The most difficult thing is the turns on the way back: “left” and “right” are counted from the robot’s nose, not from you.

SiteWhat does a robot do?What function
Start → lineDrives straight to the linedriveStraight()
…
  1. Fill out the plan table in the logbook. One line - one section.
  2. For each intersection, write down: where you came from, where you turned, what you are doing next.
  3. Guide the switched off robot along the plan with your hands. Where does his nose point after each turn?
  4. Write down where the error is most likely to occur and how you will check it.

There are seven sections in the plan: exit, line to intersection 1, load 1, place 1, intersection 2, load 2 and place 2, finish.

The plan has left, right and straight turns. Each encounter with an intersection is recorded on a separate line - even if it is the same intersection. The program does not see the letters: it only knows which solution it is currently executing.

The plan is drawn up according to your card. For each delivery, you chose the path according to the letters of the intersections and can explain why it was chosen. The route is written in such a way that only the decisions at the intersections change for another card.

Hint: The robot turned around - what about “left” now?

Stand up and turn around just like a robot. Your left hand points to his left.

It should work

The plan is written down. My partner walked through it with the robot turned off and found no errors.

2
Lesson 2 · 45 min
Program in parts
5

Prepare the blank

6 min

We assemble the program from functions. A function is an action with a clear name, for example turnLeft(). When the route is written down using function calls, it is easy to compare it with the plan.

Blank with functionsL61_Courier.ino.ino
// Робот-курьер: моя программа итоговой задачи.// Это заготовка, а не решение. Наполни функции своим проверенным кодом// из прошлых уроков и проверяй каждую отдельно, прежде чем собирать маршрут. // --- Моторы (урок 2.1) ---const int LEFT_DIR_PIN = 7;const int LEFT_SPEED_PIN = 6;const int RIGHT_DIR_PIN = 4;const int RIGHT_SPEED_PIN = 5;const int FORWARD = HIGH; // --- Датчики линии (уроки 3.1 и 3.2) ---const int LEFT_SENSOR_PIN = A4;const int RIGHT_SENSOR_PIN = A5;// Перенеси сюда свои измерения белого и чёрного и коэффициент П-регулятора. // --- Ультразвук (урок 5.1) и захват (урок 5.2) ---// Перенеси сюда контакты и настройки из своих проверенных скетчей. void stopMotors() {  // Остановить оба мотора (урок 2.1).} void driveStraight() {  // Проехать прямо проверенное время (урок 2.1), например въезд в зону финиша.} void turnLeft() {  // Повернуть налево на 90° (урок 2.2) или с перекрёстка до линии (урок 4.2).} void turnRight() {  // Повернуть направо.} void turnAround() {  // Развернуться на 180° (урок 2.2).} void followLineToCrossing() {  // Ехать по линии с П-регулятором до перекрёстка (уроки 3.2, 4.1).  // После перекрёстка сначала съедь с широкой чёрной области.} void approachCan() {  // Ехать по линии и остановиться перед грузом по ультразвуку (урок 5.1).} void pickUp() {  // Остановить моторы и закрыть захват (урок 5.2).} void putDown() {  // Открыть захват и отпустить груз (урок 5.2).} void setup() {  // Подготовь выводы, датчики и захват. Убедись, что моторы стоят.   // Здесь — твой маршрут: вызывай функции в порядке своего плана.   stopMotors();} void loop() {  // Задание выполняется один раз в setup(). После финиша робот стоит.}
  1. Open the template and save it under your name.
  2. Move your proven code from previous lessons into functions.
How it works: Why divide the program into functions

If a turn is not working correctly, there is one place that needs to be fixed - the function itself, and not every turn on the route. And the route to setup() reads almost like an outline from a logbook.

We assemble the program from functions. When the route is written down using function calls, it is easy to compare it with the plan.

Preparation: route according to planL61_Courier_Plan.ino.ino
// Робот-курьер, средний уровень: маршрут по плану из журнала.// Функций здесь нет: перенеси свои проверенные функции из уроков 2.1–5.2 в раздел ниже.// Маршрут в setup() разбит на участки плана. В каждый участок впиши вызовы функций. // --- Контакты, измерения и настройки из своих скетчей --- // --- Мои функции (перенеси и проверь каждую отдельно) ---// Нужны: остановка моторов, прямой проезд, линия до перекрёстка, проезд перекрёстка// прямо, поворот налево и направо на перекрёстке, разворот на линии, подъезд к грузу,// взять груз, поставить груз. void setup() {  // Подготовь выводы, датчики и захват. Моторы стоят.   // Участок 1. Старт → линия:   // Участок 2. Линия → груз 1:   // Участок 3. Груз 1 → место 1:   // Участок 4. Место 1 → груз 2:   // Участок 5. Груз 2 → место 2:   // Участок 6. Место 2 → финиш, стоп:} void loop() {  // Задание выполняется один раз в setup(). После финиша робот стоит.}
  1. Open the template and save it under your name. There are no ready-made functions in it.
  2. Transfer your proven functions from lessons 2.1–5.2. Check the list in the preparation that you haven’t forgotten any.
  3. Before each line of the plan in the journal, write down which function performs it. If there is no function for a string, write it and check it separately.
It should work

All the necessary functions have been transferred and tested, each line of the plan has its own function.

Requirement 1. The program is compiled from your proven programs for lessons 4.2–5.2, and not from a blank:

  • actions - functions: line to the intersection, decisions at the intersection, approach to the load, pick up, deliver, turn around;
  • route - data, separate from actions: for another card, only the route lines are changed, the functions are not affected;
  • every function that waits for something has protection against infinite waiting.

There is no own program from lesson 5.2 - take the solution from lesson 5.2 from the teacher as a basis; You write the route and defenses yourself.

  1. Write down in your journal a list of the functions of your program: what each one does and in which lesson it was tested.
  2. Mark functions without infinite wait protection and add protection.
It should work

List of functions with verification lesson, route separated from actions, protections added.

Advanced level Array route

Write down solutions at intersections as an array, for example char route[] = {'L', 'S', 'R'};, and execute them one by one in a loop, as in lesson 4.2. Then for a new card it is enough to change one line.

6

Part 1: from start to first load

12 min
  1. B setup() call the functions of the first section: exit, line, intersection, turn, approach to the load.
  2. Check only this part on the field.
  3. Working - save a copy: "working version 1".
It should work

The robot leaves the start, travels along the line to load 1 and stops in front of it.

If it doesn't work
What do you seeWhat to check
The robot does not find the line after startingDoes the robot's nose point along the line? Is the exit length long enough?
Robot stops on an arcAn arc is not a crossroads. Check the intersection search condition.
A robot passes an intersectionThe speed is high or the intersection condition does not work.
After turning, the robot loses its lineCheck that the turn ends when the sensor has found a new line.
  1. Write down in the log the calls to the functions of the first section according to the plan: exit, line, intersections, turns, access to the cargo. Then transfer them to setup().
  2. Check only this part on the field three times. The robot must stop in front of load 1 every time.
  3. Working - save a copy: "working version 1".
Hint: Where to look for the error

Compare what the robot did with the plan line. On what line did it break? Check this one feature separately.

It should work

The robot leaves the start three times in a row and stops in front of load 1.

Acceptance of part 1. Robot from start to load 1: three times out of three, including when it was placed in the start area 2 cm to the left or right and slightly turned.

  1. Write the route of the first part into the program data and check.
  2. Write down each failure: which function did not work and why.
  3. Working - save "working version 1".
LaunchHow I stood at the startResultWhat went wrong
1Exactly
22 cm to the left
32 cm to the right, rotated
It should work

Three launches out of three with different setup at the start, failures sorted out.

7

Part 2: first delivery

12 min
  1. Add: grab, turn, go to place 1, release, return to the road.
  2. Check only this part: place the robot in front of weight 1 and start it.
  3. Works - save "working version 2".
Hint: When to close the gripper?

Stop the motors first, then close the gripper. End the approach using the ultrasonic distance reading. No echo does not mean that the load is very close.

Hint: The cargo leaves with the robot

Drive away only after the grab has fully opened.

It should work

Weight 1 stands at location 1, the gripper is open, the robot is on the road and looking where it needs to go next.

  1. Record the function calls for the first delivery in the logbook: grip, turn around, travel to location 1, release, return to the road. Then add them to the program.
  2. Check only this part three times: place the robot in front of load 1 and start it.
  3. Works - save "working version 2".
Hint: the order of gripper actions

Remember the rule from lesson 5.2: stop - close; open - wait - drive away.

It should work

Three times in a row, load 1 stands in place 1, the robot is on the road and looks where it needs to go next.

Acceptance of part 2. First delivery three times out of three, including when the load is moved 1 cm to the side of the line.

  1. Add the first delivery to the route data and check it separately: place the robot in front of cargo 1.
  2. How does the robot know where to release? Write down how this place is determined in your program and how accurately.
  3. Works - save "working version 2".
It should work

Three deliveries out of three, including shifted cargo; the method of finding the release location and its accuracy are recorded.

8

Part 3: second delivery and finish

15 min
  1. Add the second delivery and the path to the finish. Weight 2 is in a different place, so the turns will be different - check the plan.
  2. At the end there is a direct entry to the finish and a stop. After the finish, the robot must stand.
  3. Run the entire route from the start. Save "working version 3".
Hint: How to understand when it's time to enter the finish line

There is no black finish mark on the field. Use the last reference point - the end of an arc or the last intersection - and the verified forward time. Two “white” readings do not mean that the line has ended: it may be between the sensors.

It should work

The robot covers the entire route in at least one trial. All working versions have been saved.

Test yourself
  1. Add the second delivery and the route to the finish as planned. Weight 2 is in a different place, so the turns will be different. Each meeting with an intersection is a separate line.
  2. At the end there is a direct entry to the finish and a stop. After the finish, the robot must stand.
  3. Run the entire route from the start. If it breaks, launch only the remaining part from the point of failure. Save "working version 3".
Hint: How to understand when it's time to enter the finish line

There is no black finish mark on the field. Use the last intersection and the verified forward time.

It should work

The robot covers the entire route in at least one trial. All working versions have been saved.

Test yourself
  1. Add the second delivery and the path to the finish. After the finish the robot stands.
  2. Run the entire route from the start. Save "working version 3".
  3. Check the separation of the route from the actions: draw another card, make a route for it and change route data only. The robot goes through a new route at least once.
  4. Write down which parts of the route are unreliable and what you will check in Lesson 6.2.
It should work

The entire route of your card has been completed, the route of the second card has been completed after replacing only the data. A list of unreliable parts is recorded.

Test yourself

Evaluation Criteria

Test races will take place in lesson 6.2 using these criteria.

How the race is scored

Maximum 100Credit from 70
CriterionPointsMax.
Direct departure from the start
5 — I drove forward from the start zone myself.
10 — Reached the line and continued the task without pushing.
10
Movement along the line
10 - I lost the line, but returned to it myself and continued the route.
20 — Passed all sections of the line and arc using the sensors without losing the line.
20
Road selection at intersections
5 - For each of the four decisions at intersections that coincided with the plan.
20
Cargo 1: detection
5 — Stopped in front of the load by ultrasound.
5
Weight 1: Grab
5 - He grabbed the load and took it away, rather than pushing it out.
5
Cargo 1: delivery
5 - The cargo is standing and partially in the desired area.
10 - The load is completely in the desired area, the gripper is released.
10
Cargo 2: detection
5 — Stopped in front of the load by ultrasound.
5
Weight 2: Grab
5 - He grabbed the load and took it away, rather than pushing it out.
5
Cargo 2: delivery
5 - The cargo is standing and partially in the desired area.
10 - The load is completely in the desired area, the gripper is released.
10
Direct entry and stop
5 — After the line, I drove forward into the finish area.
10 - Stopped inside the zone and stands with the motors turned off for at least 3 seconds.
10

Required conditions for credit

  • The team explains their program: showing forward motion, P-control calculation, ultrasonic stopping, gripper control and the line that ends the trip.
  • Bends were made according to the readings of line sensors with a P-controller.
  • The approach to the cargo ends by ultrasound measurement, and not just by time.
  • After the robot starts, no one touches or sends commands to it.

Rules

  • Speed is not assessed: there is no bonus for a fast race.
  • There are no negative penalties. An action not completed simply receives no points.
  • Cargo in a foreign zone or delivered out of order - 0 for its delivery.
  • After manual assistance, the autonomous race is over. You can continue to practice, but no points are added.
  • Each attempt is scored separately. The best parts of different attempts don't add up.
  • There is no penalty for making an emergency stop for safety reasons.

Test yourself

Select answers to prepare. They are not stored or evaluated on the site. Take the knowledge test in the course syllabus or discuss the answers with your instructor.

● Basic

1.The robot was traveling east and turned 180°. Now he needs to turn north. Which way is he turning?
2.The robot found an intersection and turned. Why do you have to exit the black area first before finding the next intersection?
3.Turning left is done with the turnLeft() function and is called four times. Rotation does not work correctly. How many places need to be fixed?
4.Why build a program in parts and save a copy after each working part?
5.On the intermediate field, the robot passes junction В several times. How does the program know what to do there on this visit?

★ Intermediate level

1.In the middle field, the same intersections appear several times. What will help you avoid confusing decisions?
2.The plan entry “go straight through junction Б” has no function. What should you do before assembling the route?
3.Part 1 worked one time out of three. Can I move on to part 2?
4.The whole route was broken in part 3. How can I check the fix faster?
5.Why is the route written in setup() and not in loop()?

★★ Advanced level

1.Route card: left, right, straight. Which entry is correct?
2.For the new card we had to change the turnLeftAtCrossing() function. What does this say about the program?
3.The entrance function is waiting for cargo, but they forgot to deliver the cargo. What should protect the robot?
4.Part 1 passes if the robot stands level at the start, and fails if it is 2 cm to the left. Where is the weak point?
5.The route along the four-solution card ends early. Why?
char route[] = {'L', 'S', 'R', 'L'};for (int i = 0; i < 3; i++) {  followLineToCrossing();  decide(route[i]);}

Answer questions at your level. Correct answers needed: Beginner - 4 out of 5; Average - 4 out of 5; Advanced - 4 out of 5. Answers will be checked by the teacher or course program.

Summary

You have a plan and a program that goes through the route. In lesson 6.2 you will make it reliable and conduct test races.

How to confirm the result

The result of the experiment relates the conditions, program version, observation and conclusion. Comparing attempts with one change helps verify the cause, including failed attempts. The mark refers to practice already completed; repetition for the sake of marking is not necessary. The discrepancy with the forecast sets the next hypothesis to be tested. A model, measurements of a real robot, and an explanation are different types of evidence.

Lesson vocabulary

functionA named block of commands that can be called multiple times: for example, turnLeft().
route planTable of path sections: what the robot does and what function is responsible for it.
working versionA copy of the program in which everything written has already been checked on the field.