gobot.io/x/gobot/v2@v2.1.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/v2" 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 func NewAdaptor(v ...string) *Adaptor { 35 a := &Adaptor{ 36 name: gobot.DefaultName("ARDrone"), 37 connect: func(a *Adaptor) (drone, error) { 38 return client.Connect(a.config) 39 }, 40 } 41 42 a.config = client.DefaultConfig() 43 if len(v) > 0 { 44 a.config.Ip = v[0] 45 } 46 47 return a 48 } 49 50 // Name returns the Adaptor Name 51 func (a *Adaptor) Name() string { return a.name } 52 53 // SetName sets the Adaptor Name 54 func (a *Adaptor) SetName(n string) { a.name = n } 55 56 // Connect establishes a connection to the ardrone 57 func (a *Adaptor) Connect() (err error) { 58 d, err := a.connect(a) 59 if err != nil { 60 return err 61 } 62 a.drone = d 63 return 64 } 65 66 // Finalize terminates the connection to the ardrone 67 func (a *Adaptor) Finalize() (err error) { return }