2018-04-17 05:08:22 +08:00
|
|
|
// +build example
|
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
|
|
|
/*
|
2018-04-20 16:29:45 +08:00
|
|
|
You must have MPlayer (https://mplayerhq.hu) installed in order to run this code. it will connect to the Tello
|
|
|
|
and then open a window using MPlayer showing the streaming video.
|
2018-04-17 05:08:22 +08:00
|
|
|
|
2018-04-18 18:15:18 +08:00
|
|
|
How to run
|
|
|
|
|
|
|
|
go run examples/tello_video.go
|
2018-04-17 05:08:22 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-04-18 18:15:18 +08:00
|
|
|
"os/exec"
|
2018-04-17 05:08:22 +08:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/platforms/dji/tello"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
drone := tello.NewDriver("8890")
|
|
|
|
|
|
|
|
work := func() {
|
2018-04-20 16:29:45 +08:00
|
|
|
mplayer := exec.Command("mplayer", "-fps", "25", "-")
|
|
|
|
mplayerIn, _ := mplayer.StdinPipe()
|
|
|
|
if err := mplayer.Start(); err != nil {
|
2018-04-17 05:08:22 +08:00
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-04-17 21:01:34 +08:00
|
|
|
drone.On(tello.ConnectedEvent, func(data interface{}) {
|
|
|
|
fmt.Println("Connected")
|
2018-04-17 05:08:22 +08:00
|
|
|
drone.StartVideo()
|
2018-04-20 00:28:14 +08:00
|
|
|
drone.SetVideoEncoderRate(4)
|
2018-04-20 16:29:45 +08:00
|
|
|
gobot.Every(100*time.Millisecond, func() {
|
2018-04-17 21:01:34 +08:00
|
|
|
drone.StartVideo()
|
|
|
|
})
|
2018-04-17 05:08:22 +08:00
|
|
|
})
|
|
|
|
|
2018-04-17 21:01:34 +08:00
|
|
|
drone.On(tello.VideoFrameEvent, func(data interface{}) {
|
2018-04-17 05:08:22 +08:00
|
|
|
pkt := data.([]byte)
|
2018-04-20 16:29:45 +08:00
|
|
|
if _, err := mplayerIn.Write(pkt); err != nil {
|
2018-04-17 05:08:22 +08:00
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("tello",
|
|
|
|
[]gobot.Connection{},
|
|
|
|
[]gobot.Device{drone},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
robot.Start()
|
|
|
|
}
|