From 9875acbe06c2a689f0bbf098e094e10739c4dbc2 Mon Sep 17 00:00:00 2001 From: Ron Evans Date: Thu, 19 Apr 2018 18:28:14 +0200 Subject: [PATCH] tello: improve video encoding rate API call Signed-off-by: Ron Evans --- examples/tello_opencv.go | 3 ++- examples/tello_video.go | 2 +- platforms/dji/tello/driver.go | 18 +++++++++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/examples/tello_opencv.go b/examples/tello_opencv.go index 87d0eba3..b099aa03 100644 --- a/examples/tello_opencv.go +++ b/examples/tello_opencv.go @@ -64,7 +64,8 @@ func main() { fmt.Println("Connected") drone.StartVideo() drone.SetExposure(1) - drone.SetVideoEncoderRate(3) + drone.SetVideoEncoderRate(4) + gobot.Every(250*time.Millisecond, func() { drone.StartVideo() }) diff --git a/examples/tello_video.go b/examples/tello_video.go index f810e22f..580d98e1 100644 --- a/examples/tello_video.go +++ b/examples/tello_video.go @@ -36,7 +36,7 @@ func main() { drone.On(tello.ConnectedEvent, func(data interface{}) { fmt.Println("Connected") drone.StartVideo() - drone.SetExposure(0) + drone.SetVideoEncoderRate(4) gobot.Every(250*time.Millisecond, func() { drone.StartVideo() }) diff --git a/platforms/dji/tello/driver.go b/platforms/dji/tello/driver.go index b883697f..0926387d 100644 --- a/platforms/dji/tello/driver.go +++ b/platforms/dji/tello/driver.go @@ -191,13 +191,13 @@ func (d *Driver) Start() error { // send stick commands go func() { - time.Sleep(100 * time.Millisecond) + time.Sleep(50 * time.Millisecond) for { err := d.SendStickCommand() if err != nil { fmt.Println("stick command error:", err) } - time.Sleep(50 * time.Millisecond) + time.Sleep(20 * time.Millisecond) } }() @@ -335,7 +335,19 @@ func (d *Driver) SetExposure(level int) (err error) { // SetVideoEncoderRate sets the drone video encoder rate. func (d *Driver) SetVideoEncoderRate(rate int) (err error) { - pkt := []byte{messageStart, 0x60, 0x00, 0x27, 0x68, videoEncoderRateCommand, 0x00, 0xe6, 0x01, byte(rate), 0x00, 0x00} + pkt := []byte{messageStart, 0x62, 0x00, 0x27, 0x68, videoEncoderRateCommand, 0x00, 0xe6, 0x01, byte(rate), 0x00, 0x00, 0x00} + + // sets ending crc bytes for packet + l := len(pkt) + pkt[(l - 2)], pkt[(l - 1)] = CalculateCRC(pkt) + + _, err = d.reqConn.Write(pkt) + return +} + +// Rate does some still unknown thing. +func (d *Driver) Rate() (err error) { + pkt := []byte{messageStart, 0x58, 0x00, 0x7c, 0x48, 40, 0x00, 0xe6, 0x01, 0x6c, 0x95} // sets ending crc bytes for packet l := len(pkt)