gobot.io/x/gobot@v1.16.0/platforms/parrot/ardrone/ardrone_adaptor.go (about) 1 package ardrone 2 3 import ( 4 client "github.com/hybridgroup/go-ardrone/client" 5 "gobot.io/x/gobot" 6 ) 7 8 // drone defines expected drone behaviour 9 type drone interface { 10 Takeoff() bool 11 Land() 12 Up(n float64) 13 Down(n float64) 14 Left(n float64) 15 Right(n float64) 16 Forward(n float64) 17 Backward(n float64) 18 Clockwise(n float64) 19 Counterclockwise(n float64) 20 Hover() 21 } 22 23 // Adaptor is gobot.Adaptor representation for the Ardrone 24 type Adaptor struct { 25 name string 26 drone drone 27 config client.Config 28 connect func(*Adaptor) (drone, error) 29 } 30 31 // NewAdaptor returns a new ardrone.Adaptor and optionally accepts: 32 // 33 // string: The ardrones IP Address 34 // 35 func NewAdaptor(v ...string) *Adaptor { 36 a := &Adaptor{ 37 name: gobot.DefaultName("ARDrone"), 38 connect: func(a *Adaptor) (drone, error) { 39 return client.Connect(a.config) 40 }, 41 } 42 43 a.config = client.DefaultConfig() 44 if len(v) > 0 { 45 a.config.Ip = v[0] 46 } 47 48 return a 49 } 50 51 // Name returns the Adaptor Name 52 func (a *Adaptor) Name() string { return a.name } 53 54 // SetName sets the Adaptor Name 55 func (a *Adaptor) SetName(n string) { a.name = n } 56 57 // Connect establishes a connection to the ardrone 58 func (a *Adaptor) Connect() (err error) { 59 d, err := a.connect(a) 60 if err != nil { 61 return err 62 } 63 a.drone = d 64 return 65 } 66 67 // Finalize terminates the connection to the ardrone 68 func (a *Adaptor) Finalize() (err error) { return }