2023-05-20 20:25:21 +08:00
|
|
|
//go:build example
|
2018-04-04 02:42:16 +08:00
|
|
|
// +build example
|
2023-05-20 20:25:21 +08:00
|
|
|
|
2018-04-04 02:42:16 +08:00
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
|
|
|
/*
|
2018-04-19 15:50:40 +08:00
|
|
|
How to run:
|
|
|
|
Connect to the drone's Wi-Fi network from your computer. It will be named something like "TELLO-XXXXXX".
|
2018-04-04 02:42:16 +08:00
|
|
|
|
2018-04-19 15:50:40 +08:00
|
|
|
Once you are connected you can run the Gobot code on your computer to control the drone.
|
|
|
|
|
|
|
|
go run examples/tello.go
|
2018-04-04 02:42:16 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-02-11 22:34:50 +08:00
|
|
|
"fmt"
|
2018-04-13 19:49:12 +08:00
|
|
|
"time"
|
2018-04-04 02:42:16 +08:00
|
|
|
|
2023-05-20 20:25:21 +08:00
|
|
|
"gobot.io/x/gobot/v2"
|
|
|
|
"gobot.io/x/gobot/v2/platforms/dji/tello"
|
2018-04-04 02:42:16 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2018-04-19 15:50:40 +08:00
|
|
|
drone := tello.NewDriver("8888")
|
2018-04-04 02:42:16 +08:00
|
|
|
|
|
|
|
work := func() {
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := drone.TakeOff(); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2018-04-04 22:13:37 +08:00
|
|
|
|
2018-04-13 19:49:12 +08:00
|
|
|
gobot.After(5*time.Second, func() {
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := drone.Land(); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2018-04-13 19:49:12 +08:00
|
|
|
})
|
2018-04-04 02:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("tello",
|
|
|
|
[]gobot.Connection{},
|
|
|
|
[]gobot.Device{drone},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := robot.Start(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2018-04-04 02:42:16 +08:00
|
|
|
}
|