Hi! I’m LineRider. I’m a racing robot and that’s the best thing I do. My task is to finish the course as soon as possible, beat my opponents, and achieve a glorious victory. Have you ever been in a real race? It is very exciting and adrenaline filled. Because of this, I sometimes get excited and wonder what to do. The race course is marked by a line. Can you help me follow it? Let’s start!
In this lesson, we will learn about arrays and continue to improve our skills with feedback algorithms.
Notice that to get the 3rd element, we pass index 2.
In python, the first index has index 0.
numeric_array = [1, 5, 7, 9, 2, 8, 2]
index = 0, 1, 2, 3, 4, 5, 6
Move the Robot
Accessing the Camera
Your robot has a camera. Let’s have a look.
Click the video camera button.
You will see the streaming camera image and a white line moving on and off the camera.
Now it is time to start thinking about how we will write an algorithm to follow the line. The camera has a resolution of 1×32, meaning that it can only scan a line. The line is represented by 32 pixels stored in an array of brightness values called: self.sensor_row
sensor_row = robot.get_sensor_data()
Using the Camera Image
max = 0
index = 0
for i in range(0, len(sensor_row)):
if sensor_row[i] > max:
max = sensor_row[i]
index = i
set_point = len(sensor_row) / 2
error = set_point – index
gain = 0.1
command = gain * error
Make the Robot Smarter
Finish the course in less than 90 seconds.
Let’s see who will be the fastest on the course. Using the time metric at the bottom of our screen, let’s see who can finish the course fastest in the group? 3, 2, 1, Start!