1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-29 13:49:14 +08:00
hybridgroup.gobot/platforms/ardrone/ardrone_driver.go

109 lines
2.8 KiB
Go
Raw Normal View History

2014-04-28 11:23:12 -07:00
package ardrone
import (
"github.com/hybridgroup/gobot"
)
var _ gobot.DriverInterface = (*ArdroneDriver)(nil)
type ArdroneDriver struct {
gobot.Driver
}
2014-10-15 16:43:38 -05:00
// NewArdroneDriver creates an ArdroneDriver with specified name.
//
// It add the following events:
// 'flying' - Sent when the device has taken off.
2014-06-14 13:55:12 -07:00
func NewArdroneDriver(adaptor *ArdroneAdaptor, name string) *ArdroneDriver {
2014-07-07 16:03:14 -07:00
d := &ArdroneDriver{
Driver: *gobot.NewDriver(
name,
"ArdroneDriver",
adaptor,
),
2014-04-28 11:23:12 -07:00
}
2014-07-09 18:32:27 -07:00
d.AddEvent("flying")
2014-07-07 16:03:14 -07:00
return d
}
2014-10-15 16:43:38 -05:00
// adaptor returns ardrone adaptor
func (a *ArdroneDriver) adaptor() *ArdroneAdaptor {
2014-07-09 18:32:27 -07:00
return a.Adaptor().(*ArdroneAdaptor)
}
2014-10-15 16:43:38 -05:00
// Start returns true if driver is started succesfully
func (a *ArdroneDriver) Start() (errs []error) {
return
}
2014-06-14 13:55:12 -07:00
2014-10-15 16:43:38 -05:00
// Halt returns true if driver is halted succesfully
func (a *ArdroneDriver) Halt() (errs []error) {
return
}
2014-10-15 16:43:38 -05:00
// TakeOff makes the drone start flying
// and publishes `flying` event
2014-06-10 15:16:11 -07:00
func (a *ArdroneDriver) TakeOff() {
2014-07-07 16:03:14 -07:00
gobot.Publish(a.Event("flying"), a.adaptor().drone.Takeoff())
}
2014-06-14 13:55:12 -07:00
2014-10-15 16:43:38 -05:00
// Land makes the drone stop flying
2014-06-10 15:16:11 -07:00
func (a *ArdroneDriver) Land() {
a.adaptor().drone.Land()
}
2014-06-14 13:55:12 -07:00
2014-10-15 16:43:38 -05:00
// 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)
}
2014-06-14 13:55:12 -07:00
2014-10-15 16:43:38 -05:00
// 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)
}
2014-06-14 13:55:12 -07:00
2014-10-15 16:43:38 -05:00
// 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)
}
2014-06-14 13:55:12 -07:00
2014-10-15 16:43:38 -05:00
// 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)
}
2014-06-14 13:55:12 -07:00
2014-10-15 16:43:38 -05:00
// 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)
}
2014-06-14 13:55:12 -07:00
2014-10-15 16:43:38 -05:00
// 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)
}
2014-06-14 13:55:12 -07:00
2014-10-15 16:43:38 -05:00
// 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)
}
2014-06-14 13:55:12 -07:00
2014-10-15 16:43:38 -05:00
// 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)
}
2014-06-14 13:55:12 -07:00
2014-10-15 16:43:38 -05:00
// Hover makes the drone to hover in place.
2014-06-10 15:16:11 -07:00
func (a *ArdroneDriver) Hover() {
a.adaptor().drone.Hover()
}