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:
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:
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.
8 months ago
Your project is really cool: it has a camera and wifi-controlled. I have also built a remote control car, which is documented on: https://www.instructables.com/How-to-Make-a-Infrar...
Mine uses a infrared sensor instead of wifi, L293D motor control module instead of Traxxas, since my design aims for simplicity and easy reproduce-ability for university projects, science fair and robotic competitions. Mine looks quite bare-bone and messy, while yours looks polished and smooth. The aim of my project is really simplicity over aesthetics.
3 years ago
I am using raspberry pi 3 to control the Traxxas RC car. There is no camera on rpi so I am giving power to steering motor through rpi 5V GPIO pin. Rest all connections are same as given in the diagram in your post.
The steering motor works properly but the acceleration (throttle) motor is not working.
I checked all signals (pwm and ground) going to throttle on the oscilloscope and they seem correct with respect to the duty cycle and voltage level.
Could some one here help me out? Am I missing any connection? Only 2 signals (pwm and ground) are there right?
Thanks in advance!
I got it working!
The throttle pwm was not at its initial ideal duty cycle which is why car's throttle went off. I varied the pwm and it worked!
Question 3 years ago
Great job on this project and thanks for the super clear instructions! I'm making something similar and have a few questions:
1. What board is the Raspberry Pi and its battery mounted on? Is that a Traxxas part or did you find/make it somewhere else?
2. Do you have remove that board and the Raspberry Pi to change the car's battery?
3. Which Traxxas vehicle is this?
Question 4 years ago on Step 8
Looks really nice. How did you mount the rpi case to the Traxxas chassis?
Answer 4 years ago
I think we just used velcro so that we could take the pi on and off for troubleshooting
4 years ago
I have been doing this for a couple of years in my spare time. I have tried a number of solutions such as WebIOPi and Wyliodrin, WebIOpi only worked with earlier releases of Raspbian. I wanted a solution that was free standing and didn't need Internet access.
The solution that I have working for me is based on an article in Linux Format Magazine LXF229 Oct 2017 about using Flask for a web server. As my use of HTML is ancient I found w3schools https://www.w3schools.com/ very useful
When I had it working I made the Raspberry Pi into an Access Point using: https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md
And now my RC-Car is untethered from any network.
1] The Raspberry Pi must be seperately supplied from the power to the motors or it hung the moment the motor wanted current. I used a small backup battery pack for this. https://www.ebay.co.uk/i/263708411847?chn=ps
2] I have three cars that I have picked up along the way. All have a 16 pin DIL IC as the radio receiver/controller. All three cars have IC's from different manufacturers, but all three use the same pins for Left/Right and Forward/Backwards, so if I was clever I would solder in an IC header and use a second header to plug into it so that I could move my R-Pis around.
3] I orignally put the AP software on my new raspberry Pi zero W (inbuilt Wireless) but this didn't work when I put the program SD card in an older Pi with an external WiFi dongle. I realised also that in doing it this way I had no fallback communications as this Pi does not have an Ethernet interface.
My first ever attempt at videoing something for YouTube is here showing the WebIOPi version:
A second recording Different car, I am not sure if it is the same software, is here:
Yours is obviously far more complex than mine with the PWM control of the motors. Well Done.
Reply 4 years ago
Further information. I have just discovered that not all Wifi dongles work as an AP. My Aqprox one won't. Maybe more later if I discover why and how to fix it. That's a ralink chipset. The ZD1211 dongle is quite happy.
Reply 4 years ago
From the Arch Linux wiki for a wireless Access Point, to determine if a dongle is capable of being a software Access Point, run 'iw list'. Mine isn't.
Question 4 years ago on Step 8
thank you ,
can you tell where to get servoblaster from?
5 years ago
That looks neat, thanks for sharing :)