Robot courier: plan and program
Final task, part 1: choose a level, plan a route and assemble a program from proven parts.
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
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.
- Than
setup()is different fromloop()and where should the route be completed so that the robot stands after the finish? - How does the program understand that there is an intersection under the robot?
- What to do if the ultrasound does not receive an echo?
Select level
6 minWhat 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 level | What 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 |
- Open the logbook and see what tasks ●, ★ and ★★ you got.
- 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.
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 level | What 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 |
- Open the logbook. Write down which tasks ★ you did and in which lessons.
- Compare with the list needed for the middle field. What's missing?
- Select the field yourself. If you choose the average, but there is no task ★, write down how and when you complete it.
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 level | What 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 |
- 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.
- For the advanced field, name the two weakest skills based on these numbers.
- Choose the field yourself and justify your choice with numbers. Write down what you will do with your weak skills before the test.
The field is selected and justified by numbers from the journal, two weak skills and a plan for them are written down.
Understand your level assignment
8 min- Leave the start area to the left and find the line.
- Follow the left arc along the line and get to the first intersection.
- Transport load 1 from the upper end of the branch to the lower end - to place 1.
- Get to the second intersection and transport load 2 from the lower end to the upper end - to place 2.
- 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.
Weight 1 → place 1, weight 2 → place 2, then finish. The route is given at the intersections:
| Site | Through the intersections |
|---|---|
| Start → load 1 | А → В → Б |
| Load 1 → place 1 | Б → В |
| Place 1 → load 2 | В → Г |
| Cargo 2 → place 2 | G |
| Place 2 → finish | G |
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.
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.
| Card | First delivery | Second delivery |
|---|---|---|
| 1 | 1 → 4 | 5 → 3 |
| 2 | 1 → 3 | 5 → 4 |
| 3 | 5 → 3 | 1 → 4 |
| 4 | 5 → 4 | 1 → 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.
- Point your finger on the diagram: start, both loads, both delivery points, finish.
- Read the rubric at the end of the lesson. What do you get the most points for?
You can retell the task of your level in your own words.
Check skills individually
10 minAfter 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.
- Both wheels spin forward and backward; motors stop when turned off (lesson 2.1).
- The robot turns 90° and turns 180° (lesson 2.2).
- The robot travels along a line with a P-controller and passes the arcs of its field (lesson 3.2).
- The robot finds an intersection and turns from it onto the desired line (lessons 4.1, 4.2).
- Ultrasound sees the load at the required distance (lesson 5.1).
- The gripper takes, holds and releases the load (lesson 5.2).
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.
| Skill | Lesson | Passed from 3 |
|---|---|---|
| Wheels forward, backward and stop | 2.1 | |
| Rotate 90° and rotate 180° | 2.2 | |
| Line and arcs of your field | 3.2 | |
| Intersection and turn from it | 4.1, 4.2 | |
| Stopping in front of the load | 5.1 | |
| Grab and release | 5.2 |
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.
| Skill | My criterion | Passed from 5 |
|---|---|---|
| Straight: 1 m offset | no more... cm | |
| Rotate 90° | error no more than …° | |
| Steep arc of own field | without moving | |
| Intersection and turn from it | to a new line | |
| Stopping at the cargo | … ± 1 cm | |
| Capture | the load does not fall out when turning |
Mark the skills that failed five times out of five - you will start working on them.
The criteria are written in numbers, each skill has a result from five trials.
Make a route plan
16 minA 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.
| Site | What does a robot do? | What function |
|---|---|---|
| Start → line | Drives straight to the line | driveStraight() |
| … |
- Fill out the plan table in the logbook. One line - one section.
- For each intersection, write down: where you came from, where you turned, what you are doing next.
- Guide the switched off robot along the plan with your hands. Where does his nose point after each turn?
- 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.
The plan is written down. My partner walked through it with the robot turned off and found no errors.
Prepare the blank
6 minWe 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.
// Робот-курьер: моя программа итоговой задачи.// Это заготовка, а не решение. Наполни функции своим проверенным кодом// из прошлых уроков и проверяй каждую отдельно, прежде чем собирать маршрут. // --- Моторы (урок 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(). После финиша робот стоит.}
- Open the template and save it under your name.
- 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.
// Робот-курьер, средний уровень: маршрут по плану из журнала.// Функций здесь нет: перенеси свои проверенные функции из уроков 2.1–5.2 в раздел ниже.// Маршрут в setup() разбит на участки плана. В каждый участок впиши вызовы функций. // --- Контакты, измерения и настройки из своих скетчей --- // --- Мои функции (перенеси и проверь каждую отдельно) ---// Нужны: остановка моторов, прямой проезд, линия до перекрёстка, проезд перекрёстка// прямо, поворот налево и направо на перекрёстке, разворот на линии, подъезд к грузу,// взять груз, поставить груз. void setup() { // Подготовь выводы, датчики и захват. Моторы стоят. // Участок 1. Старт → линия: // Участок 2. Линия → груз 1: // Участок 3. Груз 1 → место 1: // Участок 4. Место 1 → груз 2: // Участок 5. Груз 2 → место 2: // Участок 6. Место 2 → финиш, стоп:} void loop() { // Задание выполняется один раз в setup(). После финиша робот стоит.}
- Open the template and save it under your name. There are no ready-made functions in it.
- Transfer your proven functions from lessons 2.1–5.2. Check the list in the preparation that you haven’t forgotten any.
- 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.
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.
- Write down in your journal a list of the functions of your program: what each one does and in which lesson it was tested.
- Mark functions without infinite wait protection and add protection.
List of functions with verification lesson, route separated from actions, protections added.
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.
Part 1: from start to first load
12 min- B
setup()call the functions of the first section: exit, line, intersection, turn, approach to the load. - Check only this part on the field.
- Working - save a copy: "working version 1".
The robot leaves the start, travels along the line to load 1 and stops in front of it.
| What do you see | What to check |
|---|---|
| The robot does not find the line after starting | Does the robot's nose point along the line? Is the exit length long enough? |
| Robot stops on an arc | An arc is not a crossroads. Check the intersection search condition. |
| A robot passes an intersection | The speed is high or the intersection condition does not work. |
| After turning, the robot loses its line | Check that the turn ends when the sensor has found a new line. |
- 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(). - Check only this part on the field three times. The robot must stop in front of load 1 every time.
- 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.
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.
- Write the route of the first part into the program data and check.
- Write down each failure: which function did not work and why.
- Working - save "working version 1".
| Launch | How I stood at the start | Result | What went wrong |
|---|---|---|---|
| 1 | Exactly | ||
| 2 | 2 cm to the left | ||
| 3 | 2 cm to the right, rotated |
Three launches out of three with different setup at the start, failures sorted out.
Part 2: first delivery
12 min- Add: grab, turn, go to place 1, release, return to the road.
- Check only this part: place the robot in front of weight 1 and start it.
- 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.
Weight 1 stands at location 1, the gripper is open, the robot is on the road and looking where it needs to go next.
- 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.
- Check only this part three times: place the robot in front of load 1 and start it.
- Works - save "working version 2".
Hint: the order of gripper actions
Remember the rule from lesson 5.2: stop - close; open - wait - drive away.
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.
- Add the first delivery to the route data and check it separately: place the robot in front of cargo 1.
- How does the robot know where to release? Write down how this place is determined in your program and how accurately.
- Works - save "working version 2".
Three deliveries out of three, including shifted cargo; the method of finding the release location and its accuracy are recorded.
Part 3: second delivery and finish
15 min- 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.
- At the end there is a direct entry to the finish and a stop. After the finish, the robot must stand.
- 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.
The robot covers the entire route in at least one trial. All working versions have been saved.
- 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.
- At the end there is a direct entry to the finish and a stop. After the finish, the robot must stand.
- 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.
The robot covers the entire route in at least one trial. All working versions have been saved.
- Add the second delivery and the path to the finish. After the finish the robot stands.
- Run the entire route from the start. Save "working version 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.
- Write down which parts of the route are unreliable and what you will check in Lesson 6.2.
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.
Evaluation Criteria
Test races will take place in lesson 6.2 using these criteria.
How the race is scored
| Criterion | Points | Max. |
|---|---|---|
| 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
★ Intermediate level
★★ Advanced level
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
| function | A named block of commands that can be called multiple times: for example, turnLeft(). |
| route plan | Table of path sections: what the robot does and what function is responsible for it. |
| working version | A copy of the program in which everything written has already been checked on the field. |