I've got each of the example Gobot programs from the recent article running, so now I want to combine two of them so I can have vision and control simultaneously.
I couldn't find an example, so I tried the following approach - which seg faults...
Can anyone point me in the right direction?
I couldn't find an example, so I tried the following approach - which seg faults...
Code:
package main
import (
"fmt"
"os/exec"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/platforms/dji/tello"
)
func main() {
droneCam := tello.NewDriver("8890")
droneCmd := tello.NewDriver("8888")
work := func() {
mplayer := exec.Command("mplayer", "-vo", "x11", "-fps", "30", "-")
mplayerIn, _ := mplayer.StdinPipe()
if err := mplayer.Start(); err != nil {
fmt.Println(err)
return
}
droneCam.On(tello.ConnectedEvent, func(data interface{}) {
fmt.Println("Connected")
droneCam.StartVideo()
droneCam.SetVideoEncoderRate(2)
gobot.Every(2000*time.Millisecond, func() {
droneCam.StartVideo()
})
})
droneCam.On(tello.VideoFrameEvent, func(data interface{}) {
pkt := data.([]byte)
if _, err := mplayerIn.Write(pkt); err != nil {
fmt.Println(err)
}
})
// droneCmd.TakeOff()
// gobot.After(5*time.Second, func() {
// droneCmd.Land()
// })
}
robot := gobot.NewRobot("tello",
[]gobot.Connection{},
[]gobot.Device{droneCam, droneCmd},
work,
)
robot.Start()
}
Can anyone point me in the right direction?