Skip to content

Commit

Permalink
Bebop hull protection setting and beginning of test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
deadprogram committed Oct 5, 2015
1 parent 810e07b commit 360585a
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 2 deletions.
41 changes: 40 additions & 1 deletion platforms/bebop/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Bebop
# Bebop

The Bebop from Parrot is an inexpensive quadcopter that is controlled using WiFi. It includes a built-in front-facing HD video camera, as well as a second lower resolution bottom facing video camera.

Expand All @@ -7,6 +7,45 @@ The Bebop from Parrot is an inexpensive quadcopter that is controlled using WiFi
```
go get -d -u github.com/hybridgroup/gobot/... && go install github.com/hybridgroup/gobot/platforms/bebop
```

## How to Use
```go
package main

import (
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/bebop"
)

func main() {
gbot := gobot.NewGobot()

bebopAdaptor := bebop.NewBebopAdaptor("Drone")
drone := bebop.NewBebopDriver(bebopAdaptor, "Drone")

work := func() {
drone.HullProtection(true)
drone.TakeOff()
gobot.On(drone.Event("flying"), func(data interface{}) {
gobot.After(3*time.Second, func() {
drone.Land()
})
})
}

robot := gobot.NewRobot("drone",
[]gobot.Connection{bebopAdaptor},
[]gobot.Device{drone},
work,
)
gbot.AddRobot(robot)

gbot.Start()
}
```

## How to Connect

The Bebop is a WiFi device, so there is no additional work to establish a connection to a single drone. However, in order to connect to multiple drones, you need to perform some configuration steps on each drone via SSH.
1 change: 1 addition & 0 deletions platforms/bebop/bebop_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type drone interface {
Video() chan []byte
StartRecording() error
StopRecording() error
HullProtection(protect bool) error
}

// BebopAdaptor is gobot.Adaptor representation for the Bebop
Expand Down
33 changes: 33 additions & 0 deletions platforms/bebop/bebop_adaptor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package bebop

import (
"errors"
"testing"

"github.com/hybridgroup/gobot"
)

func initTestBebopAdaptor() *BebopAdaptor {
a := NewBebopAdaptor("bot")
a.connect = func(b *BebopAdaptor) (err error) {
b.drone = &testDrone{}
return nil
}
return a
}

func TestBebopAdaptorConnect(t *testing.T) {
a := initTestBebopAdaptor()
gobot.Assert(t, len(a.Connect()), 0)

a.connect = func(a *BebopAdaptor) (error) {
return errors.New("connection error")
}
gobot.Assert(t, a.Connect()[0], errors.New("connection error"))
}

func TestBebopAdaptorFinalize(t *testing.T) {
a := initTestBebopAdaptor()
a.Connect()
gobot.Assert(t, len(a.Finalize()), 0)
}
8 changes: 7 additions & 1 deletion platforms/bebop/bebop_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func NewBebopDriver(connection *BebopAdaptor, name string) *BebopDriver {
connection: connection,
Eventer: gobot.NewEventer(),
}
d.AddEvent("flying")
return d
}

Expand All @@ -46,7 +47,7 @@ func (a *BebopDriver) Halt() (errs []error) {

// TakeOff makes the drone start flying
func (a *BebopDriver) TakeOff() {
a.adaptor().drone.TakeOff()
gobot.Publish(a.Event("flying"), a.adaptor().drone.TakeOff())
}

// Land causes the drone to land
Expand Down Expand Up @@ -123,3 +124,8 @@ func (a *BebopDriver) StartRecording() error {
func (a *BebopDriver) StopRecording() error {
return a.adaptor().drone.StopRecording()
}

// HullProtection tells the drone if the hull/prop protectors are attached. This is needed to adjust flight characteristics of the Bebop.
func (a *BebopDriver) HullProtection(protect bool) error {
return a.adaptor().drone.HullProtection(protect)
}
52 changes: 52 additions & 0 deletions platforms/bebop/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,58 @@ func (b *Bebop) Video() chan []byte {
return b.video
}

func (b *Bebop) HullProtection(protect bool) error {
//
// ARCOMMANDS_Generator_GenerateARDrone3SpeedSettingsHullProtection
//

cmd := &bytes.Buffer{}

cmd.WriteByte(ARCOMMANDS_ID_PROJECT_ARDRONE3)
cmd.WriteByte(ARCOMMANDS_ID_ARDRONE3_CLASS_SPEEDSETTINGS)

tmp := &bytes.Buffer{}
binary.Write(tmp,
binary.LittleEndian,
uint16(ARCOMMANDS_ID_ARDRONE3_SPEEDSETTINGS_CMD_HULLPROTECTION),
)

cmd.Write(tmp.Bytes())

tmp = &bytes.Buffer{}
binary.Write(tmp, binary.LittleEndian, bool(protect))
cmd.Write(tmp.Bytes())

_, err := b.write(b.networkFrameGenerator(cmd, ARNETWORKAL_FRAME_TYPE_DATA, BD_NET_CD_NONACK_ID).Bytes())
return err
}

func (b *Bebop) Outdoor(outdoor bool) error {
//
// ARCOMMANDS_Generator_GenerateARDrone3SpeedSettingsOutdoor
//

cmd := &bytes.Buffer{}

cmd.WriteByte(ARCOMMANDS_ID_PROJECT_ARDRONE3)
cmd.WriteByte(ARCOMMANDS_ID_ARDRONE3_CLASS_SPEEDSETTINGS)

tmp := &bytes.Buffer{}
binary.Write(tmp,
binary.LittleEndian,
uint16(ARCOMMANDS_ID_ARDRONE3_SPEEDSETTINGS_CMD_OUTDOOR),
)

cmd.Write(tmp.Bytes())

tmp = &bytes.Buffer{}
binary.Write(tmp, binary.LittleEndian, bool(outdoor))
cmd.Write(tmp.Bytes())

_, err := b.write(b.networkFrameGenerator(cmd, ARNETWORKAL_FRAME_TYPE_DATA, BD_NET_CD_NONACK_ID).Bytes())
return err
}

func (b *Bebop) createARStreamACK(frame ARStreamFrame) *bytes.Buffer {
//
// ARSTREAM_NetworkHeaders_AckPacket_t;
Expand Down
5 changes: 5 additions & 0 deletions platforms/bebop/client/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,9 @@ const (
ARNETWORKAL_FRAME_TYPE_DATA_LOW_LATENCY byte = 3
ARNETWORKAL_FRAME_TYPE_DATA_WITH_ACK byte = 4
ARNETWORKAL_FRAME_TYPE_MAX byte = 5

ARCOMMANDS_ID_ARDRONE3_SPEEDSETTINGS_CMD_MAXVERTICALSPEED byte = 0
ARCOMMANDS_ID_ARDRONE3_SPEEDSETTINGS_CMD_MAXROTATIONSPEED byte = 1
ARCOMMANDS_ID_ARDRONE3_SPEEDSETTINGS_CMD_HULLPROTECTION byte = 2
ARCOMMANDS_ID_ARDRONE3_SPEEDSETTINGS_CMD_OUTDOOR byte = 3
)
17 changes: 17 additions & 0 deletions platforms/bebop/client/examples/takeoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,30 @@ import (

func main() {
bebop := client.New()

if err := bebop.Connect(); err != nil {
fmt.Println(err)
return
}

fmt.Println("hull")
bebop.HullProtection(true)
//fmt.Println("outdoor")
//bebop.Outdoor(false)

fmt.Println("takeoff")
if err := bebop.TakeOff(); err != nil {
fmt.Println(err)
fmt.Println("fail")
return
}
<-time.After(5 * time.Second)
fmt.Println("land")
if err := bebop.Land(); err != nil {
fmt.Println(err)
return
}

<-time.After(5 * time.Second)
fmt.Println("done")
}
21 changes: 21 additions & 0 deletions platforms/bebop/test_helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package bebop

type testDrone struct{}

//func (t testDrone) Close() {}
func (t testDrone) TakeOff() error { return nil }
func (t testDrone) Land() error { return nil }
func (t testDrone) Up(n int) error { return nil }
func (t testDrone) Down(n int) error { return nil }
func (t testDrone) Left(n int) error { return nil}
func (t testDrone) Right(n int) error { return nil }
func (t testDrone) Forward(n int) error { return nil }
func (t testDrone) Backward(n int) error { return nil }
func (t testDrone) Clockwise(n int) error { return nil }
func (t testDrone) CounterClockwise(n int) error { return nil }
func (t testDrone) Stop() error { return nil }
func (t testDrone) Connect() error { return nil }
func (t testDrone) Video() chan []byte { return nil }
func (t testDrone) StartRecording() error { return nil }
func (t testDrone) StopRecording() error { return nil }
func (t testDrone) HullProtection(protect bool) error { return nil }

0 comments on commit 360585a

Please sign in to comment.