goroslib is a library in pure Go that allows to build clients (nodes) for the Robot Operating System (ROS).
The Robot Operating System (ROS) is a project that provides a protocol specification to make multiple programs communicate with each other over time, exchanging structured data through topics, services and parameters. It was conceived to link sensors, algorithms and actuators in unmanned ground vehicles (UGVs) and robots, but it is not bounded to the robot world and can be used anywhere there's the need of building streams of data (for example in video processing).
The official project provides libraries to write nodes in C++ and Python, but they require the download of over 1GB of data and work only through a cmake-based buildchain, that is computationally intensive and difficult to customize. This library allows to write lightweight nodes that can be built with the standard Go compiler, do not need any runtime library and have a size of some megabytes. Another advantage lies in the possibility of compiling nodes for all the Golang supported operating systems (Linux, Windows, Mac OS X, etc) and architectures.
Features:
- Subscribe and publish to topics, via TCP or UDP
- Call and provide services
- Get and set parameters
- Get infos about other nodes, topics, services
- Compile or cross-compile ROS nodes for all Golang supported OSs (Linux, Windows, Mac OS X) and architectures
- Compilation of
.msg
files is not necessary, message definitions are deducted from code - Standard messages are available in folder
msgs/
- Examples provided for every feature, comprehensive test suite, continuous integration
The library provides its features by implementing in pure Go all the ROS protocols (xml-rpc, TCPROS, UDPROS) and APIs (Master API, Parameter Server API, Slave API).
-
Install Go ≥ 1.12.
-
Create an empty folder, open a terminal in it and initialize the Go modules system:
go mod init main
-
Download one of the example files and place it in the folder:
-
Compile and run (a ROS master must be already running in the background)
go run name-of-the-go-file.go
https://pkg.go.dev/github.com/aler9/goroslib
Standard messages are listed in the documentation.
To define custom messages, the standard ROS C++/Python libraries require .msg
files in this format:
bool field1
int32 field2
This library doesn't require any .msg
file, it is enough to write Go structures in this format:
import (
"github.com/aler9/goroslib/msgs"
)
type MessageName struct {
msg.Package `ros:"my_package"`
Field1 bool
Field2 int32
}
The type of a field can be one of the following:
- one of the primitive field types:
- bool
- int8
- uint8
- int16
- uint16
- int32
- uint32
- int64
- uint64
- float32
- float64
- string
- time.Time
- time.Duration
- another standard or custom message
A command-line utility is provided to convert existing .msg
files into their equivalent Go structures:
go get github.com/aler9/goroslib/commands/msg-import
msg-import --rospackage=my_package mymessage.msg > mymessage.go
To compile a node for another OS, it's enough to follow the standard Golang procedure to cross-compile, that consists in setting the GOOS
and GOARCH
environment variables according to the target machine. For instance, to build a node for Windows from another OS, run:
GOOS=windows GOARCH=amd64 go build -o node.exe name-of-source-file.go
If you want to hack the library and test the results, unit tests can be launched with:
make test
(v1) Protocol documentation
- https://wiki.ros.org/ROS/Technical%20Overview
- https://wiki.ros.org/Implementing%20Client%20Libraries
- https://wiki.ros.org/ROS/Master_API
- https://wiki.ros.org/ROS/Parameter%20Server%20API
- https://wiki.ros.org/ROS/Slave_API
- https://wiki.ros.org/ROS/Connection%20Header
- https://wiki.ros.org/ROS/TCPROS
- https://wiki.ros.org/ROS/UDPROS
- https://fossies.org/linux/wireshark/epan/dissectors/packet-prototcp.c
(v1) Messages
Other Go libraries
Other non-Go libraries
- (v1) [cpp] https://github.com/ros/ros_comm/tree/melodic-devel/clients/roscpp/src/libros (https://docs.ros.org/melodic/api/roscpp/html/classros_1_1NodeHandle.html)
- (v1) [python] https://docs.ros.org/melodic/api/rosnode/html/
- (v1) [c] https://github.com/ros-industrial/cros
- (v2) [misc] https://fkromer.github.io/awesome-ros2/