gobot.io/x/gobot@v1.16.0/platforms/parrot/ardrone/ardrone_driver.go (about)

     1  package ardrone
     2  
     3  import (
     4  	"gobot.io/x/gobot"
     5  )
     6  
     7  const (
     8  	// Flying event
     9  	Flying = "flying"
    10  )
    11  
    12  // Driver is gobot.Driver representation for the Ardrone
    13  type Driver struct {
    14  	name       string
    15  	connection gobot.Connection
    16  	gobot.Eventer
    17  }
    18  
    19  // NewDriver creates an Driver for the ARDrone.
    20  //
    21  // It add the following events:
    22  //     'flying' - Sent when the device has taken off.
    23  func NewDriver(connection *Adaptor) *Driver {
    24  	d := &Driver{
    25  		name:       gobot.DefaultName("ARDrone"),
    26  		connection: connection,
    27  		Eventer:    gobot.NewEventer(),
    28  	}
    29  	d.AddEvent(Flying)
    30  	return d
    31  }
    32  
    33  // Name returns the Driver Name
    34  func (a *Driver) Name() string { return a.name }
    35  
    36  // SetName sets the Driver Name
    37  func (a *Driver) SetName(n string) { a.name = n }
    38  
    39  // Connection returns the Driver Connection
    40  func (a *Driver) Connection() gobot.Connection { return a.connection }
    41  
    42  // adaptor returns ardrone adaptor
    43  func (a *Driver) adaptor() *Adaptor {
    44  	return a.Connection().(*Adaptor)
    45  }
    46  
    47  // Start starts the Driver
    48  func (a *Driver) Start() (err error) {
    49  	return
    50  }
    51  
    52  // Halt halts the Driver
    53  func (a *Driver) Halt() (err error) {
    54  	return
    55  }
    56  
    57  // TakeOff makes the drone start flying, and publishes `flying` event
    58  func (a *Driver) TakeOff() {
    59  	a.Publish(a.Event("flying"), a.adaptor().drone.Takeoff())
    60  }
    61  
    62  // Land causes the drone to land
    63  func (a *Driver) Land() {
    64  	a.adaptor().drone.Land()
    65  }
    66  
    67  // Up makes the drone gain altitude.
    68  // speed can be a value from `0.0` to `1.0`.
    69  func (a *Driver) Up(speed float64) {
    70  	a.adaptor().drone.Up(speed)
    71  }
    72  
    73  // Down makes the drone reduce altitude.
    74  // speed can be a value from `0.0` to `1.0`.
    75  func (a *Driver) Down(speed float64) {
    76  	a.adaptor().drone.Down(speed)
    77  }
    78  
    79  // Left causes the drone to bank to the left, controls the roll, which is
    80  // a horizontal movement using the camera as a reference point.
    81  // speed can be a value from `0.0` to `1.0`.
    82  func (a *Driver) Left(speed float64) {
    83  	a.adaptor().drone.Left(speed)
    84  }
    85  
    86  // Right causes the drone to bank to the right, controls the roll, which is
    87  // a horizontal movement using the camera as a reference point.
    88  // speed can be a value from `0.0` to `1.0`.
    89  func (a *Driver) Right(speed float64) {
    90  	a.adaptor().drone.Right(speed)
    91  }
    92  
    93  // Forward causes the drone go forward, controls the pitch.
    94  // speed can be a value from `0.0` to `1.0`.
    95  func (a *Driver) Forward(speed float64) {
    96  	a.adaptor().drone.Forward(speed)
    97  }
    98  
    99  // Backward causes the drone go backward, controls the pitch.
   100  // speed can be a value from `0.0` to `1.0`.
   101  func (a *Driver) Backward(speed float64) {
   102  	a.adaptor().drone.Backward(speed)
   103  }
   104  
   105  // Clockwise causes the drone to spin in clockwise direction
   106  // speed can be a value from `0.0` to `1.0`.
   107  func (a *Driver) Clockwise(speed float64) {
   108  	a.adaptor().drone.Clockwise(speed)
   109  }
   110  
   111  // CounterClockwise the drone to spin in counter clockwise direction
   112  // speed can be a value from `0.0` to `1.0`.
   113  func (a *Driver) CounterClockwise(speed float64) {
   114  	a.adaptor().drone.Counterclockwise(speed)
   115  }
   116  
   117  // Hover makes the drone to hover in place.
   118  func (a *Driver) Hover() {
   119  	a.adaptor().drone.Hover()
   120  }