2016-07-04 17:00:36 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2016-07-04 20:10:30 +02:00
|
|
|
"fmt"
|
2016-07-04 20:31:15 +02:00
|
|
|
"time"
|
2016-07-04 17:00:36 +02:00
|
|
|
|
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/ble"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
gbot := gobot.NewGobot()
|
|
|
|
|
|
|
|
bleAdaptor := ble.NewBLEAdaptor("ble", os.Args[1])
|
|
|
|
drone := ble.NewBLEMinidroneDriver(bleAdaptor, "drone")
|
|
|
|
|
|
|
|
work := func() {
|
2016-07-04 19:46:42 +02:00
|
|
|
drone.Init()
|
2016-07-04 22:53:54 +02:00
|
|
|
drone.StartPcmd()
|
|
|
|
|
2016-07-04 20:10:30 +02:00
|
|
|
gobot.On(drone.Event("battery"), func(data interface{}) {
|
2016-07-04 20:31:15 +02:00
|
|
|
fmt.Printf("battery: %d\n", data)
|
2016-07-04 20:10:30 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
gobot.On(drone.Event("status"), func(data interface{}) {
|
2016-07-04 20:31:15 +02:00
|
|
|
fmt.Printf("status: %d\n", data)
|
2016-07-04 20:10:30 +02:00
|
|
|
})
|
2016-07-04 20:31:15 +02:00
|
|
|
|
2016-07-04 22:23:59 +02:00
|
|
|
gobot.On(drone.Event("flying"), func(data interface{}) {
|
|
|
|
fmt.Println("flying!")
|
|
|
|
gobot.After(5*time.Second, func() {
|
|
|
|
fmt.Println("landing...")
|
|
|
|
drone.Land()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
gobot.On(drone.Event("landed"), func(data interface{}) {
|
|
|
|
fmt.Println("landed.")
|
2016-07-04 20:31:15 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
drone.TakeOff()
|
2016-07-04 17:00:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("bleBot",
|
|
|
|
[]gobot.Connection{bleAdaptor},
|
|
|
|
[]gobot.Device{drone},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
gbot.AddRobot(robot)
|
|
|
|
|
|
|
|
gbot.Start()
|
|
|
|
}
|