gobot.io/x/gobot@v1.16.0/examples/ardrone.go (about)

     1  // +build example
     2  //
     3  // Do not build by default.
     4  
     5  package main
     6  
     7  import (
     8  	"time"
     9  
    10  	"gobot.io/x/gobot"
    11  	"gobot.io/x/gobot/platforms/parrot/ardrone"
    12  )
    13  
    14  func main() {
    15  	ardroneAdaptor := ardrone.NewAdaptor()
    16  	drone := ardrone.NewDriver(ardroneAdaptor)
    17  
    18  	work := func() {
    19  		drone.On(ardrone.Flying, func(data interface{}) {
    20  			gobot.After(3*time.Second, func() {
    21  				drone.Land()
    22  			})
    23  		})
    24  		drone.TakeOff()
    25  	}
    26  
    27  	robot := gobot.NewRobot("drone",
    28  		[]gobot.Connection{ardroneAdaptor},
    29  		[]gobot.Device{drone},
    30  		work,
    31  	)
    32  
    33  	robot.Start()
    34  }