Scientists and engineers have been working on autonomous driving for many years. The goal is to create a vehicle that can drive itself without any human intervention. This is a very challenging task, and it is still far from being achieved. However, we can already see some autonomous vehicles on the road.
In this Workshop, we will build our own self-driving vehicle using LEGO Mindstorms EV3 PickwickCars. We will use the EV3 PickwickCars to explore the basic concepts of autonomous driving. We will also learn the basics of programming in Python.
To get started, you need to have the following installed on your computer:
- Python 3
- Visual Studio Code
- PyPi package
python-ev3dev2
We have prepared two ZIPs for you to install the prerequisites. They contain the Python 3 and Visual Studio Code installers as well as the PyPi package python-ev3dev2
installer. You can download them here:
-
Windows 10/11 (no other Windows versions): Windows.zip
-
MacOS: MacOS.zip
First unzip the ZIP file and install Python, then Visual Studio Code and finally run the setup.bat
/setup.sh
file
-
Linux: We don't have a ZIP for Linux, but you can install the prerequisites using the following commands:
wget https://code.visualstudio.com/sha/download?build=stable&os=linux-deb-x64 sudo apt install ./code_*.deb rm code_*.deb sudo apt install python3-pip pip3 install python-ev3dev2
- Python (by Microsoft)
- Python for EV3 (by EV3Dev)
To install the plugins, open Visual Studio Code and click on the Extensions icon in the left sidebar. You can also open the Extensions by pressing Ctrl+Shift+X on Windows or Cmd+Shift+X on MacOS
Search for the plugins and install them.
The code for the workshop is available on GitHub: Workshop ZIP file
Unzip the ZIP file.
Go to File -> Open Folder and select the folder robotic-workshop-main
from the extracted ZIP file.
The workshop is divided into four Missions. Each Mission has a number of Tasks. The Tasks are ordered in a way that you can complete them one after another.
- Getting started
- Get to know your PickwickCar
- Mission 1: Hit the road
- Drive forward and backward
- Steer your PickwickCar
- Enhance your driving/steering skills
- Mission 2: Safety systems in PickwickCars
- Drive to obstacle and stop
- Wait for obstacle to move away
- Avoid obstacles by driving around them
- Mission 3: Follow me car (two robots required)
- Follow me
- Mission Impossible: Autonomous driving
- If you manage this, you are a true PickwickCar master
Repeating certain commands a given number of times can be simplified by using a loop.
In Python you can create one like this:
for _ in range(n): # Repeat n times
... # Your code to be repeated n times.
If you need to know how many times you have already repeated the code, you can use a variable like this:
for i in range(n): # Repeat n times
print(i) # Prints 0, 1, 2, ..., n-1
... # Your code to be repeated n times.
Note: The variable i
is always starting at 0 and is incremented by 1 after each loop. You can use any other variable name instead of i
.
Repeating certain commands forever can be achieved using while-loops
like that:.
while True: # Repeat forever
... # Your code to be repeated forever
To take a decision you have to use an if-statement
if condition:
... # This will run if condition is True
elif another_condition:
...
else:
...
Replace the conditions by logical checks. For example:
"Python" == "Python"
is True
(The code inside the if
gets executed)
"Python" == "Java"
is False
(The code inside the if
doesn't get executed)
1 < 5
is True
(The code inside the if
gets executed)
1 > 5
is True
(The code inside the if
doesn't get executed)
To make it more concrete:
name = "Java"
if name == "Python":
print("The name is Python")
elif name == "Java":
print("The name is Java")
else:
print("The name is unknown")
# Replace n with the speed
# SpeedPercent(100) is the maximum speed of 100%
pickwickCar.on(SpeedPercent(n), SpeedPercent(n))
# Replace n with the number of seconds
pickwickCar.on_for_seconds(SpeedPercent(80), SpeedPercent(80), n)
Note: A full turn is not of 360° due to using wheel degrees instead of absolute pickwickCar location degrees. You have to find out yourself how many degrees your pickwickCar needs to make a certain turn
# You already know everything to turn the PickwickCar
...
- Acceleration and braking smoothly
- Follow me car
- Line following
- Smart car combining multiple safety features
- Color recognision