2014-04-26 18:11:51 +08:00
|
|
|
package ardrone
|
|
|
|
|
|
|
|
import (
|
2014-04-29 02:23:12 +08:00
|
|
|
client "github.com/hybridgroup/go-ardrone/client"
|
2014-04-26 18:11:51 +08:00
|
|
|
)
|
|
|
|
|
2014-10-16 05:43:38 +08:00
|
|
|
// drone defines expected drone behaviour
|
2014-06-15 04:55:12 +08:00
|
|
|
type drone interface {
|
|
|
|
Takeoff() bool
|
|
|
|
Land()
|
|
|
|
Up(n float64)
|
|
|
|
Down(n float64)
|
|
|
|
Left(n float64)
|
|
|
|
Right(n float64)
|
|
|
|
Forward(n float64)
|
|
|
|
Backward(n float64)
|
|
|
|
Clockwise(n float64)
|
|
|
|
Counterclockwise(n float64)
|
|
|
|
Hover()
|
|
|
|
}
|
2014-04-26 18:11:51 +08:00
|
|
|
|
2014-12-31 22:34:36 +08:00
|
|
|
// ArdroneAdaptor is gobot.Adaptor representation for the Ardrone
|
2014-04-26 18:11:51 +08:00
|
|
|
type ArdroneAdaptor struct {
|
2014-11-23 10:56:23 +08:00
|
|
|
name string
|
2014-04-29 02:23:12 +08:00
|
|
|
drone drone
|
2014-12-19 05:33:33 +08:00
|
|
|
config client.Config
|
|
|
|
connect func(*ArdroneAdaptor) (drone, error)
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|
|
|
|
|
2014-12-31 22:34:36 +08:00
|
|
|
// NewArdroneAdaptor returns a new ArdroneAdaptor and optionally accepts:
|
|
|
|
//
|
|
|
|
// string: The ardrones IP Address
|
|
|
|
//
|
2014-11-06 09:47:12 +08:00
|
|
|
func NewArdroneAdaptor(name string, v ...string) *ArdroneAdaptor {
|
2014-12-19 05:33:33 +08:00
|
|
|
a := &ArdroneAdaptor{
|
2014-11-23 10:56:23 +08:00
|
|
|
name: name,
|
2014-12-19 05:33:33 +08:00
|
|
|
connect: func(a *ArdroneAdaptor) (drone, error) {
|
|
|
|
return client.Connect(a.config)
|
2014-04-29 02:23:12 +08:00
|
|
|
},
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|
2014-12-19 05:33:33 +08:00
|
|
|
|
|
|
|
a.config = client.DefaultConfig()
|
|
|
|
if len(v) > 0 {
|
|
|
|
a.config.Ip = v[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
return a
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|
|
|
|
|
2014-12-31 22:34:36 +08:00
|
|
|
// Name returns the ArdroneAdaptors Name
|
2014-11-23 10:56:23 +08:00
|
|
|
func (a *ArdroneAdaptor) Name() string { return a.name }
|
|
|
|
|
2014-12-31 22:34:36 +08:00
|
|
|
// Connect establishes a connection to the ardrone
|
2014-11-20 15:21:19 +08:00
|
|
|
func (a *ArdroneAdaptor) Connect() (errs []error) {
|
2014-12-31 22:34:36 +08:00
|
|
|
d, err := a.connect(a)
|
|
|
|
if err != nil {
|
2014-11-20 15:21:19 +08:00
|
|
|
return []error{err}
|
|
|
|
}
|
2014-12-31 22:34:36 +08:00
|
|
|
a.drone = d
|
2014-11-20 15:21:19 +08:00
|
|
|
return
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|
|
|
|
|
2014-12-31 22:34:36 +08:00
|
|
|
// Finalize terminates the connection to the ardrone
|
2014-11-23 10:56:23 +08:00
|
|
|
func (a *ArdroneAdaptor) Finalize() (errs []error) { return }
|