GOBOT is a framework for robotics, physical computing, and the Internet of Things (IoT), written in the Go programming language by The Hybrid Group Team .It provides adapters and drivers for controlling a wide variety of physical devices from low-level Arduino to Drones.
In this post, we are going to learn some basics of Gobot framework and a bit about drone. Combining together, let us build a solution to automate the drone.
First, let us see the core things of the Gobot framework.
- Adaptors provide the needed interface to communicate with the hardware.
- Drivers consume the interface provided by the adaptors and talk to the hardware directly.
- Robot is the main abstraction used by Gobot. A Robot can represent a drone or some other kind of connected or autonomous machine.
- Commands are to control the capabilities through our Gobot programs which are exposed via the Gobot API.
- Events are how notifications are passed to inform code when important things happen. Drivers use this to communicate back to Robot.
Apart from these things, Gobot includes RESTful API to query the connection status and other information from a single device(Robot)/ Devices running in the group.
Also, Gobot can be extended to add new support for additional hardware and software devices. In such a case, we can write our own Adaptor/Driver or both for new devices.
A bit about our Drone…
New to drone? Then DJI Tello is the best choice to start. It is highly programmable and cost about USD $99 only. A tech startup based out of China Ryze Technology is the creator of this drone. It is powered by a world-leading DJI flight control system and an Intel processor.
- Weight: Approximately 80 g (with propellers and battery)
- Built-In Functions: Range Finder, Barometer, LED, Vision System, WIFI 802.11n 2.4G, 5MP Camera with 720P Live View.
- Max Flight Distance/Speed/Flight Time: 100m /(8m/s) /13min.
- Detachable Battery: 1.1Ah/3.8V
- Port: Micro USB Charging Port
Tello provides Mobile App for both Android and iOS with super user-friendly UI to control the drone. That apart, Tello is compatible with VR Headset and Controller. That’s all the key things about our drone!
go get -tool in Golang will help you to install Gobot and its required dependencies.
$ go get -d -u gobot.io/x/gobot/...
In addition, we need to install two libraries and the corresponding path need to be configured. Refer to the below steps:
1.FFMPEG is a software suite of libraries and programs for handling video, audio and other multimedia files and streams. Here, we are going to use it to transcode the raw video stream from the drone.
$ brew install ffmpeg $(brew options ffmpeg | grep -v -e '\s' | grep -e '--with-\|--HEAD' | tr '\n' ' ')$ export LDFLAGS="-L/usr/local/opt/libffi/lib"
$ export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"
2.OpenCv (Open Source Computer Vision Library) is mainly aimed at real-time computer vision. In our case, we are using this library to create a window to show the transcoded video frames from the FFMPEG.
$ brew install opencv$ export LDFLAGS="-L/usr/local/opt/openblas/lib"
$ export CPPFLAGS="-I/usr/local/opt/openblas/include"
$ export PKG_CONFIG_PATH="/usr/local/opt/openblas/lib/pkgconfig"
Our environment is ready to Go…
Start-Automating the Drone…
Create a file and name it as automate_tello.go to write the program. I referred the Gobot Tello API from here to write the below program.
So, what is the program going to do?
- It will start the FFMPEG to encode the raw video from Drone.
- Then, connect to drone. On successful connection, it will start and continue the video stream from the drone.
- It pipes the raw video frame to the FFMPEG function to transcode it.
- The GoCV function creates a window and displays continuously the video from FFMPEG.
- After 5 seconds, the drone will take off and fly.
- After 10 seconds, drone automatically lands.
Refer the below program:
Power up the drone. Now, connect to the drone’s Wi-Fi network from your computer. It will be named something like “TELLO-XXXXXX”.
All set! let us run the program to fly the drone…
To run the program
$ go run automate_tello.go
Where it’s being used?
Automating of drones serves innumerable purposes. One of them being, Industrial Asset management has a good use-case where using the UAV (Unmanned Aerial Vehicle) nothing but a drone to Inspect & Monitor the Industrial Assets. Different range of Drones is available in the market with features like GPS, waypoints and point of interest etc., By using those features drone can be operated autonomously to do a myriad of jobs.
Please 👏🏼 if you enjoyed this post !! Let me know your thoughts in 💬 below 👇🏻