6 Find a way to make the robot follow a line
Your task is to find a way to make the robot follow a line. Given an image of the line that the robot is trying to follow, you need to steer the robot so that it moves along the line.
To make your task easier, the only way that you can steer the robot is to change the velocity of the right wheel of the robot. Trying to control the velocities of both wheels is a harder problem.
The simulation is implemented so that the left wheel of the robot always moves at 5 cm/s. To make the robot turn right, you adjust the right wheel velocity so that it is less than 5 cm/s. To make the robot turn left, you adjust the right wheel velocity so that it is greater than 5 cm/s.
The state of the robot is a vector of values that the describes the robot. The 5 elements of the state vector are:
state(1)
the x coordinate of the robot in the worldstate(2)
the y coordinate of the robot in the worldstate(3)
the bearing of the robot in radiansstate(4)
the left wheel velocity (always 5 cm/s)state(5)
the right wheel velocity
The bearing of the robot is the direction that the robot is currently travelling in; it is represented as an angle in radians measured relative the positive x-axis of the world.
The only element of the state vector that you should change is state(5)
the right wheel velocity.
6.1 followLine.m
Run the followLine
script.
This script simulates a robot trying to follow a horizontal line. As written, there is no steering of the robot so the robot simply moves to the right but never steers towards the line so that the line is in the center of the camera image.
If you read the comments in the script, you will see that inside the while
loop you need to steer the robot by adjusting the right wheel velocity. You should probably create a function that computes the new velocity for the right wheel given the current camera image I
. The same steering function should also work for the other simulations.
6.2 followCurve1.m
Run the followCurve1
script.
This script simulates a robot trying to follow a simple curve. As written, there is no steering of the robot so the robot simply moves to the right but never steers towards the line. Eventually, no complete line is detected in the image so the simulation stops.
Again, you need to add some steering code to make the robot follow the curve. Ideally, the same code can be used in all of the simulations.
6.3 followCurve2.m
Run the followCurve2
script.
This script simulates a robot trying to follow a curved path that is more complicated than the one in followCurve1
. As written, there is no steering of the robot so the robot simply moves to the right but never steers towards the line. Eventually, no complete line is detected in the image so the simulation stops.
Again, you need to add some steering code to make the robot follow the curve. Ideally, the same code can be used in all of the simulations.
6.4 Note
There is no one “correct” solution for this problem. Many different strategies are viable. Ideally, you find a strategy that steers the robot smoothly so that it successfully follows the paths in the three simulations.
It is possible that you do not find a viable strategy that works for all three simulations; this is ok.