gobot.io/x/gobot@v1.16.0/platforms/parrot/minidrone/README.md (about)

     1  # Parrot Minidrone
     2  
     3  The Parrot Minidrones are very inexpensive drones that are controlled using Bluetooth LE aka Bluetooth 4.0.
     4  
     5  Models that are known to work with this package include:
     6  
     7  	- Parrot Rolling Spider
     8  	- Parrot Airborne Cargo Mars
     9  	- Parrot Airborne Cargo Travis
    10  	- Parrot Mambo
    11  
    12  Models that should work now, but have not been tested by us:
    13  
    14  	- Parrot Airborne Night Swat
    15  	- Parrot Airborne Night Maclane
    16  	- Parrot Airborne Night Blaze
    17  	- Parrot HYDROFOIL Orak
    18  	- Parrot HYDROFOIL NewZ
    19  
    20  Models that will require additional work for compatibility:
    21  
    22  	- Parrot Swing
    23  
    24  ## How to Install
    25  
    26  ```
    27  go get -d -u gobot.io/x/gobot/...
    28  ```
    29  
    30  ## How to Use
    31  
    32  ```go
    33  package main
    34  
    35  import (
    36  	"fmt"
    37  	"os"
    38  	"time"
    39  
    40  	"gobot.io/x/gobot"
    41  	"gobot.io/x/gobot/platforms/ble"
    42  	"gobot.io/x/gobot/platforms/parrot/minidrone"
    43  )
    44  
    45  func main() {
    46  	bleAdaptor := ble.NewClientAdaptor(os.Args[1])
    47  	drone := minidrone.NewDriver(bleAdaptor)
    48  
    49  	work := func() {
    50  		drone.On(minidrone.Battery, func(data interface{}) {
    51  			fmt.Printf("battery: %d\n", data)
    52  		})
    53  
    54  		drone.On(minidrone.FlightStatus, func(data interface{}) {
    55  			fmt.Printf("flight status: %d\n", data)
    56  		})
    57  
    58  		drone.On(minidrone.Takeoff, func(data interface{}) {
    59  			fmt.Println("taking off...")
    60  		})
    61  
    62  		drone.On(minidrone.Hovering, func(data interface{}) {
    63  			fmt.Println("hovering!")
    64  			gobot.After(5*time.Second, func() {
    65  				drone.Land()
    66  			})
    67  		})
    68  
    69  		drone.On(minidrone.Landing, func(data interface{}) {
    70  			fmt.Println("landing...")
    71  		})
    72  
    73  		drone.On(minidrone.Landed, func(data interface{}) {
    74  			fmt.Println("landed.")
    75  		})
    76  
    77  		time.Sleep(1000 * time.Millisecond)
    78  		drone.TakeOff()
    79  	}
    80  
    81  	robot := gobot.NewRobot("minidrone",
    82  		[]gobot.Connection{bleAdaptor},
    83  		[]gobot.Device{drone},
    84  		work,
    85  	)
    86  
    87  	robot.Start()
    88  }
    89  ```
    90  
    91  ## How to Connect
    92  
    93  The Parrot Minidrones are Bluetooth LE devices.
    94  
    95  You need to know the BLE ID or name of the Minidrone you want to connect to. The Gobot BLE client adaptor also lets you connect by friendly name, aka "RS_1234".
    96  
    97  ### OSX
    98  
    99  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.
   100  
   101  If you connect by name, then you do not need to worry about the Bluetooth LE ID. However, if you want to connect by ID, OS X 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.
   102  
   103  For example:
   104  
   105      GODEBUG=cgocheck=0 go run examples/minidrone.go RS_1234
   106  
   107  ### Ubuntu
   108  
   109  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`.
   110  
   111  For example:
   112  
   113      go build examples/minidrone.go
   114      sudo ./minidrone RS_1234
   115  
   116  ### Windows
   117  
   118  Hopefully coming soon...