We made this car for our ELEC 424 project at Rice university to learn about how we could use embedded systems to make an autonomous vehicle. We used open cv on a beaglebone black board to control a modified remote control car. The car can now lane keep and stop at "stop signs" along a track. We based our project on one by raja_961.
User raja_961, “Autonomous Lane-Keeping Car Using Raspberry Pi and OpenCV”. Instructables. URL: https://www.instructables.com/Autonomous-Lane-Keeping-Car-U sing-Raspberry-Pi-and/
We paid special attention to the resolution that we captured with our webcam because having a high resolution would make the program take too long to steer accurately and having a resolution that is too low would make picking out specific features too difficult. We found that a resolution of 160x120 fell within our bounds. We also had to find a balance for the proportional gain we used for steering. Steering is controlled by the PWM values we sent to the servos with 6 being a full left turn and 9 being a full right turn. We used a mechanism which would scale the PWM values linear with the degrees of the turn up to a threshold degree, with turns larger than the threshold degree having using the maximum/minimum PWM values. We also found that because the wheels of our car were slightly skewed and so we adjusted the PWM value for 0 degrees to counteract this. We decided to not use the entire range so that the car did not over steer. We found that restricting the PWM values between 6.2 to 8.8 was sufficient so that the car did not over steer or under steer. In the figure below the read lines in the first plot represent the maximum degree before the PWM values are constant, and in the second plot it represents the maximum PWM value. The green lines represent the same things but for the minimum degree and PWM. Finally we used a constant PWM value for the drive motors.
Steering angle and PWM value plot per frame.
We used openCV to determine if there was a stop sign directly ahead. At every frame we masked the hsv representation of the frame, to ignore everything outside of a range of red values. We then averaged the pixels in the resulting matrix and if the average crossed 15.0 we determined that there was a stop sign. We stopped for about 3 seconds at a stop sign.
Here is a video of the final product!