A simple set of interfaces for communicating with your Wi-Fi enabled quadcopter.
QuadKit powers SCARAB, an RC controller for iOS. Read about the making of QuadKit: Building a Quadcopter Controller for iOS and Open-Sourcing the Internals
Add this to your Cartfile:
github "gabrieloc/QuadKit"
To test the examples, make sure Carthage is installed, then run:
carthage update
Ensure any project using this framework includes QuadKit.framework
and SwiftSocket.framework
as embedded binaries.
To connect to your quadcopter, create an instance of QuadClient
and call -connect:
. Ensure that your device has been connected to the Wi-Fi network created by your quadcopter, before attempting to connect. Once a connection has been established, the client expects to be passed an InputState
object via -updateInput:
, in response to user interaction.
let client = QuadClient()
let inputState = InputState()
let thrustControl = UIControl()
func connectClient() {
if let error = client.connect() {
// Error connecting
}
thrustControl.enabled = true
}
func thrustControlTouched(_ thrustControl: UIControl) {
inputState.thrust = thrustControl.selected ? 1.0 : 0.0
client.updateInput(with inputState)
}
iOS and macOS samples can be found inside the Examples/
directory.
While the format for input data appears to be generic across models (needs to be verified), it's possible that handshake data isn't. For this reason, BindingSupport
defines a protocol QuadcopterModel
, which individual models can use for providing this data.
Handshake data can be found by running a tool like tcpdump
or Wireshark
to get a packet trace, and collecting the first few packets your device sends your quadcopter in the software provided by it's manufacturer.
- Connect your device via USB and create a RVI:
$ rvictl -s (DEVICE UDID)
- Ensure the remote interface was created by running:
$ ifconfig -l
and verifyingrvi0
exists - Turn on your quadcopter and join it's Wi-Fi network
- In a tool like Wireshark, begin capturing
rvi0
- Open the software provided by your quadcopter's manufacturer and access the input controls
- Stop capturing and find what looks like identification data. It should consistently look the same every time you try to connect the app, and will appear before you begin receiving any form of input or video data
- Create a new class in
QuadKit
representing your quadcopter model, and have it adoptQuadcopterModel
- In your class' implementation of
-identification
, return the data your recorded in the form of byte arrays
Apple provides step by step instructions for creating using various network debugging tools: Technical Q&A QA1176: Getting a Packet Trace.
For more information on the protocol, refer to Jim Hung's Hubsan X4 H107L Quadcopter Control Protocol Specification, or his excellent reverse engineering series, Reverse Engineering a Hubsan X4 Quadcopter.