@@ -45,14 +45,18 @@ const (
45
45
46
46
// VideoFrameEvent event
47
47
VideoFrameEvent = "videoframe"
48
+
49
+ // SetVideoEncoderRateEvent event
50
+ SetVideoEncoderRateEvent = "setvideoencoder"
48
51
)
49
52
50
53
const (
51
- messageStart = 0xcc
52
- wifiMessage = 26
53
- lightMessage = 53
54
- timeMessage = 70
55
- flightMessage = 86
54
+ messageStart = 0xcc
55
+ wifiMessage = 26
56
+ videoRateQuery = 40
57
+ lightMessage = 53
58
+ timeMessage = 70
59
+ flightMessage = 86
56
60
57
61
logMessage = 0x50
58
62
@@ -63,11 +67,58 @@ const (
63
67
takeoffCommand = 0x54
64
68
landCommand = 0x55
65
69
flipCommand = 0x5c
70
+ )
71
+
72
+ // FlipType is used for the various flips supported by the Tello.
73
+ type FlipType int
74
+
75
+ const (
76
+ // FlipFront flips forward.
77
+ FlipFront FlipType = 0
78
+
79
+ // FlipLeft flips left.
80
+ FlipLeft FlipType = 1
81
+
82
+ // FlipBack flips backwards.
83
+ FlipBack FlipType = 2
84
+
85
+ // FlipRight flips to the right.
86
+ FlipRight FlipType = 3
87
+
88
+ // FlipForwardLeft flips forwards and to the left.
89
+ FlipForwardLeft FlipType = 4
90
+
91
+ // FlipBackLeft flips backwards and to the left.
92
+ FlipBackLeft FlipType = 5
93
+
94
+ // FlipBackRight flips backwards and to the right.
95
+ FlipBackRight FlipType = 6
66
96
67
- flipFront = 0
68
- flipLeft = 1
69
- flipBack = 2
70
- flipRight = 3
97
+ // FlipForwardRight flips forewards and to the right.
98
+ FlipForwardRight FlipType = 7
99
+ )
100
+
101
+ // VideoBitRate is used to set the bit rate for the streaming video returned by the Tello.
102
+ type VideoBitRate int
103
+
104
+ const (
105
+ // VideoBitRateAuto sets the bitrate for streaming video to auto-adjust.
106
+ VideoBitRateAuto VideoBitRate = 0
107
+
108
+ // VideoBitRate1M sets the bitrate for streaming video to 1 Mb/s.
109
+ VideoBitRate1M VideoBitRate = 1
110
+
111
+ // VideoBitRate15M sets the bitrate for streaming video to 1.5 Mb/s
112
+ VideoBitRate15M VideoBitRate = 2
113
+
114
+ // VideoBitRate2M sets the bitrate for streaming video to 2 Mb/s.
115
+ VideoBitRate2M VideoBitRate = 3
116
+
117
+ // VideoBitRate3M sets the bitrate for streaming video to 3 Mb/s.
118
+ VideoBitRate3M VideoBitRate = 4
119
+
120
+ // VideoBitRate4M sets the bitrate for streaming video to 4 Mb/s.
121
+ VideoBitRate4M VideoBitRate = 5
71
122
)
72
123
73
124
// FlightData packet returned by the Tello
@@ -140,10 +191,16 @@ func NewDriver(port string) *Driver {
140
191
141
192
d .AddEvent (ConnectedEvent )
142
193
d .AddEvent (FlightDataEvent )
194
+ d .AddEvent (TakeoffEvent )
195
+ d .AddEvent (LandingEvent )
196
+ d .AddEvent (FlipEvent )
197
+ d .AddEvent (TimeEvent )
198
+ d .AddEvent (LogEvent )
143
199
d .AddEvent (WifiDataEvent )
144
200
d .AddEvent (LightStrengthEvent )
145
- d .AddEvent (VideoFrameEvent )
146
201
d .AddEvent (SetExposureEvent )
202
+ d .AddEvent (VideoFrameEvent )
203
+ d .AddEvent (SetVideoEncoderRateEvent )
147
204
148
205
return d
149
206
}
@@ -250,6 +307,8 @@ func (d *Driver) handleResponse() error {
250
307
d .Publish (d .Event (FlightDataEvent ), fd )
251
308
case exposureCommand :
252
309
d .Publish (d .Event (SetExposureEvent ), buf [7 :8 ])
310
+ case videoEncoderRateCommand :
311
+ d .Publish (d .Event (SetVideoEncoderRateEvent ), buf [7 :8 ])
253
312
default :
254
313
fmt .Printf ("Unknown message: %+v\n " , buf [0 :n ])
255
314
}
@@ -311,7 +370,7 @@ func (d *Driver) Land() (err error) {
311
370
return
312
371
}
313
372
314
- // StartVideo tells to start video stream.
373
+ // StartVideo tells Tello to send start info (SPS/PPS) for video stream.
315
374
func (d * Driver ) StartVideo () (err error ) {
316
375
pkt := []byte {messageStart , 0x58 , 0x00 , 0x7c , 0x60 , videoStartCommand , 0x00 , 0x00 , 0x00 , 0x6c , 0x95 }
317
376
_ , err = d .reqConn .Write (pkt )
@@ -334,8 +393,8 @@ func (d *Driver) SetExposure(level int) (err error) {
334
393
}
335
394
336
395
// SetVideoEncoderRate sets the drone video encoder rate.
337
- func (d * Driver ) SetVideoEncoderRate (rate int ) (err error ) {
338
- pkt := []byte {messageStart , 0x62 , 0x00 , 0x27 , 0x68 , videoEncoderRateCommand , 0x00 , 0xe6 , 0x01 , byte (rate ), 0x00 , 0x00 , 0x00 }
396
+ func (d * Driver ) SetVideoEncoderRate (rate VideoBitRate ) (err error ) {
397
+ pkt := []byte {messageStart , 0x60 , 0x00 , 0x27 , 0x68 , videoEncoderRateCommand , 0x00 , 0xe6 , 0x01 , byte (rate ), 0x00 , 0x00 }
339
398
340
399
// sets ending crc bytes for packet
341
400
l := len (pkt )
@@ -345,9 +404,9 @@ func (d *Driver) SetVideoEncoderRate(rate int) (err error) {
345
404
return
346
405
}
347
406
348
- // Rate does some still unknown thing .
407
+ // Rate queries the current video bit rate .
349
408
func (d * Driver ) Rate () (err error ) {
350
- pkt := []byte {messageStart , 0x58 , 0x00 , 0x7c , 0x48 , 40 , 0x00 , 0xe6 , 0x01 , 0x6c , 0x95 }
409
+ pkt := []byte {messageStart , 0x58 , 0x00 , 0x7c , 0x48 , videoRateQuery , 0x00 , 0xe6 , 0x01 , 0x6c , 0x95 }
351
410
352
411
// sets ending crc bytes for packet
353
412
l := len (pkt )
@@ -431,7 +490,7 @@ func (d *Driver) CounterClockwise(val int) error {
431
490
}
432
491
433
492
// Flip tells drone to flip
434
- func (d * Driver ) Flip (direction int ) (err error ) {
493
+ func (d * Driver ) Flip (direction FlipType ) (err error ) {
435
494
pkt := []byte {messageStart , 0x60 , 0x00 , 0x27 , 0x70 , flipCommand , 0x00 , 0xe6 , 0x01 , byte (direction ), 0x00 , 0x00 }
436
495
437
496
// sets ending crc bytes for packet
@@ -444,22 +503,22 @@ func (d *Driver) Flip(direction int) (err error) {
444
503
445
504
// FrontFlip tells the drone to perform a front flip.
446
505
func (d * Driver ) FrontFlip () (err error ) {
447
- return d .Flip (flipFront )
506
+ return d .Flip (FlipFront )
448
507
}
449
508
450
509
// BackFlip tells the drone to perform a back flip.
451
510
func (d * Driver ) BackFlip () (err error ) {
452
- return d .Flip (flipBack )
511
+ return d .Flip (FlipBack )
453
512
}
454
513
455
514
// RightFlip tells the drone to perform a flip to the right.
456
515
func (d * Driver ) RightFlip () (err error ) {
457
- return d .Flip (flipRight )
516
+ return d .Flip (FlipRight )
458
517
}
459
518
460
519
// LeftFlip tells the drone to perform a flip to the left.
461
520
func (d * Driver ) LeftFlip () (err error ) {
462
- return d .Flip (flipLeft )
521
+ return d .Flip (FlipLeft )
463
522
}
464
523
465
524
// ParseFlightData from drone
0 commit comments