RaspberryPi RC-car project

During 2021, I did VCE Applied Computing, In this class, we got the opportunity to work on a project of our choosing. I had an old rc cay lying around with a controller that refused to work. I decided to give it a new life by retrofitting a raspberry pi inside and writing code to control it.

I wanted to create a few seperate programs that would control the car in varying ways.

The steps taken to complete this project were as follows

  1. Create proof of concept
  2. Fit Pi inside car
  3. Create sample code
  4. Add powerbank
  5. Xbox controller code
  6. Computer vision
  7. Ultrasonic sensor and yell detection
  8. Voice commands

Create proof of concept

Before going any further with this project, I needed to ensure that it was possible at first. I connected the drive motor to a 9V battery and a relay that was controlled by the raspberry pi. Once I knew that the wheels spun, I needed to find a way to control the steering, I cut some plastic and hot glued a sg90 servo motor inside the steering box. I confirmed that this functioned correctly with some code.

Fit Pi inside car

Next I had to fit the Raspberry pi and relay HAT inside the car. The Pi just fit, any larger and it would have stuck out the sides. For the relay HAT, I had to trim some on the shell so it would sit back on top, however, it only cut into the bed of the ute, rather than the side where the body panels were therefore, it was not very noticible.

src/IMG_20210713_182849.jpg src/IMG_20210715_194325.jpg src/IMG_20210713_215515.jpg

Create sample code

Next I created some sample code to control both the drive motor and the steering. This piece of code had no user input, It was ran based off time. I also tested it moving under its own weight with a long power cord.

src/20210727_221402.jpg

Add powerbank

Next I added the powerbank under the shell of the car, this allowed me to power the car without a long fixed power cord. I initially hot glued the power bank in place, however later on in the project, I hot glued a paper shell that matches the profile of the powerbank. This allows it to slide in and out so I could swap it out with a charged one instead of waiting for the fixed one to charge before driving the car again.

src/Snapchat-1649997304.jpg src/20210731_154629.jpg

Xbox controller code

Next I wrote code to control the car via an xbox controller. I programmed the triggers to forward and reverse, and I connected the right joystick to steer right and left. Originally, I tried to code it with variable movement so if I pushed the joystick 50% to the right it would only steer 50%. However, the servo could not keep up with continous updates. In the end I made the steeping snap to 3 different locations, forward, left and right. The USB reciever for the joystick has a housing with a pairing button and a light, this housing was too large to fit underneath the shell. I opted to tape it to the roof, it looks like a roof pod that you put snow skis in, which is pretty cool.

Computer Vision

One of the things I wanted the car to do is to detect and run over red cups. There are specially made cameras that have a ribbon cable that slots into a port on the Pi. I found a spot for it to sit in the front bumper and I drilled a hole for the lens. After a couple of days of debuging, I was able to load a tenserflow lite model onto the Pi which detected red cups along with other objects. While this model did work, it was incredibly slow and there was no chance of it being able to control the car. I potentially could have gotten it to work by streaming the camera feed to my desktop pc and sending comands back over wifi, but this was out of my skillset at the time. Although the computer vision did not work, I could have sent the camera feed over LAN to my computer or any device on the network. This allowed me to stay in my room while driving the car around the house with the Xbox controller.

src/Snapchat-182188547.jpg src/20210905_143841.jpg src/20210905_144221.jpg

Ultrasonic sensor and yell detection

A feature I wanted this car to have was to run away when you yell at it while also avoiding obstacles as was suggested from one of my highschool teachers. Firstly, I used a USB microphone and I wrote some code to detect volume level. Then I picked a threshold value between noisy and quiet and I used that to trigger the sequence which worked quite well. I wanted to use an ultrasonic sensor to measure the distance to an object infront of the car. I wanted to use this to steer the car away from any objects. I got the proof of concept working, and I attached it to the front of the car, however it was not responsive enough to steer away in time. I had no way of making the car drive any slower as I did not have a speed regulator.

Voice commands

While I had the microphone working, I wanted to run it through a speach detection library to extract text from my voice and to then use that to drive the car. I had the most success with Google's text to speach engine. It worked with a 1-2 second delay which was acceptable for this project. Originally, I tried to have seperate start and stop commands, but it could not hear me say stop ofer the sound of the motor. I decided that the forward and reverse commands would make it drive for 500ms before stopping, I found that this was a good value, as it would run into things when I set it to 1 second.