MINDSTORMS EV3 Core Set

Make a Driverless Car

Design an autonomous vehicle that follows user-defined driving commands.

120+ min.
Intermed.
Years 10-13
roaming-vehicles-gps

Lesson plan

Prepare
- Read through this teacher material.
- If you feel that it is necessary, plan a lesson using the getting started material in the EV3 Lab Software or Programming App. This will help to familiarise your pupils with LEGO® MINDSTORMS Education EV3.

Engage (30 Min.)
- Use the ideas in the Ignite a Discussion section below to engage your pupils in a discussion relating to this project.
- Explain the project.
- Divide your class into teams of two pupils.
- Allow your pupils some time to brainstorm.

Explore (30 Min.)
- Have your pupils create multiple prototypes.
- Encourage them to explore both building and programming.
- Have each pair of pupils build and test two solutions.

Explain (60 Min.)
- Ask your pupils to test their solutions and to choose the best one.
- Make sure that they can create their own testing tables.
- Allow some time for each team to finalise their project and to collect assets for documenting their work.

Elaborate (60 Min.)
- Allow your pupils some time to produce their final reports.
- Facilitate a sharing session in which each team presents their results.

Evaluate
- Provide feedback on each pupil's performance.
- In order to simplify the process, you can use the assessment rubrics that have been provided.

Ignite a Discussion

Today, many navigation systems are used in cars. Some of these systems are now taking on the drivers' responsibility for driving passengers safely to their destinations. Before figuring out the best route between points A and B, autonomous cars must be able to execute a series of movements based on user input.

roaming-vehicles-gps

Encourage an active brainstorming process.
Ask your pupils to think about these questions:

  • What is an autonomous car and how does it work?
  • Where do autonomous cars get their directions from?
  • What movements must the car perform in order to move through a series of city streets on a north, south, east, west grid?

Give your pupils some time to answer these questions.

Encourage your pupils to document their initial ideas and to explain why they chose the solution that they will use for their first prototype. Ask them to describe how they will evaluate their ideas throughout the project. That way, when they are reviewing and revising, they will have specific information that they can use to evaluate their solution and decide whether or not it was effective.

Pseudocode is a great tool for helping pupils to organise their thoughts before they begin programming.

Building Tips

Start by building a vehicle. Your pupils may use any of the suggested LEGO® MINDSTORMS EV3 Driving Base models or design their own model. Make sure that there is clear access to the buttons on top of the EV3 Brick. They will be used to control direction in this activity.

ev3-robot-driving-base

Coding Tips

Explain to your pupils that they will program their robots to move according to a recorded set of instructions that will be given through the buttons on the EV3 Brick. Use these parameters:

  • Up Button bumped, the robot moves forwards 30 cm
  • Down Button bumped, the robot moves backwards 30 cm
  • Left Button bumped, the robot turns 90 degrees left
  • Right Button bumped, the robot turns 90 degrees right

Recording One Action to Make the Robot Move

coding-08-01

Explanation of the Program

  1. Start the program.

  2. Create a Variable Block called ‘Drive’.

  3. Wait for a brick button to be bumped.

  4. Play sound ‘Click 2’.

  5. Record the numerical value of the pressed button in the variable ‘Drive’.

  6. Wait for 2 seconds.

  7. Play sound ‘G02’.

  8. Read the number that is stored in variable ‘Drive’ and send the value to a Switch.

  9. Numeric switch:

    a. If Drive = 0 (default case), do nothing.
    b. If Drive = 1, curve turn the robot left.
    c. If Drive = 3, curve turn the robot right.
    d. If Drive = 4, move the robot straight forwards for 2 rotations of the wheels.
    e. If Drive = 5, move the robot straight backwards for 2 rotations of the wheels.

  10. Play sound ‘Game Over 2’.

Recording Multiple Actions to Make the Robot Move

The Array Operations Block is used to store a sequence of data. It is often described as a table consisting of a single row with multiple columns.

coding-08-02

Explanation of the Solution

  1. Start the program.
  2. Create a Variable Block called ‘Drive’. Choose the ‘Write Numeric Array’ option.
  3. Create a Loop. The example code is set to run 5 times.
  4. Wait for a brick button to be bumped.
  5. Play sound ‘Click’.”
  6. Read the Variable Block ‘Drive’. Choose the ‘Read Numeric Array’ option.
  7. Use the Array Operations Block. Choose ‘Write at Index - Numeric’.

a. Wire-in the ‘Drive’ Variable Block.
b. Wire the Loop index from the front of the Loop into the index location on the Array Operations Block.
c. Wire the value from the Wait for EV3 Button Block into the value location on the Array Operations Block.

  1. Write the output of the Array Operations Block into the Variable Block ‘Drive’.
  2. Wait for 2 seconds.
  3. Play sound ‘Go’.
  4. Create a second Loop. The example code is set to run 5 times, the same number of times as the first Loop.
  5. Read the Variable Block ‘Drive’. Choose the ‘Read Numeric Array’ option.
  6. Use the Array Operations Block. Choose ‘Read at Index - Numeric’ option.
  7. Numeric switch:

a. If Drive = 0 (default case), do nothing.
b. If Drive = 1, curve turn the robot left.
c. If Drive = 3, curve turn the robot right.
d. If Drive = 4, move the robot straight forwards for 2 rotations of the wheels.
e. If Drive = 5, move the robot straight backwards for 2 rotations of the wheels.

  1. Play sound ‘Game Over 2’.
Download Sample Programs 32 KB, Requires EV3 Lab Software

Tabs ‘1’ and ‘2’

EV3 MicroPython Program Solutions

Recording One Action to Make the Robot Move

#!/usr/bin/env pybricks-micropython

from pybricks import ev3brick as brick
from pybricks.ev3devices import Motor
from pybricks.parameters import Port, Stop, Button, SoundFile
from pybricks.tools import wait
from pybricks.robotics import DriveBase

# The Left, Right, Up, and Down Buttons are used to command the robot.
COMMAND_BUTTONS = (Button.LEFT, Button.RIGHT, Button.UP, Button.DOWN)

# Configure 2 motors with default settings on Ports B and C.  These
# will be the left and right motors of the Driving Base.
left_motor = Motor(Port.B)
right_motor = Motor(Port.C)

# The wheel diameter of the Robot Educator Driving Base is 56 mm.
wheel_diameter = 56

# The axle track is the distance between the centers of each of the
# wheels.  This is 118 mm for the Robot Educator Driving Base.
axle_track = 118

# The Driving Base is comprised of 2 motors.  There is a wheel on each
# motor.  The wheel diameter and axle track values are used to make the
# motors move at the correct speed when you give a drive command.
robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)

# Wait until one of the command buttons is pressed.
while not any(b in brick.buttons() for b in COMMAND_BUTTONS):
    wait(10)

# Store the pressed button as the drive command.
drive_command = brick.buttons()[0]
brick.sound.file(SoundFile.CLICK)

# Wait 2 seconds and then play a sound to indicate that the robot is
# about to drive.
wait(2000)
brick.sound.file(SoundFile.GO)
wait(1000)

# Now drive the robot using the drive command.  Depending on which
# button was pressed, drive in a different way.

# The robot turns 90 degrees to the left.
if drive_command == Button.LEFT:
    robot.drive_time(100, -90, 1000) 

# The robot turns 90 degrees to the right.
elif drive_command == Button.RIGHT:
    robot.drive_time(100, 90, 1000)

# The robot drives straight forward 30 cm.
elif drive_command == Button.UP:
    robot.drive_time(100, 0, 3000) 
    
# The robot drives straight backward 30 cm.
elif drive_command == Button.DOWN:
    robot.drive_time(-100, 0, 3000)

# Play a sound to indicate that it is finished.
brick.sound.file(SoundFile.GAME_OVER)
wait(2000)

Recording Multiple Actions to Make the Robot Move

#!/usr/bin/env pybricks-micropython

from pybricks import ev3brick as brick
from pybricks.ev3devices import Motor
from pybricks.parameters import Port, Stop, Button, SoundFile
from pybricks.tools import wait
from pybricks.robotics import DriveBase

# The Left, Right, Up, and Down Buttons are used to command the robot.
COMMAND_BUTTONS = (Button.LEFT, Button.RIGHT, Button.UP, Button.DOWN)

# Configure 2 motors with default settings on Ports B and C.  These
# will be the left and right motors of the Driving Base.
left_motor = Motor(Port.B)
right_motor = Motor(Port.C)

# The wheel diameter of the Robot Educator Driving Base is 56 mm.
wheel_diameter = 56

# The axle track is the distance between the centers of each of the
# wheels.  This is 118 mm for the Robot Educator Driving Base.
axle_track = 118

# The Driving Base is comprised of 2 motors.  There is a wheel on each
# motor.  The wheel diameter and axle track values are used to make the
# motors move at the correct speed when you give a drive command.
robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)

# Pressing a button stores the command in a list.  The list is empty to
# start.  It will grow as commands are added to it.
drive_command_list = []

# This loop records the commands in the list.  It repeats until 5
# buttons have been pressed.  This is done by repeating the loop while
# the list contains less than 5 commands. 
while len(drive_command_list) < 5:
    # Wait until one of the command buttons is pressed.
    while not any(b in brick.buttons() for b in COMMAND_BUTTONS):
        wait(10)
    
    # Add the pressed button to the command list.
    drive_command_list.append(brick.buttons()[0])
    brick.sound.file(SoundFile.CLICK)

    # To avoid registering the same command again, wait until the Brick
    # Button is released before continuing.
    while any(brick.buttons()):
        wait(10)

# Wait 2 seconds and then play a sound to indicate that the robot is
# about to drive.
wait(2000)
brick.sound.file(SoundFile.GO)
wait(1000)

# Now drive the robot using the list of stored commands.  This is done
# by going over each command in the list in a loop.
for drive_command in drive_command_list:
    # The robot turns 90 degrees to the left.
    if drive_command == Button.LEFT:
        robot.drive_time(100, -90, 1000) 

    # The robot turns 90 degrees to the right.
    elif drive_command == Button.RIGHT:
        robot.drive_time(100, 90, 1000)

    # The robot drives straight forward 30 cm.
    elif drive_command == Button.UP:
        robot.drive_time(100, 0, 3000) 
        
    # The robot drives straight backward 30 cm.
    elif drive_command == Button.DOWN:
        robot.drive_time(-100, 0, 3000)

# Play a sound to indicate that it is finished.
brick.sound.file(SoundFile.GAME_OVER)
wait(2000)

Extensions

Language Arts Extension

Option 1
Using Text-Based Programming:

  • Have the pupils explore text-based programming solutions so that they can compare different programming languages.

Option 2
In this lesson, your pupils created a driverless car that operated according to the instructions given to it in an array. What if the driverless cars of the future could be programmed to override input from their human drivers?
To incorporate the development of language arts, have your pupils:

  • Write an argument supporting the claim that driverless cars shouldn't be able to autonomously control their speed despite passenger input
  • Include specific evidence to support the validity of this claim, citing situational examples in which this could leave the passenger at a disadvantage
  • Make sure to address the counter-claim that autonomous speed control by driverless cars could be an effective strategy for improving driver or traffic safety

Maths Extension

In this lesson, your pupils created a turn-by-turn sequence of instructions for a driverless car. Using sensors and machine learning, driverless cars can follow instructions and modify the execution of these instructions based on new conditions.
To incorporate the development of maths skills and explore machine learning applications for driverless cars, give your pupils a ‘budget’ of a certain number of turns. Then have them:

  • Create a grid representing city streets (e.g. five streets that go east to west and five streets that go north to south)
  • Pick a starting point and destination · Keeping in mind that the path with the fewest turns represents the best path, analyse three intersections between the starting point and destination
  • Determine the probability that their vehicle will get to the destination ‘under budget’ in a random direction

Assessment Opportunities

Teacher Observation Checklist
Create a scale that suits your needs, for example:

  1. Partially accomplished
  2. Fully accomplished
  3. Overachieved

Use the following success criteria to evaluate your pupils' progress:

  • The pupils are able to identify the key elements of a problem.
  • The pupils are autonomous in developing a working and creative solution.
  • The pupils are able to communicate their ideas clearly.

Self-Assessment
Once your pupils have collected some performance data, allow them a bit of time to reflect on their solutions. Help them by asking questions, like:

  • Is your solution meeting the Design Brief criteria?
  • Can your robot’s movement(s) be more accurate?
  • What are some ways in which others have solved this problem?

Ask your pupils to brainstorm and document two ways in which they could improve their solutions.

Peer Feedback
Encourage a peer-review process in which each group is responsible for evaluating their own as well as others’ projects. This review process can help the pupils to develop skills in giving constructive feedback as well as sharpen their analytical skills and their ability to use objective data in order to support an argument.

The pupils who enjoyed this lesson might be interested in exploring these career pathways:

  • Business and Finance (Entrepreneurship)
  • Manufacturing and Engineering (Pre-Engineering)

Teacher Support

The pupils will:
Use the design process to solve a real-world problem

National curriculum in England
Design and technology programmes of study: key stage 3 (DFE-00192-2013)

• identify and solve their own design problems and understand how to reformulate problems given to them

• test, evaluate and refine their ideas and products against a specification, taking into account the views of intended users and other interested groups

• develop and communicate design ideas using annotated sketches, detailed plans, 3-D and mathematical modelling, oral and digital presentations and computer-based tools

• understand how more advanced electrical and electronic systems can be powered and used in their products [for example, circuits with heat, light, sound and movement as inputs and outputs]

• apply computing and use electronics to embed intelligence in products that respond to inputs [for example, sensors], and control outputs [for example, actuators], using programmable components [for example, microcontrollers].

Pupil Material

Student Worksheet

Download to view and share the student worksheet.

Share with:

Google ClassroomGoogle Classroom