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

slow/fast mode switch function

This commit is contained in:
cbwang2016 2018-05-21 15:06:27 +08:00 committed by GitHub
parent 68fef4ebf9
commit 244d26c993
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -186,7 +186,8 @@ type Driver struct {
respPort string respPort string
cmdMutex sync.Mutex cmdMutex sync.Mutex
seq int16 seq int16
rx, ry, lx, ly, throttle float32 rx, ry, lx, ly float32
throttle int
bouncing bool bouncing bool
gobot.Eventer gobot.Eventer
} }
@ -364,6 +365,24 @@ func (d *Driver) SetVideoEncoderRate(rate VideoBitRate) (err error) {
return 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. // Rate queries the current video bit rate.
func (d *Driver) Rate() (err error) { func (d *Driver) Rate() (err error) {
buf, _ := d.createPacket(videoRateQuery, 0x48, 0) buf, _ := d.createPacket(videoRateQuery, 0x48, 0)
@ -628,7 +647,7 @@ func (d *Driver) SendStickCommand() (err error) {
axis4 := int16(660.0*d.lx + 1024.0) axis4 := int16(660.0*d.lx + 1024.0)
// speed control // 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 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)) binary.Write(buf, binary.LittleEndian, byte(0xFF&packedAxis))