Skip to content

Commit

Permalink
Merge pull request hybridgroup#550 from cbwang2016/patch-3
Browse files Browse the repository at this point in the history
slow/fast mode switch function for DJI Tello
  • Loading branch information
deadprogram authored May 21, 2018
2 parents 68fef4e + 244d26c commit ae755c3
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions platforms/dji/tello/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ type Driver struct {
respPort string
cmdMutex sync.Mutex
seq int16
rx, ry, lx, ly, throttle float32
rx, ry, lx, ly float32
throttle int
bouncing bool
gobot.Eventer
}
Expand Down Expand Up @@ -364,6 +365,24 @@ func (d *Driver) SetVideoEncoderRate(rate VideoBitRate) (err error) {
return
}

// SetFastMode sets the drone throttle to 1.
func (d *Driver) SetFastMode() error {
d.cmdMutex.Lock()
defer d.cmdMutex.Unlock()

d.throttle = 1
return nil
}

// SetSlowMode sets the drone throttle to 0.
func (d *Driver) SetSlowMode() error {
d.cmdMutex.Lock()
defer d.cmdMutex.Unlock()

d.throttle = 0
return nil
}

// Rate queries the current video bit rate.
func (d *Driver) Rate() (err error) {
buf, _ := d.createPacket(videoRateQuery, 0x48, 0)
Expand Down Expand Up @@ -628,7 +647,7 @@ func (d *Driver) SendStickCommand() (err error) {
axis4 := int16(660.0*d.lx + 1024.0)

// speed control
axis5 := int16(660.0*d.throttle + 1024.0)
axis5 := int16(d.throttle)

packedAxis := int64(axis1)&0x7FF | int64(axis2&0x7FF)<<11 | 0x7FF&int64(axis3)<<22 | 0x7FF&int64(axis4)<<33 | int64(axis5)<<44
binary.Write(buf, binary.LittleEndian, byte(0xFF&packedAxis))
Expand Down

0 comments on commit ae755c3

Please sign in to comment.