2015-07-22 11:03:27 +08:00
|
|
|
package bebop
|
|
|
|
|
|
|
|
import (
|
2016-12-08 20:24:03 +08:00
|
|
|
"gobot.io/x/gobot"
|
2015-07-22 11:03:27 +08:00
|
|
|
)
|
|
|
|
|
2016-09-01 18:17:43 +08:00
|
|
|
const (
|
|
|
|
// Flying event
|
|
|
|
Flying = "flying"
|
|
|
|
)
|
|
|
|
|
2016-09-25 22:05:24 +08:00
|
|
|
// Driver is gobot.Driver representation for the Bebop
|
|
|
|
type Driver struct {
|
2015-07-22 11:03:27 +08:00
|
|
|
name string
|
|
|
|
connection gobot.Connection
|
|
|
|
gobot.Eventer
|
|
|
|
}
|
|
|
|
|
2016-09-25 22:05:24 +08:00
|
|
|
// NewDriver creates an Bebop Driver.
|
|
|
|
func NewDriver(connection *Adaptor) *Driver {
|
|
|
|
d := &Driver{
|
2017-02-02 23:35:26 +08:00
|
|
|
name: gobot.DefaultName("Bebop"),
|
2015-07-22 11:03:27 +08:00
|
|
|
connection: connection,
|
|
|
|
Eventer: gobot.NewEventer(),
|
|
|
|
}
|
2016-09-01 18:17:43 +08:00
|
|
|
d.AddEvent(Flying)
|
2015-07-22 11:03:27 +08:00
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
2016-09-25 22:05:24 +08:00
|
|
|
// Name returns the Bebop Drivers Name
|
|
|
|
func (a *Driver) Name() string { return a.name }
|
2015-07-22 11:03:27 +08:00
|
|
|
|
2016-09-25 22:05:24 +08:00
|
|
|
// SetName sets the Bebop Drivers Name
|
|
|
|
func (a *Driver) SetName(n string) { a.name = n }
|
|
|
|
|
|
|
|
// Connection returns the Bebop Drivers Connection
|
|
|
|
func (a *Driver) Connection() gobot.Connection { return a.connection }
|
2015-07-22 11:03:27 +08:00
|
|
|
|
|
|
|
// adaptor returns ardrone adaptor
|
2016-09-25 22:05:24 +08:00
|
|
|
func (a *Driver) adaptor() *Adaptor {
|
|
|
|
return a.Connection().(*Adaptor)
|
2015-07-22 11:03:27 +08:00
|
|
|
}
|
|
|
|
|
2016-09-25 22:05:24 +08:00
|
|
|
// Start starts the Bebop Driver
|
2016-11-08 00:35:03 +08:00
|
|
|
func (a *Driver) Start() (err error) {
|
2015-07-22 11:03:27 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-09-25 22:05:24 +08:00
|
|
|
// Halt halts the Bebop Driver
|
2016-11-08 00:35:03 +08:00
|
|
|
func (a *Driver) Halt() (err error) {
|
2015-07-22 11:03:27 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// TakeOff makes the drone start flying
|
2016-09-25 22:05:24 +08:00
|
|
|
func (a *Driver) TakeOff() {
|
2016-08-31 02:24:47 +08:00
|
|
|
a.Publish(a.Event("flying"), a.adaptor().drone.TakeOff())
|
2015-07-22 11:03:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Land causes the drone to land
|
2016-09-25 22:05:24 +08:00
|
|
|
func (a *Driver) Land() {
|
2015-07-22 11:03:27 +08:00
|
|
|
a.adaptor().drone.Land()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Up makes the drone gain altitude.
|
|
|
|
// speed can be a value from `0` to `100`.
|
2016-09-25 22:05:24 +08:00
|
|
|
func (a *Driver) Up(speed int) {
|
2015-07-22 11:03:27 +08:00
|
|
|
a.adaptor().drone.Up(speed)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Down makes the drone reduce altitude.
|
|
|
|
// speed can be a value from `0` to `100`.
|
2016-09-25 22:05:24 +08:00
|
|
|
func (a *Driver) Down(speed int) {
|
2015-07-22 11:03:27 +08:00
|
|
|
a.adaptor().drone.Down(speed)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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` to `100`.
|
2016-09-25 22:05:24 +08:00
|
|
|
func (a *Driver) Left(speed int) {
|
2015-07-22 11:03:27 +08:00
|
|
|
a.adaptor().drone.Left(speed)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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` to `100`.
|
2016-09-25 22:05:24 +08:00
|
|
|
func (a *Driver) Right(speed int) {
|
2015-07-22 11:03:27 +08:00
|
|
|
a.adaptor().drone.Right(speed)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Forward causes the drone go forward, controls the pitch.
|
|
|
|
// speed can be a value from `0` to `100`.
|
2016-09-25 22:05:24 +08:00
|
|
|
func (a *Driver) Forward(speed int) {
|
2015-07-22 11:03:27 +08:00
|
|
|
a.adaptor().drone.Forward(speed)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Backward causes the drone go forward, controls the pitch.
|
|
|
|
// speed can be a value from `0` to `100`.
|
2016-09-25 22:05:24 +08:00
|
|
|
func (a *Driver) Backward(speed int) {
|
2015-07-22 11:03:27 +08:00
|
|
|
a.adaptor().drone.Backward(speed)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clockwise causes the drone to spin in clockwise direction
|
|
|
|
// speed can be a value from `0` to `100`.
|
2016-09-25 22:05:24 +08:00
|
|
|
func (a *Driver) Clockwise(speed int) {
|
2015-07-22 11:03:27 +08:00
|
|
|
a.adaptor().drone.Clockwise(speed)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CounterClockwise the drone to spin in counter clockwise direction
|
|
|
|
// speed can be a value from `0` to `100`.
|
2016-09-25 22:05:24 +08:00
|
|
|
func (a *Driver) CounterClockwise(speed int) {
|
2015-07-22 11:03:27 +08:00
|
|
|
a.adaptor().drone.CounterClockwise(speed)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop makes the drone to hover in place.
|
2016-09-25 22:05:24 +08:00
|
|
|
func (a *Driver) Stop() {
|
2015-07-22 11:03:27 +08:00
|
|
|
a.adaptor().drone.Stop()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Video returns a channel which raw video frames will be broadcast on
|
2016-09-25 22:05:24 +08:00
|
|
|
func (a *Driver) Video() chan []byte {
|
2015-07-22 11:03:27 +08:00
|
|
|
return a.adaptor().drone.Video()
|
|
|
|
}
|
2015-07-24 00:03:46 +08:00
|
|
|
|
|
|
|
// StartRecording starts the recording video to the drones interal storage
|
2016-09-25 22:05:24 +08:00
|
|
|
func (a *Driver) StartRecording() error {
|
2015-07-24 00:03:46 +08:00
|
|
|
return a.adaptor().drone.StartRecording()
|
|
|
|
}
|
|
|
|
|
|
|
|
// StopRecording stops a previously started recording
|
2016-09-25 22:05:24 +08:00
|
|
|
func (a *Driver) StopRecording() error {
|
2015-07-24 00:03:46 +08:00
|
|
|
return a.adaptor().drone.StopRecording()
|
|
|
|
}
|
2015-10-05 14:06:26 +08:00
|
|
|
|
|
|
|
// HullProtection tells the drone if the hull/prop protectors are attached. This is needed to adjust flight characteristics of the Bebop.
|
2016-09-25 22:05:24 +08:00
|
|
|
func (a *Driver) HullProtection(protect bool) error {
|
2015-10-05 14:06:26 +08:00
|
|
|
return a.adaptor().drone.HullProtection(protect)
|
|
|
|
}
|
2015-10-25 07:45:53 +08:00
|
|
|
|
|
|
|
// Outdoor tells the drone if flying Outdoor or not. This is needed to adjust flight characteristics of the Bebop.
|
2016-09-25 22:05:24 +08:00
|
|
|
func (a *Driver) Outdoor(outdoor bool) error {
|
2015-10-25 07:45:53 +08:00
|
|
|
return a.adaptor().drone.Outdoor(outdoor)
|
|
|
|
}
|
2016-12-27 01:37:55 +08:00
|
|
|
|
|
|
|
// VideoEnable tells the drone to start/stop streaming video
|
|
|
|
func (a *Driver) VideoEnable(enable bool) error {
|
|
|
|
return a.adaptor().drone.VideoEnable(enable)
|
|
|
|
}
|
|
|
|
|
|
|
|
// VideoStreamMode tells the drone what mode to use for streaming video
|
|
|
|
func (a *Driver) VideoStreamMode(mode int8) error {
|
|
|
|
return a.adaptor().drone.VideoStreamMode(mode)
|
|
|
|
}
|