Skip to content

Commit

Permalink
Refactor ardrone driver
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Jun 14, 2014
1 parent 8fa4ce8 commit daf6e32
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 52 deletions.
26 changes: 13 additions & 13 deletions platforms/ardrone/ardrone_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@ import (
"github.com/hybridgroup/gobot"
)

type drone interface{}
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()
}

type ArdroneAdaptor struct {
gobot.Adaptor
Expand Down Expand Up @@ -33,18 +45,6 @@ func (a *ArdroneAdaptor) Connect() bool {
return true
}

func (a *ArdroneAdaptor) Reconnect() bool {
return true
}

func (a *ArdroneAdaptor) Disconnect() bool {
return true
}

func (a *ArdroneAdaptor) Finalize() bool {
return true
}

func (a *ArdroneAdaptor) Drone() drone {
return a.drone
}
29 changes: 7 additions & 22 deletions platforms/ardrone/ardrone_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,20 @@ import (
"testing"
)

func initTestArdroneAdaptor() (*ArdroneAdaptor, *testDrone) {
d := &testDrone{}
func initTestArdroneAdaptor() *ArdroneAdaptor {
a := NewArdroneAdaptor("drone")
a.connect = func(a *ArdroneAdaptor) {
a.drone = d
a.drone = &testDrone{}
}
return a, d
return a
}

func TestFinalize(t *testing.T) {
a, _ := initTestArdroneAdaptor()
gobot.Expect(t, a.Finalize(), true)
}
func TestConnect(t *testing.T) {
a, _ := initTestArdroneAdaptor()
a := initTestArdroneAdaptor()
gobot.Expect(t, a.Connect(), true)
}
func TestDisconnect(t *testing.T) {
a, _ := initTestArdroneAdaptor()
gobot.Expect(t, a.Disconnect(), true)
}

func TestReconnect(t *testing.T) {
a, _ := initTestArdroneAdaptor()
gobot.Expect(t, a.Reconnect(), true)
}

func TestDrone(t *testing.T) {
a, d := initTestArdroneAdaptor()
a.Connect()
gobot.Expect(t, a.Drone(), d)
func TestFinalize(t *testing.T) {
a := initTestArdroneAdaptor()
gobot.Expect(t, a.Finalize(), true)
}
41 changes: 24 additions & 17 deletions platforms/ardrone/ardrone_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ import (

type ArdroneDriver struct {
gobot.Driver
Adaptor DroneInterface
Adaptor *ArdroneAdaptor
}

type DroneInterface interface {
Drone() drone
}

func NewArdroneDriver(adaptor DroneInterface, name string) *ArdroneDriver {
func NewArdroneDriver(adaptor *ArdroneAdaptor, name string) *ArdroneDriver {
return &ArdroneDriver{
Driver: gobot.Driver{
Name: name,
Expand All @@ -28,40 +24,51 @@ func NewArdroneDriver(adaptor DroneInterface, name string) *ArdroneDriver {
func (a *ArdroneDriver) Start() bool {
return true
}

func (a *ArdroneDriver) Halt() bool {
return true
}

func (a *ArdroneDriver) TakeOff() {
gobot.Publish(a.Events["Flying"], gobot.Call(a.Adaptor.Drone(), "Takeoff"))
gobot.Publish(a.Events["Flying"], a.Adaptor.drone.Takeoff())
}

func (a *ArdroneDriver) Land() {
gobot.Call(a.Adaptor.Drone(), "Land")
a.Adaptor.drone.Land()
}

func (a *ArdroneDriver) Up(n float64) {
gobot.Call(a.Adaptor.Drone(), "Up", n)
a.Adaptor.drone.Up(n)
}

func (a *ArdroneDriver) Down(n float64) {
gobot.Call(a.Adaptor.Drone(), "Down", n)
a.Adaptor.drone.Down(n)
}

func (a *ArdroneDriver) Left(n float64) {
gobot.Call(a.Adaptor.Drone(), "Left", n)
a.Adaptor.drone.Left(n)
}

func (a *ArdroneDriver) Right(n float64) {
gobot.Call(a.Adaptor.Drone(), "Right", n)
a.Adaptor.drone.Right(n)
}

func (a *ArdroneDriver) Forward(n float64) {
gobot.Call(a.Adaptor.Drone(), "Forward", n)
a.Adaptor.drone.Forward(n)
}

func (a *ArdroneDriver) Backward(n float64) {
gobot.Call(a.Adaptor.Drone(), "Backward", n)
a.Adaptor.drone.Backward(n)
}

func (a *ArdroneDriver) Clockwise(n float64) {
gobot.Call(a.Adaptor.Drone(), "Clockwise", n)
a.Adaptor.drone.Clockwise(n)
}

func (a *ArdroneDriver) CounterClockwise(n float64) {
gobot.Call(a.Adaptor.Drone(), "Counterclockwise", n)
a.Adaptor.drone.Counterclockwise(n)
}

func (a *ArdroneDriver) Hover() {
gobot.Call(a.Adaptor.Drone(), "Hover")
a.Adaptor.drone.Hover()
}

0 comments on commit daf6e32

Please sign in to comment.