This project is a modification of Star Road. Instead of using a color sensor, we will be using a camera. The problem statement is to create a line-following robot using your Pi Camera.
Challenges we completed along the way:
The only change added was the addition of a camera holder which has slits to interlock in front of the robot. The camera stand is placed 8 inches above the ground to successfully capture the scope of the line and not lose track of it.
The code was extremely similar to the color sensor, adjusted to take the inputs of the camera rather than RGB values. The following code uses the camera and tries to keep a following cx value between 50 and 120 in order to go straight. Below 50 goes left, and over 120 goes right. This code was much more responsive due to the camera having better quality than the color sensor.
The only electronics connected was the camera to the Pi board. Everything else stayed the same, except for the removal of the color sensor. Below, one can see how the camera was wired up to the Raspberry Pi 4.
The solution below shows the robot quickly traversing the purple line. It is able to traverse through all the lines with the PID controls enabled. We found it best to not use integral control, so we set Ki to 0 for the robot to run as smoothly and quickly as possible.