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