Introducing LineRider
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!
Introduction
In this lesson, we will learn about arrays and continue to improve our skills with feedback algorithms.
- If you want to store a lot of elements together which are all the same type, you need an array. Below are some examples of arrays:
numeric_array = [1, 5, 7, 9, 2, 8, 2]
string_array = [“cat”, “dog”, “turtle”, “wolf”]
boolean_array = [True, False, False, False, True] - In the example above, the array numeric_array has length 7. We can read the 3rd element like this:
value_of_3rd_element = numeric_array[2]
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
Getting Started
- Start the simulation
- Notice the line on the track. We will write an algorithm to follow this line.
Robot Commands
- robot.is_ok() – True while the simulation is running.
- robot.move(v) – Set robot speed v [meter/sec].
- robot.rotate(ω) – Set robot angular velocity ω [radian/sec]. Positive ω is counter-clockwise (CCW). Negative ω is clockwise (CW).
- robot.image_data() – Used to the get the image from the camera.
- robot.get_sensor_data() – Used to read the pixels of the camera image. More details below.
Checkpoints
Move the Robot
- Our robot is not moving. Try adding the following code:
while robot.is_ok():
robot.move(1.0)
- Run the simulation and observe the robot’s motion.
Accessing the Camera
Your robot has a camera. Let’s have a look.
Click the video camera button.