Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasVautherin committed Feb 8, 2019
1 parent 73779ad commit 14ce3b6
Showing 1 changed file with 53 additions and 50 deletions.
103 changes: 53 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,87 +1,90 @@
# Dronecode-SDK-Swift

## Use framework in iOS application
## Getting started in iOS

### Get framework using carthage
### Carthage

To use this framework, add the following to your `Cartfile`:
Add the following to your `Cartfile`:

```
github "Dronecode/DronecodeSDK-Swift" ~> 0.2.1
```shell
github "Dronecode/DronecodeSDK-Swift" ~> 0.3.0
```

And then get the framework using:
```

```shell
carthage bootstrap --platform ios
```

### First steps to use framework
### Start MAVLink connection

The steps below assume that your iOS device has a network connection to the drone, e.g. using WiFi.

By default, the backend will connect using MAVLink on UDP port 14540 which is running by default when PX4 is run in SITL (software in the loop simulation).
To change the connection port, check [this line in the backend](https://github.com/Dronecode/DronecodeSDK/blob/d4fb6ca56f8e4ce01252ed498835c500e477d2d2/backend/src/backend.cpp#L19). For now, the backend is limited to UDP even though the core supports UDP, TCP, and serial.
By default, the SDK will connect using MAVLink on UDP port 14540, which is running by default when PX4 is run in SITL (software in the loop simulation).
For now, the backend is limited to UDP even though the core supports UDP, TCP, and serial.

One way to start is to add a CoreManager to your iOS application:
```swift
import Dronecode_SDK_Swift

let drone = Drone()
drone.startMavlink.subscribe()
```
import Foundation
import Dronecode_SDK_Swift
import RxSwift

class CoreManager {
After that, you can start writing some code [as described below](#start-writing-code).

static let shared = CoreManager()
__For advanced users:__ note that `startMavlink` will run the SDK backend in a background thread on the iOS device. You could connect the SDK to another backend (say, running on a computer with IP `192.168.0.42` by omitting the second line above and running only: `let drone = Drone(address: "192.168.0.42", port: 50051)`.

let disposeBag = DisposeBag()
## Start writing code
After that, you can start using the SDK, for instance:

let core = Core()
let telemetry = Telemetry(address: "localhost", port: 50051)
let action = Action(address: "localhost", port: 50051)
let mission = Mission(address: "localhost", port: 50051)
let camera = Camera(address: "localhost", port: 50051)
```swift
drone.action.arm()
.andThen(drone.action.takeoff())
.subscribe()
```

private init() {}
or

lazy var startCompletable = createStartCompletable()
```swift
drone.telemetry.position()
.do(onNext: { next in print(next) })
.subscribe()
```

private func createStartCompletable() -> Observable<Never> {
let startCompletable = core.connect().asObservable().replay(1)
startCompletable.connect().disposed(by: disposeBag)
Learn more about RxSwift [here](https://github.com/ReactiveX/RxSwift), and have a look at our [examples](#examples).

return startCompletable.asObservable()
}
}
```
### Examples

Then, use the `CoreManager` in your view controller like this:
Check out the [examples](https://github.com/Dronecode/DronecodeSDK-Swift-Example) for more examples using this framework.

```
import Dronecode_SDK_Swift
import RxSwift
## Contribute

class MyViewController: UIViewController {
If you want to contribute, please check out: [CONTRIBUTING.md](https://github.com/Dronecode/DronecodeSDK-Swift/blob/master/CONTRIBUTING.md).

@IBOutlet weak var armButton: UIButton!
@IBOutlet weak var feedbackLabel: UILabel!
### Build the SDK

private let disposeBag = DisposeBag()
Most of the SDK is auto-generated from the proto files (see in _proto/protos_). Note that they come from a submodule (i.e. you may need to `$ git submodule update --init --recursive`).

@IBAction func armPressed(_ sender: Any) {
CoreManager.shared.action.arm()
.do(onError: { error in self.feedbackLabel.text = "Arming failed : \(error.localizedDescription)" },
onCompleted: { self.feedbackLabel.text = "Arming succeeded" })
.subscribe()
.disposed(by: disposeBag)
}
To generate the source code, run:

```shell
bash tools/generate_from_protos.bash
```

### Example of iOS application
After that, you can either build the code with SwiftPM using:

Check out the [iOS example application](https://github.com/Dronecode/DronecodeSDK-Swift-Example) for a complete example project using this framework.
```shell
swift build
```

## Develop for this framework
Or generate an iOS Xcode project with:

For instructions how to develop on the Swift wrappers and contribute, please check out:
[CONTRIBUTING.md](https://github.com/Dronecode/DronecodeSDK-Swift/blob/master/CONTRIBUTING.md).
```shell
xcodegen
```

This will create the `Dronecode-SDK-Swift.xcodeproj` project file from `project.yml`. If you don't have it already, install Xcodegen with:

```shell
brew install xcodegen
```

0 comments on commit 14ce3b6

Please sign in to comment.