Hello Tello!
Join our DJI Tello community & remove this banner.
Sign up

Gobot Question

SMerrony

Well-known member
Joined
May 1, 2018
Messages
45
Likes
35
Location
UK and France
#1
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...

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?
 

redruff

Active member
Joined
Apr 26, 2018
Messages
35
Likes
13
#4
I'm kind of new at GO but what actually happened when you ran that code? Did it throw an error?
And what I'm really getting at is....can you control two drones with one program by calling two drivers???
 

SMerrony

Well-known member
Joined
May 1, 2018
Messages
45
Likes
35
Location
UK and France
#5
I'm kind of new at GO but what actually happened when you ran that code? Did it throw an error?
And what I'm really getting at is....can you control two drones with one program by calling two drivers???
My code worked as soon as I used a single driver as suggested by javaguy, I got a video stream and control of the drone simultaneously.

I think you need to look at the "swarm" concept in Gobot to control two or more drones - can't help there as I'm monodromous at the moment.:D
 
Likes: Inakigarm

New Threads

Forum statistics

Threads
1,092
Messages
7,049
Members
2,319
Latest member
Mikos