Jump to main content

How do Self-Driving Cars Know What to Do?

1
2
3
4
5
5 reviews

Summary

Active Time
30-45 minutes
Total Project Time
30-45 minutes
Key Concepts
Flowcharts, algorithms
Credits
Ben Finio, PhD, Science Buddies
Valuable input provided by Analog Devices employees.
Sketch of a top-down view of a four way intersection with stop signs and pedestrian crosswalks

Introduction

How do driverless cars know what to do at an intersection? How do they know when they should stop and when it is their turn to go? What about yielding to pedestrians? In this activity, you will write your own algorithm, or list of steps, for a driverless car to follow when navigating through various road scenarios like stop signs, traffic lights, and roundabouts (traffic circles).

This activity is not recommended for use as a science fair project. Good science fair projects have a stronger focus on controlling variables, taking accurate measurements, and analyzing data. To find a science fair project that is just right for you, browse our library of over 1,200 Science Fair Project Ideas or use the Topic Selection Wizard to get a personalized project recommendation.

Materials

  • Paper and pencil or a whiteboard/chalkboard
  • Optional: Sticky notes

Prep Work

  1. There are many "rules of the road" that drivers must follow in order to drive safely. For example, they must stay between the lines, not drive over the speed limit, and not get too close to the car in front of them.

    You might know some of these rules if you have paid attention while riding in a car. For example, you probably know that a red light means stop and a green light means go. The next time you are riding in a car, try to observe what rules the driver follows.

  2. Certain types of roads and intersections have specific rules. For example, take a four-way intersection with stop signs and pedestrian crosswalks (see picture). Cars driving through this intersection have to follow several rules:
    1. Stop at the stop sign.
    2. If there are other cars that got to the intersection before you, let them go through the intersection first.
    3. If there are pedestrians waiting to cross in a crosswalk, let them go first.
    Sketch of a top-down view of a four way intersection with stop signs and pedestrian crosswalks
  3. Driverless cars, also called self-driving cars or autonomous vehicles, also have to follow all these rules.

    A driverless car is controlled by a computer program instead of a human driver. It uses cameras and electronic sensors to see the world around it, detecting things like the road, traffic signs, other cars, and pedestrians.

    Computer scientists write computer programs that tell the car what to do. These programs consist of a set of steps called an algorithm.

    Sometimes algorithms are represented graphically with a flowchart. A flowchart uses blocks of text and arrows to show what should happen next. This flowchart represents an algorithm that uses the rules in Step 2 to tell a car how to drive straight through the intersection.

    A flowchart represents an algorithm for driving through a four-way intersection with stop signs.

    The first question on the flowchart is 'Have we reached the other side of the intersection?' If yes, the arrow points to a box that says 'Finish.' If no, the arrow points to a box that says 'Are we at the stop sign?' If yes, the arrow points to a box that says 'Stop.' If no, the arrow points to a box that says, 'Drive forward.' The flow chart continues with the questions 'Are there other cars at the intersection?' 'Did they get there before us?' and 'Are there pedestrians in the crosswalk?' In each case, there is an action for either yes or no.

    Note that flowcharts use specific symbols for different things. A rectangle represents an action, like "stop" or "drive forward." Diamonds represent questions or decisions, like "Are we at the stop sign?" Rectangles with rounded corners represent the beginning and end of the algorithm, i.e. the "start" and "finish" blocks.

Instructions

  1. Download driverless-car-scenarios (pdf). It contains top-down views of three different types of intersections.
  2. For each type of intersection, make a flowchart based on rules that would help a driverless car get safely from one side of the intersection to the other.

    The Prep Work section shows an example flowchart for the intersection with stop signs, but you can make your own.

    Draw your entire flowchart on a piece of paper or a whiteboard. You can also write on sticky notes, put them on a whiteboard, and then draw arrows to connect them.

  3. Next, ask yourself what happens if other drivers do not follow the rules in each scenario. For example:
    1. For the intersection with stop signs, what happens if another car goes through the intersection without stopping first?
    2. For the intersection with traffic lights, what happens if another car drives through while the light is red instead of stopping?
    3. For the roundabout (traffic circle), what happens if your car is already in the roundabout and another car fails to yield to you (let you go first) when entering?
    Think about:
    Can you modify your flowchart to account for unexpected behavior by other drivers or pedestrians? What about cyclists?
  4. Try moving the Finish point in each scenario. For example, have the vehicle make a left or right turn. (You might need to ask an adult for help with the rules of the road for each scenario.) Make a new flowchart. How does your flowchart need to change?
  5. Make a list of other things that might happen when driving. For example, what other objects might you encounter on or near the road? What types of objects would you swerve or brake to avoid (for example, a person or an animal), and which ones would you drive over (such as a small piece of trash)? How would you decide what to do?

What Happened?

You probably found that designing an algorithm for a driverless car is very complicated! It might be simple to write rules for a very basic scenario, like driving straight through an intersection. However, your algorithm quickly becomes more complicated when you account for unexpected behavior by other drivers or things like turning instead of going straight. Your algorithm might fail and result in a crash if you do not account for certain possibilities, like another driver running a red light. Real driverless cars need to know how to drive in many different scenarios, ranging from winding country roads to speedy highways and busy city streets.

Digging Deeper

There are many rules of the road that drivers must learn—when to stop, when to yield to other cars, etc. These rules can all be written down and put into an algorithm or flowchart like you did in this activity. However, it is impossible to write a computer program with a list of rules that covers every single scenario a driver might encounter.

Humans are very good at reacting to new, unexpected situations and making decisions based on very little information. For example, if a human driver suddenly sees a cow in the middle of the road, they would know to hit the brakes! However, a computer program that has only been told to look for pedestrians and other cars, and has no idea what a cow is or what one looks like, might have no idea that it should stop.

A human driver would also know that it is safer to drive over a small piece of trash like a napkin than to slam on the brakes and risk being hit by another car. However, a computer program that has been told to stop if there is any obstacle in the road might stop unnecessarily.

So if it is impossible to write a program that tells a driverless car exactly what to do in every possible situation, how do these algorithms work?

Real driverless cars use machine learning to "learn" how to drive. They analyze massive amounts of data, like recordings from cameras mounted on cars and actions taken by real human drivers. They use this data to learn how to do everything from identifying street signs to predicting what cars in adjacent lanes might do next.

Check out the links in the Additional Resources section to learn more about machine learning.

icon scientific method

Ask an Expert

Curious about the science? Post your question for our scientists.

For Further Exploration

  • Try drawing your own map with a more complex scenario, like driving from your house to a store. (The document with scenarios contains one example.) Your map can also contain things like speed limits, obstacles in the road, and even multi-lane roads and highways. Can you write an algorithm to safely drive your car from the start to the destination? You might find that it is easier to break your algorithm out into multiple sub-processes or "functions." For example, the flowchart you made at the beginning of this activity could be a function for "driving through an intersection with a stop sign." Functions are useful because you can re-use them multiple times in a program whenever you need them.

Project Ideas

Science Fair Project Idea
How do you design a program that can pilot a self-driving race car? By using machine learning. In this project, you will train your own machine learning model for an autonomous vehicle, the AWS (Amazon Web Services) DeepRacer. You can run your car's machine learning model on a simulated racetrack (Figure 1), or you can purchase a 1/18 scale model vehicle that can race on a physical track (Figure 2). Figure 1. Screenshot of the virtual racing environment. … Read more

Activities

STEM Activity
1
2
3
4
5
6 reviews
How do scientists and engineers control robots that drive around other planets millions of miles away? It's nowhere near as easy as driving a toy remote-control car here on Earth. In this activity you will experience some of the challenges you face when driving a "robot" that you can't see! Read more
STEM Activity
1
2
3
4
5
9 reviews
Have you ever wanted a robot assistant that could do all your household chores? Science fiction has been showing us such robots for decades, but they're still not available! What's taking so long? In this project you will investigate some of the challenges in programming a "robot" to do a simple household task, such as making a sandwich. Read more

Links

Careers

Career Profile
Industrial engineering technicians and technologists work in a lot of different places. They work side by side with engineers to set up and fix processes and machines. Do you like to work with puzzles? If so, you could apply problem solving skills to helping companies improve the way they make products or serve customers. Whether you'd like to work in a factory, office, repair shop or healthcare organization, there is a place for you as an Industrial Engineering Technician or Technologist. Read more
Top
Free science fair projects.