forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ardrone_adaptor.go
67 lines (57 loc) · 1.4 KB
/
ardrone_adaptor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package ardrone
import (
client "github.com/hybridgroup/go-ardrone/client"
"github.com/hybridgroup/gobot"
)
var _ gobot.Adaptor = (*ArdroneAdaptor)(nil)
// drone defines expected drone behaviour
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()
}
// ArdroneAdaptor is gobot.Adaptor representation for the Ardrone
type ArdroneAdaptor struct {
name string
drone drone
config client.Config
connect func(*ArdroneAdaptor) (drone, error)
}
// NewArdroneAdaptor returns a new ArdroneAdaptor and optionally accepts:
//
// string: The ardrones IP Address
//
func NewArdroneAdaptor(name string, v ...string) *ArdroneAdaptor {
a := &ArdroneAdaptor{
name: name,
connect: func(a *ArdroneAdaptor) (drone, error) {
return client.Connect(a.config)
},
}
a.config = client.DefaultConfig()
if len(v) > 0 {
a.config.Ip = v[0]
}
return a
}
// Name returns the ArdroneAdaptors Name
func (a *ArdroneAdaptor) Name() string { return a.name }
// Connect establishes a connection to the ardrone
func (a *ArdroneAdaptor) Connect() (errs []error) {
d, err := a.connect(a)
if err != nil {
return []error{err}
}
a.drone = d
return
}
// Finalize terminates the connection to the ardrone
func (a *ArdroneAdaptor) Finalize() (errs []error) { return }