Gobot is a framework written in the Go programming language, suitable for the development of robots, drones, and IoT projects. It was created and maintained by the Hybrid Group, aiming to simplify the application development process related to smart hardware and IoT. By using Gobot, developers can more easily connect, control, and expand various physical devices.
Gobot provides a simple API for interacting with various hardware platforms (such as Arduino, Raspberry Pi, BeagleBone, etc.) and software protocols (such as MQTT, HTTP, WebSockets, etc.). Additionally, it provides drivers and adapters to control devices ranging from low-level devices like Arduino and Raspberry Pi to more advanced devices like drones, toys, and other devices with APIs.
Because the Go language is known for its concurrency model and memory safety, Gobot performs exceptionally well in handling real-time systems and resource-constrained hardware. Therefore, Gobot is an ideal choice for robot, drone, and IoT projects that require high performance and portability.
Overall, Gobot provides developers with a powerful and flexible toolkit to quickly build and expand smart device and robot applications.
To obtain the Gobot source code, run the following command:
git clone https://github.com/hybridgroup/gobot.git
git checkout release
Then take a look at the examples directory. You need to find an example that matches your platform for your first test (for example, “raspi_blink.go”). Then build the binary (cross-compile), transfer it to your target, and run it.
env GOOS=linux GOARCH=arm GOARM=5 go build -o ./output/my_raspi_blink examples/raspi_blink.go
Building code on your local machine using the above example will create a binary for ARMv5. This may not be what is needed for your specific target platform. Please also read the platform-specific documentation in the platform subfolder.
Create Your First Project
Create a new folder and a new Go module project.
mkdir ~/my_gobot_example
cd ~/my_gobot_example
go mod init my.gobot.example.com
Besides the go.mod file, copy the example file, import the requirements, and build.
cp //examples/raspi_blink.go ~/my_gobot_example/
go mod tidy
env GOOS=linux GOARCH=arm GOARM=5 go build -o ./output/my_raspi_blink raspi_blink.go
Now you are ready to modify the example and test your changes. First, remove the build directive at the beginning of the file.
Examples
Gobot with Arduino
package main
import (
"time"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/gpio"
"gobot.io/x/gobot/v2/platforms/firmata"
)
func main() {
firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
led := gpio.NewLedDriver(firmataAdaptor, "13")
work := func() {
gobot.Every(1*time.Second, func() {
led.Toggle()
})
}
robot := gobot.NewRobot("bot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{led},
work,
)
robot.Start()
}
Gobot with Sphero
package main
import (
"fmt"
"time"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/platforms/sphero"
)
func main() {
adaptor := sphero.NewAdaptor("/dev/rfcomm0")
driver := sphero.NewSpheroDriver(adaptor)
work := func() {
gobot.Every(3*time.Second, func() {
driver.Roll(30, uint16(gobot.Rand(360)))
})
}
robot := gobot.NewRobot("sphero",
[]gobot.Connection{adaptor},
[]gobot.Device{driver},
work,
)
robot.Start()
}
Hardware Support
Gobot has an extensible system for connecting hardware devices. Currently, it supports the following robots and physical computing platforms:
- Arduino
- Beaglebone Black
- Raspberry Pi
- ESP8266
- And many more…
To quickly develop a drone application with Gobot, you can follow these steps:
- Install and Set Up Gobot:
- First, ensure you have the Go programming environment installed.
- Use
go get
to install the Gobot library:go get -u gopkg.in/hybridgroup.io/gobot.v2
- Understand Drone Hardware:
- Identify the drone hardware you will use (such as DJI, Parrot, or other brands) and the communication protocols (like MQTT, HTTP, etc.).
- Understand the drone’s API and control commands to be able to control it via code.
- Write Gobot Program:
- Create a new Go file, for example,
drone_app.go
. - Import necessary Gobot packages and other related packages.
- Initialize Gobot and set up the connection to the drone hardware.
- Create a new Go file, for example,
- Define Robot and Connection:
- Use Gobot’s API to define your drone as a robot.
- Configure the connection to the drone, which may involve setting up serial communication, network connection, or other communication methods.
- Write Control Logic:
- In Gobot’s
Start
function, write the logic to control the drone. - Use Gobot’s API to send control commands to the drone, such as takeoff, landing, moving forward, moving backward, etc.
- You can add sensor readings, obstacle avoidance logic, or other custom features as needed.
- In Gobot’s
- Run and Test the Application:
- Run your Go program in the terminal:
go run drone_app.go
. - Observe the drone’s behavior to ensure it acts as expected.
- Adjust and optimize your control logic based on test results.
- Run your Go program in the terminal:
- Expand Functionality:
- Add more features as needed, such as GPS navigation, image recognition, automated flight tasks, etc.
- Utilize Gobot’s concurrency model to easily add parallel processing tasks and logic.
Please note that the specific implementation will depend on the drone hardware and API you are using. Be sure to refer to the drone’s developer documentation on how to communicate and control it.
Additionally, due to the complexity and safety requirements of drone applications, it is recommended to strictly adhere to relevant laws and safety guidelines during development to ensure safe and compliant flights.