2014-04-26 03:11:51 -07:00
|
|
|
package ardrone
|
|
|
|
|
|
|
|
import (
|
2014-04-28 11:23:12 -07:00
|
|
|
client "github.com/hybridgroup/go-ardrone/client"
|
2014-04-26 03:11:51 -07:00
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
)
|
|
|
|
|
2014-11-16 12:25:48 -08:00
|
|
|
var _ gobot.AdaptorInterface = (*ArdroneAdaptor)(nil)
|
|
|
|
|
2014-10-15 16:43:38 -05:00
|
|
|
// drone defines expected drone behaviour
|
2014-06-14 13:55:12 -07: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 03:11:51 -07:00
|
|
|
|
|
|
|
type ArdroneAdaptor struct {
|
|
|
|
gobot.Adaptor
|
2014-04-28 11:23:12 -07:00
|
|
|
drone drone
|
2014-11-16 13:46:23 -08:00
|
|
|
connect func(*ArdroneAdaptor) (err error)
|
2014-04-26 03:11:51 -07:00
|
|
|
}
|
|
|
|
|
2014-10-15 16:43:38 -05:00
|
|
|
// NewArdroneAdaptor creates a new ardrone and connects with default configuration
|
2014-11-05 17:47:12 -08:00
|
|
|
func NewArdroneAdaptor(name string, v ...string) *ArdroneAdaptor {
|
2014-04-28 11:23:12 -07:00
|
|
|
return &ArdroneAdaptor{
|
2014-07-07 16:03:14 -07:00
|
|
|
Adaptor: *gobot.NewAdaptor(
|
|
|
|
name,
|
|
|
|
"ArdroneAdaptor",
|
|
|
|
),
|
2014-11-16 13:46:23 -08:00
|
|
|
connect: func(a *ArdroneAdaptor) (err error) {
|
2014-11-05 17:47:12 -08:00
|
|
|
config := client.DefaultConfig()
|
|
|
|
if len(v) > 0 {
|
|
|
|
config.Ip = v[0]
|
|
|
|
}
|
|
|
|
d, err := client.Connect(config)
|
2014-04-28 11:23:12 -07:00
|
|
|
if err != nil {
|
2014-11-16 13:46:23 -08:00
|
|
|
return
|
2014-04-28 11:23:12 -07:00
|
|
|
}
|
|
|
|
a.drone = d
|
2014-11-16 13:46:23 -08:00
|
|
|
return
|
2014-04-28 11:23:12 -07:00
|
|
|
},
|
2014-04-26 03:11:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-15 16:43:38 -05:00
|
|
|
// Connect returns true when connection to ardrone is established correclty
|
2014-11-19 23:21:19 -08:00
|
|
|
func (a *ArdroneAdaptor) Connect() (errs []error) {
|
|
|
|
if err := a.connect(a); err != nil {
|
|
|
|
return []error{err}
|
|
|
|
}
|
|
|
|
return
|
2014-04-26 03:11:51 -07:00
|
|
|
}
|
|
|
|
|
2014-10-15 16:43:38 -05:00
|
|
|
// Finalize returns true when connection is finalized correctly
|
2014-11-19 23:21:19 -08:00
|
|
|
func (a *ArdroneAdaptor) Finalize() (errs []error) {
|
|
|
|
return
|
2014-04-26 03:11:51 -07:00
|
|
|
}
|