Introduction: Raspberry Pi Remote Controlled Car

This project modifies a Traxxas remote control car to be driven from a computer in a remote location. The car can be driven remotely while viewing its perspective through a camera mounted on the car. The car also utilizes a pan tilt motor that moves the camera around so that the user can see everything going on from where the car is. We implemented this project at our university where the wifi network was obtainable across the entire campus. This allowed us to drive the car anywhere that it could connect to the wifi. Realistically if you were to implement this project on your own you could control the car from your computer anywhere that is within reach of that same wifi signal. This instructable is laid out with the idea that if you were to implement this project, you would follow our steps exactly. There are many things that can be modified.

Things you will need:

Traxxas RC Car

Raspberry Pi 3 with memory card

Raspberry Pi case - We purchased ours here http://www.mindsensors.com/rpi/70-pi-case-clear-f... it is not the best quality but it works well with the pan-tilt motor but honestly any pi case will do

Battery pack to power the Pi - We purchased ours here https://www.amazon.com/FOXNOV-5000mAh-Portable-Ch...

Pan-Tilt Motor - We purchased ours here http://www.mindsensors.com/rpi/33-pi-pan

Raspberry Pi Camera

Long Range WiFi USB with Antenna for Raspberry Pi - We purchased ours here https://www.amazon.com/Long-Range-WiFi-Antenna-Ras...

Step 1: Install Linux on Pi

Use your memory card and download a Linux OS for your raspberry pi. We personally used Raspian but any Linux OS will do as long as it has the capability of running python scripts. There are a plethora of online tutorials for getting your pi up and running.

Step 2: Hack the Motor Controller

This was arguably the most difficult part of the project and will vary if you use a different car than the one we used. The Traxxas motor controller that we had was a bit different than many motor controllers in RC cars. The Traxxas motor controller operates by first receiving a certain PWM (pulse width modulation) signal that initializes the controller. After receiving that signal, the PWM can be altered to increase or decrease the speed of the throttle. The steering servo acts like a typical servo where a certain PWM signal will align the wheels to be straight and incrementing that signal in either direction will turn the wheels. We eventually connected our car up to an oscilloscope to read the pwm that was being sent to the motor controller and then we imitated that signal on a function generator to see if it would work.

Step 3: Building the Pan-Tilt Motor

If you purchased the same pan-tilt motor that we did you can click here to find the instructions on how to build it. http://www.mindsensors.com/content/27-assembly-instructions-for-pi-pan-kit. The assembly is fairly simple, but be careful not to lose the screws and to not over tighten them. When finished, you can mount the pan-tilt motor onto your pi case. If you purchased the same one that we did the holes are already cut out and ready.

Step 4: Setting Up the Pi Camera

To be able to maintain visual while you are driving it is helpful to have a webcam server setup with your Pi camera. The first thing that needs to be done is to plug the camera into the Pi. The ribbon fits nicely into the port next to the HDMI port.

The method that was used in this project can be obtained using the following link:

http://elinux.org/RPi-Cam-Web-Interface

You want to make sure your raspberry pi is completely updated before you start this process. Also, use the "Basic Installation" steps This method was chosen because of the minimal latency you get while running off of this server. It isn't perfect, but it is better than the 3 second lag time that was found using other methods. This way it should be less than a second lag time depending on your signal strength.

After you have made it through the steps you should be ready to use it. Just go into your web browser and type in the IPaddress of your raspberry Pi. You should have a link to follow there and then you will be able to see the video

Step 5: Writing the Code

The code is structured in two segments. The main code will run everything but it requires you to import certain sections of code to fully function. The code linked should take car of all of the coding. The only code you need is picam.py and picar2.py. Make sure you put them in the same file when running them. Testconnection1.py is a script that you can run in a separate terminal window to monitor your wifi strength as you drive. If your signal level gets much below 60/100 you will start noticing lag and could have a runaway car if your Pi cuts out.

The code required for the operation of the car is simply one script that does it all. The script allows the user to drive the car using the following keys:

w-acceleration

s-reverse

a-turn left

d-turn right

left arrow - pan left

right arrow - pan right

up arrow - tilt up

down arrow - tilt down

enter - neutral out pan/tilt motor

esc - kill the code completely

Step 6: Wiring Everything Up

The wiring diagram is shown above. We used the pi hat that came with the pan-tilt motor to source the power for the steering servo. Pins 35 and 37 send the PWM signals for the throttle and steering servo motors. The pan and tilt motors are connected to S4 and S5 on the pan tilt hat.

Step 7: Running the Script

If you have made it this far you are doing great and there isn't much left to do. The first thing you can do is bring up your camera screen in a window so that you can see what is going on from the perspective of your car.

In order to run the script properly, certain things must be done. Because our code uses the pygame module it must open a GUI in order to run properly. This GUI must be the active window while driving the car, otherwise the keyboard input will not be received on the car and you will not be able to drive. We found that the easiest way to achieve this is to run a remote desktop on your computer. If you are not familiar with remote desktop there are plenty of tutorials online and microsoft makes an application that runs on both windows and mac if you are using one of those machines. An alternative to running remote desktop is to run your terminal through X quarts on a mac which will also allow you to open up a GUI on your machine.

Once you get the remote desktop of the pi running on your computer you can navigate in the terminal to the location of your python script. Run the script by typing "python ./ picar.py" and the small GUI should pop up. You should be able to drive your car using the wsda keys from throttle and steering and you should be able to pan and tilt the camera by using the up down left right keys. The enter key will return the camera to its neutral position and the escape key will exit the program. Have fun driving!

Step 8: Cautions and Improvements

As most projects go there were many unforeseen difficulties that we encountered along the way with this project. We originally wanted to implement an autonomous mode on the car that would allow the user to give the car GPS locations and it would drive to them. We were short on time however and were unable to implement this feature.

An important note of caution, while we wanted this car to be able to drive completely across our campus wherever there was a wifi signal we were not able to achieve that goal entirely. The car works very well with a wifi signal but does have some issues when the signal strength gets low. As our university is quite large and has many wifi routers, we found that the pi would try to hang on to one router too long until the signal was non-existent. This would result in us losing connection with the car. The pi would then search for wifi and reconnect to a closer router and have great connection once again. This poses problems if you would like to implement this same type of project with a similar wifi setup.

If we had more time we would have liked to implement a feature that is constantly searching for wifi networks and comparing them with the current connection. This would allow the pi to connect to the signal that is the strongest. The largest drawback to this wifi issue is that sometimes when we lost connection, if the throttle was being held down, the code would be stuck in the throttle loop and would not stop. We originally had tried to ping the wifi signal every so often to determine the wifi strength but we still lost signal and had issues.

Take caution when implementing this project so as not to have your car run off without you, or into a wall.