51 lines
989 B
Go
51 lines
989 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/hybridgroup/gobot"
|
|
"github.com/hybridgroup/gobot/platforms/ble"
|
|
"github.com/hybridgroup/gobot/platforms/parrot/minidrone"
|
|
)
|
|
|
|
func main() {
|
|
bleAdaptor := ble.NewClientAdaptor(os.Args[1])
|
|
drone := minidrone.NewDriver(bleAdaptor)
|
|
|
|
work := func() {
|
|
drone.On(drone.Event("battery"), func(data interface{}) {
|
|
fmt.Printf("battery: %d\n", data)
|
|
})
|
|
|
|
drone.On(drone.Event("status"), func(data interface{}) {
|
|
fmt.Printf("status: %d\n", data)
|
|
})
|
|
|
|
drone.On(drone.Event("flying"), func(data interface{}) {
|
|
fmt.Println("flying!")
|
|
gobot.After(5*time.Second, func() {
|
|
fmt.Println("landing...")
|
|
drone.Land()
|
|
drone.Land()
|
|
})
|
|
})
|
|
|
|
drone.On(drone.Event("landed"), func(data interface{}) {
|
|
fmt.Println("landed.")
|
|
})
|
|
|
|
time.Sleep(1000 * time.Millisecond)
|
|
drone.TakeOff()
|
|
}
|
|
|
|
robot := gobot.NewRobot("minidrone",
|
|
[]gobot.Connection{bleAdaptor},
|
|
[]gobot.Device{drone},
|
|
work,
|
|
)
|
|
|
|
robot.Start()
|
|
}
|