-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
121 lines (103 loc) · 2.57 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package main
import (
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/platforms/dji/tello"
"gobot.io/x/gobot/platforms/keyboard"
)
const (
nextStepTime = 7 * time.Second
frameSize = 960 * 720 * 3
)
func main() {
drone := tello.NewDriver("8888")
keys := keyboard.NewDriver()
// window := opencv.NewWindowDriver()
work := func() {
/// video
// mplayer := exec.Command("mplayer", "-fps", "25", "-")
// mplayerIn, _ := mplayer.StdinPipe()
// if err := mplayer.Start(); err != nil {
// fmt.Println(err)
// return
// }
// drone.On(tello.ConnectedEvent, func(data interface{}) {
// fmt.Println("Connected")
// drone.StartVideo()
// drone.SetVideoEncoderRate(4)
// gobot.Every(100*time.Millisecond, func() {
// drone.StartVideo()
// })
// })
// drone.On(tello.VideoFrameEvent, func(data interface{}) {
// pkt := data.([]byte)
// if _, err := mplayerIn.Write(pkt); err != nil {
// fmt.Println(err)
// }
// })
/// opencv
// ffmpeg := exec.Command("ffmpeg", "-i", "pipe:0", "-pix_fmt", "bgr24", "-vcodec", "rawvideo",
// "-an", "-sn", "-s", "960x720", "-f", "rawvideo", "pipe:1")
// ffmpegIn, _ := ffmpeg.StdinPipe()
// ffmpegOut, _ := ffmpeg.StdoutPipe()
// if err := ffmpeg.Start(); err != nil {
// fmt.Println(err)
// return
// }
// go func() {
// for {
// buf := make([]byte, frameSize)
// if _, err := io.ReadFull(ffmpegOut, buf); err != nil {
// fmt.Println(err)
// continue
// }
// img := gocv.NewMatFromBytes(720, 960, gocv.MatTypeCV8UC3, buf)
// if img.Empty() {
// continue
// }
// window.ShowImage(img)
// window.WaitKey(1)
// }
// }()
// drone.On(tello.ConnectedEvent, func(data interface{}) {
// fmt.Println("Connected")
// drone.StartVideo()
// drone.SetExposure(1)
// drone.SetVideoEncoderRate(4)
// gobot.Every(100*time.Millisecond, func() {
// drone.StartVideo()
// })
// })
// drone.On(tello.VideoFrameEvent, func(data interface{}) {
// pkt := data.([]byte)
// if _, err := ffmpegIn.Write(pkt); err != nil {
// fmt.Println(err)
// }
// })
/// work
drone.TakeOff()
gobot.After(nextStepTime, func() {
drone.RightFlip()
})
gobot.After(nextStepTime, func() {
drone.Land()
})
/// keyboad
keys.On(keyboard.Key, func(data interface{}) {
key := data.(keyboard.KeyEvent)
switch key.Key {
case keyboard.T:
drone.TakeOff()
case keyboard.L:
drone.Land()
}
})
}
robot := gobot.NewRobot(
"tello",
[]gobot.Connection{},
[]gobot.Device{drone, keys},
work,
)
robot.Start()
}