2016-12-07 01:51:14 +08:00
# Parrot Minidrone
2016-12-27 20:53:53 +08:00
The Parrot Minidrones are very inexpensive drones that are controlled using Bluetooth LE aka Bluetooth 4.0.
2016-12-07 01:51:14 +08:00
2016-12-27 20:53:53 +08:00
Models that are known to work with this package include:
- Parrot Rolling Spider
- Parrot Airborne Cargo Mars
- Parrot Airborne Cargo Travis
Models that should work now, but have not been tested by us:
- Parrot Airborne Night Swat
- Parrot Airborne Night Maclane
- Parrot Airborne Night Blaze
- Parrot HYDROFOIL Orak
- Parrot HYDROFOIL NewZ
Models that will require additional work for compatibility:
- Parrot Swing
- Parrot Mambo
2016-12-07 01:51:14 +08:00
## How to Install
```
2016-12-08 20:24:03 +08:00
go get -d -u gobot.io/x/gobot/... & & go install gobot.io/x/gobot/platforms/ble
2016-12-07 01:51:14 +08:00
```
## How to Use
```go
2016-12-20 02:06:39 +08:00
package main
import (
"fmt"
"os"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/platforms/ble"
"gobot.io/x/gobot/platforms/parrot/minidrone"
)
func main() {
bleAdaptor := ble.NewClientAdaptor(os.Args[1])
drone := minidrone.NewDriver(bleAdaptor)
work := func() {
2016-12-27 22:56:22 +08:00
drone.On(minidrone.Battery, func(data interface{}) {
2016-12-20 02:06:39 +08:00
fmt.Printf("battery: %d\n", data)
})
2016-12-27 22:56:22 +08:00
drone.On(minidrone.FlightStatus, func(data interface{}) {
fmt.Printf("flight status: %d\n", data)
2016-12-20 02:06:39 +08:00
})
2016-12-27 22:56:22 +08:00
drone.On(minidrone.Takeoff, func(data interface{}) {
fmt.Println("taking off...")
})
drone.On(minidrone.Hovering, func(data interface{}) {
fmt.Println("hovering!")
2016-12-20 02:06:39 +08:00
gobot.After(5*time.Second, func() {
drone.Land()
})
})
2016-12-27 22:56:22 +08:00
drone.On(minidrone.Landing, func(data interface{}) {
fmt.Println("landing...")
})
drone.On(minidrone.Landed, func(data interface{}) {
2016-12-20 02:06:39 +08:00
fmt.Println("landed.")
})
time.Sleep(1000 * time.Millisecond)
drone.TakeOff()
}
robot := gobot.NewRobot("minidrone",
[]gobot.Connection{bleAdaptor},
[]gobot.Device{drone},
work,
)
robot.Start()
}
2016-12-07 01:51:14 +08:00
```
## How to Connect
2016-12-27 20:53:53 +08:00
The Parrot Minidrones are Bluetooth LE devices.
2016-12-20 02:06:39 +08:00
You need to know the BLE ID of the Minidrone you want to connect to. The Gobot BLE client adaptor also lets you connect by friendly name, aka "RS_1234".
### OSX
To run any of the Gobot BLE code you must use the `GODEBUG=cgocheck=0` flag in order to get around some of the issues in the CGo-based implementation.
For example:
GODEBUG=cgocheck=0 go run examples/minidrone.go RS_1234
OSX uses its own Bluetooth ID system which is different from the IDs used on Linux. The code calls thru the XPC interfaces provided by OSX, so as a result does not need to run under sudo.
### Ubuntu
On Linux the BLE code will need to run as a root user account. The easiest way to accomplish this is probably to use `go build` to build your program, and then to run the requesting executable using `sudo` .
For example:
go build examples/minidrone.go
2016-12-27 23:23:25 +08:00
sudo ./minidrone RS_1234
2016-12-20 02:06:39 +08:00
### Windows
Hopefully coming soon...