Skip to content

Commit

Permalink
Merge pull request hybridgroup#136 from hybridgroup/godocs-ardrone
Browse files Browse the repository at this point in the history
Adding ardrone go docs
  • Loading branch information
zankich committed Oct 27, 2014
2 parents 1f223ee + 15055f1 commit 8310353
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 16 deletions.
4 changes: 4 additions & 0 deletions platforms/ardrone/ardrone_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/hybridgroup/gobot"
)

// drone defines expected drone behaviour
type drone interface {
Takeoff() bool
Land()
Expand All @@ -25,6 +26,7 @@ type ArdroneAdaptor struct {
connect func(*ArdroneAdaptor)
}

// NewArdroneAdaptor creates a new ardrone and connects with default configuration
func NewArdroneAdaptor(name string) *ArdroneAdaptor {
return &ArdroneAdaptor{
Adaptor: *gobot.NewAdaptor(
Expand All @@ -41,11 +43,13 @@ func NewArdroneAdaptor(name string) *ArdroneAdaptor {
}
}

// Connect returns true when connection to ardrone is established correclty
func (a *ArdroneAdaptor) Connect() bool {
a.connect(a)
return true
}

// Finalize returns true when connection is finalized correctly
func (a *ArdroneAdaptor) Finalize() bool {
return true
}
62 changes: 46 additions & 16 deletions platforms/ardrone/ardrone_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ type ArdroneDriver struct {
gobot.Driver
}

// NewArdroneDriver creates an ArdroneDriver with specified name.
//
// It add the following events:
// 'flying' - Sent when the device has taken off.
func NewArdroneDriver(adaptor *ArdroneAdaptor, name string) *ArdroneDriver {
d := &ArdroneDriver{
Driver: *gobot.NewDriver(
Expand All @@ -19,58 +23,84 @@ func NewArdroneDriver(adaptor *ArdroneAdaptor, name string) *ArdroneDriver {
d.AddEvent("flying")
return d
}

// adaptor returns ardrone adaptor
func (a *ArdroneDriver) adaptor() *ArdroneAdaptor {
return a.Adaptor().(*ArdroneAdaptor)
}

// Start returns true if driver is started succesfully
func (a *ArdroneDriver) Start() bool {
return true
}

// Halt returns true if driver is halted succesfully
func (a *ArdroneDriver) Halt() bool {
return true
}

// TakeOff makes the drone start flying
// and publishes `flying` event
func (a *ArdroneDriver) TakeOff() {
gobot.Publish(a.Event("flying"), a.adaptor().drone.Takeoff())
}

// Land makes the drone stop flying
func (a *ArdroneDriver) Land() {
a.adaptor().drone.Land()
}

func (a *ArdroneDriver) Up(n float64) {
a.adaptor().drone.Up(n)
// Up makes the drone gain altitude.
// speed can be a value from `0.0` to `1.0`.
func (a *ArdroneDriver) Up(speed float64) {
a.adaptor().drone.Up(speed)
}

func (a *ArdroneDriver) Down(n float64) {
a.adaptor().drone.Down(n)
// Down makes the drone reduce altitude.
// speed can be a value from `0.0` to `1.0`.
func (a *ArdroneDriver) Down(speed float64) {
a.adaptor().drone.Down(speed)
}

func (a *ArdroneDriver) Left(n float64) {
a.adaptor().drone.Left(n)
// Left causes the drone to bank to the left, controls the roll, which is
// a horizontal movement using the camera as a reference point.
// speed can be a value from `0.0` to `1.0`.
func (a *ArdroneDriver) Left(speed float64) {
a.adaptor().drone.Left(speed)
}

func (a *ArdroneDriver) Right(n float64) {
a.adaptor().drone.Right(n)
// Right causes the drone to bank to the right, controls the roll, which is
// a horizontal movement using the camera as a reference point.
// speed can be a value from `0.0` to `1.0`.
func (a *ArdroneDriver) Right(speed float64) {
a.adaptor().drone.Right(speed)
}

func (a *ArdroneDriver) Forward(n float64) {
a.adaptor().drone.Forward(n)
// Forward causes the drone go forward, controls the pitch.
// speed can be a value from `0.0` to `1.0`.
func (a *ArdroneDriver) Forward(speed float64) {
a.adaptor().drone.Forward(speed)
}

func (a *ArdroneDriver) Backward(n float64) {
a.adaptor().drone.Backward(n)
// Backward causes the drone go forward, controls the pitch.
// speed can be a value from `0.0` to `1.0`.
func (a *ArdroneDriver) Backward(speed float64) {
a.adaptor().drone.Backward(speed)
}

func (a *ArdroneDriver) Clockwise(n float64) {
a.adaptor().drone.Clockwise(n)
// Clockwise causes the drone to spin in clockwise direction
// speed can be a value from `0.0` to `1.0`.
func (a *ArdroneDriver) Clockwise(speed float64) {
a.adaptor().drone.Clockwise(speed)
}

func (a *ArdroneDriver) CounterClockwise(n float64) {
a.adaptor().drone.Counterclockwise(n)
// CounterClockwise the drone to spin in counter clockwise direction
// speed can be a value from `0.0` to `1.0`.
func (a *ArdroneDriver) CounterClockwise(speed float64) {
a.adaptor().drone.Counterclockwise(speed)
}

// Hover makes the drone to hover in place.
func (a *ArdroneDriver) Hover() {
a.adaptor().drone.Hover()
}
47 changes: 47 additions & 0 deletions platforms/ardrone/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
This package provides the Gobot adaptor and driver for the [Parrot Ardrone](http://ardrone2.parrot.com).
Installing:
go get github.com/hybridgroup/gobot && go install github.com/hybridgroup/gobot/platforms/ardrone
Example:
package main
import (
"time"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/ardrone"
)
func main() {
gbot := gobot.NewGobot()
ardroneAdaptor := ardrone.NewArdroneAdaptor("Drone")
drone := ardrone.NewArdroneDriver(ardroneAdaptor, "Drone")
work := func() {
drone.TakeOff()
gobot.On(drone.Event("flying"), func(data interface{}) {
gobot.After(3*time.Second, func() {
drone.Land()
})
})
}
robot := gobot.NewRobot("drone",
[]gobot.Connection{ardroneAdaptor},
[]gobot.Device{drone},
work,
)
gbot.AddRobot(robot)
gbot.Start()
}
For more information refer to the ardrone README:
https://github.com/hybridgroup/gobot/tree/master/platforms/ardrone
*/
package ardrone

0 comments on commit 8310353

Please sign in to comment.