WebRTC Creeper Drone – Browser Controlled RC Car
This is an advanced Instructable, which describes the process of building a drone controlled remotely from a browser. The drone uses an Android phone to stream video and audio back to the browser via WebRTC.
Since the software used in this project is somewhat complex, you will need to have some programming experience in order to benefit from this Instructable, as I will not be explaining the software parts in great detail.
Step 1: Allow me to introduce the Creeper Drone
Creeper Drone was created from a cheap RC truck, which I modified with an Android and Raspberry Pi, so it can now be driven over a WiFi network from any browser that supports WebRTC. The Creeper transmits a video stream, allowing the driver to control the Creeper from a remote location. Bi-directional audio is also supported, providing the driver with the ability to converse through the Creeper.
This Instructable provides a detailed description of the hardware, software and part manufacturing that went into this project.
Step 2: Architecture and Design
All 3 devices must be connected to the same WiFi network. The diagram above shows the Android phone being used as a WiFi Hotspot, with the other 2 devices connecting to it, but other configurations are possible.
One obvious improvement to this design would be to enable communication with the Android device via the Mobile connection instead of WiFi, thus extending the drone’s range to anywhere with LTE coverage. This would likely require an addition of a TURN server into the design.
The Creeper Drone can be controlled from any WiFi connected device that can run Chrome, or another WebRTC capable browser.
A WebSocket is used as a signalling channel between the browser and the Android phone.
A simple TCP/IP socket is used for communicating with the Raspberry Pi. The Raspberry Pi uses the onboard GPIO port to communicate with the Control Board which handles the hardware requirements of driving servos and motors.
Once the WebSocket handshake completes, the WebRTC stack on the Android is initialized and an SDP Offer is sent via the WebSocket to the browser. The client code running in the browser receives the Offer, initializes its own WebRTC stack and send an SDP Answer. At this point the Android and the Browser exchange ICE Candidates and establish a WebRTC session.
When a successful WebRTC session is established, the user can now see and hear everything through the Creeper Drone. Using the keyboard the user can now control the camera position and drive the drone.
A Control Command is sent through the WebSocket, recognized as such by the CreeperAndroid app, and forwarded to the Raspberry Pi via a network socket. The RPi receives the command and dispatches it to the correct PWM Generator module (servos require a different control scheme from DC motors). The selected PWM module uses the pigpio library to send PWM signals through the GPIO port. Once the selected command was executed, a Status Message for the appropriate servo/motor is communicated back through the network socket, through the WebSocket and into the Browser page the user is using to control the drone.
Step 3: Selecting the RC car
The RC car I used was a $50 New Bright F-150 Truck.
I highly recommend not getting the same RC truck! I only got it b/c at the time, I did not know any better. The problem with this toy is illustrated in the close up of the steering mechanism. That small gear shaft is not driven by a servo – it’s a conventional motor, which spins until it is jammed at the extremes of travel. The wheels are straightened when power is removed by a small spring on the other side. This means that there is only one angle at which the wheels can be turned, and that angle is way too small for making sharp turns at low speeds.
Even worse, this design assumes that the car will be instructed to turn only momentarily, b/c it does not have a speed controller and therefore goes way too fast to ever require long turns. Since we are definitely building a speed controller into the Creeper Drone, the time we need to spend turning increases drastically. Since the turning mechanism relies on stalling a DC motor (which should never be done anyways), we spend way too much time drawing about 2A from the battery, which naturally destroyed the steering motor in about 5 minutes of heavy usage.
I actually had to completely remove the steering mechanism and replace it with a servo mechanism that I will discuss later.
If you would like to try this project, do yourself a favour and select some kind of treaded platform that can turn on a dime, such as an RC tank of comparable size.
Step 4: Major Parts List
- A large RC car or tank
- A battery pack to power the Raspberry Pi and the Servos. I used a RAVPower 10400mAh External Battery Pack.
- A Raspberry Pi.
- An Android device with some sort of holster and clip that will help you attach the Android to the servo assembly. I used a Samsung Galaxy S4 running Android 4.2.2, with an Otterbox Defender.
- Servos powerful enough to hold the weight of the phone and handle the front steering. I used the HS-645MG Ultra Torque Servo. This servo is strong enough, but it still fails to park properly in positions where the weight of the phone is torquing on it with full force.
- Pan and Tilt unit. I got the SPT100.
Step 5: Assorted Parts List
Some other things you will need:
- Materials for making a PCB. There are plenty of tutorials out there, so I won’t cover it here.
- Type A Male to Type A Male USB cable for powering the servos.
- Type A Male to Micro USB Male for powering the Raspberry Pi.
- L293D Half-H Driver (x2)
- GPIO connection header, socket and 13×2 ribbon cable.
- 680uF capacitors (x3)
- Assorted resistors, caps and transistors shown in the schematic later on.
Step 6: Install python and pigpio library on Raspberry Pi
TODO: Python install procedure
TODO: pigpio install procedure
You may be wondering why I chose pigpio, instead of the more well known RPi.GPIO library. The problem with RPi.GPIO is that it still does not support hardware PWM on more than one pin, whereas pigpio provides independent hardware PWM on any of GPIO pins simultaneously by utilizing the DMA controller on the RPi.
Step 7: Control Board
This section describes the control circuit used to drive servos and the rear motor from RPi’s GPIO port.
Although it’s way to early in the process to be making a board, I am placing this section here b/c I wanted to show you the schematic. It will be useful to have parts of this circuit wired up on a breadboard in order to incrementally test the different parts of the software that follow.
The board was designed in Kicad (professional quality, free, open-source software) and made on ProtoMat S103 available at my local Maker Space (AssentWorks). I am attaching my Kicad project to this tutorial.
Note that the connector for the rear motor was taken from the original board that was inside the truck.
The shape of the board was made to exactly reproduce the shape of the original board. This way I was able to reuse the existing mounting posts and attach to the 9V battery posts.
The circuit is fairly self-explanatory, I hope. The NPN transistor hooked up to the Rear_Direction output is acting as a simple inverter.
Step 8: Taking apart the car and reverse engineering motor control
The F-150 was very easy to take apart. Everything is held with screws and all important parts are removable.
Make sure you keep the original board after you take it out, since it can be very useful for testing when you are debugging or reverse engineering the controls. You can also take the connectors from the original board and put them onto yours.
Turns out that the rear motor could be successfully throttled with a simple PWM technique. I had to write a small PWM generator utility which was very useful for figuring out how to control the motor and the servos. You can download the utility from here:
Step 9: Get your servos working
Now that you have the rear motor working, time to play with the servos.
You can use the following test script https://github.com/vace117/CreeperPiController/blo…, just make sure that your servos are hooked up to the correct GPIO pins. Look at the source code to figure out which.
The video shows me activating the servos from my phone, b/c I am SSHed into the RPi from it.
For more detail: WebRTC Creeper Drone – Browser Controlled RC Car