2016-07-04 23:00:36 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-07-05 02:10:30 +08:00
|
|
|
"fmt"
|
2016-09-01 19:32:40 +08:00
|
|
|
"os"
|
2016-07-05 02:31:15 +08:00
|
|
|
"time"
|
2016-07-04 23:00:36 +08:00
|
|
|
|
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/ble"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-16 02:02:54 +08:00
|
|
|
gbot := gobot.NewMaster()
|
2016-07-04 23:00:36 +08:00
|
|
|
|
2016-10-03 22:58:43 +08:00
|
|
|
bleAdaptor := ble.NewClientAdaptor(os.Args[1])
|
|
|
|
drone := ble.NewMinidroneDriver(bleAdaptor)
|
2016-07-04 23:00:36 +08:00
|
|
|
|
|
|
|
work := func() {
|
2016-08-30 23:53:29 +08:00
|
|
|
drone.On(drone.Event("battery"), func(data interface{}) {
|
2016-07-05 02:31:15 +08:00
|
|
|
fmt.Printf("battery: %d\n", data)
|
2016-07-05 02:10:30 +08:00
|
|
|
})
|
|
|
|
|
2016-08-30 23:53:29 +08:00
|
|
|
drone.On(drone.Event("status"), func(data interface{}) {
|
2016-07-05 02:31:15 +08:00
|
|
|
fmt.Printf("status: %d\n", data)
|
2016-07-05 02:10:30 +08:00
|
|
|
})
|
2016-07-05 02:31:15 +08:00
|
|
|
|
2016-08-30 23:53:29 +08:00
|
|
|
drone.On(drone.Event("flying"), func(data interface{}) {
|
2016-07-05 04:23:59 +08:00
|
|
|
fmt.Println("flying!")
|
|
|
|
gobot.After(5*time.Second, func() {
|
|
|
|
fmt.Println("landing...")
|
|
|
|
drone.Land()
|
2016-07-05 05:54:44 +08:00
|
|
|
drone.Land()
|
2016-07-05 04:23:59 +08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-09-01 18:17:43 +08:00
|
|
|
drone.On(drone.Event("landed"), func(data interface{}) {
|
2016-07-05 04:23:59 +08:00
|
|
|
fmt.Println("landed.")
|
2016-07-05 02:31:15 +08:00
|
|
|
})
|
|
|
|
|
2016-07-05 05:54:44 +08:00
|
|
|
<-time.After(1000 * time.Millisecond)
|
2016-07-05 02:31:15 +08:00
|
|
|
drone.TakeOff()
|
2016-07-04 23:00:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("bleBot",
|
|
|
|
[]gobot.Connection{bleAdaptor},
|
|
|
|
[]gobot.Device{drone},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
gbot.AddRobot(robot)
|
|
|
|
|
|
|
|
gbot.Start()
|
|
|
|
}
|