If you started reading this post thinking I would explain why you should go for ROS when building robots, think again. To be fair, that topic deserves a post of its own. But for this article, I’ll be using Go in the context of Golang. As in the Go programming language. As in the one designed by Google with an adorable Gopher for a mascot.
Specifically, we will talk about ROS client libraries for the Go programming language; their features, their advantages, and what gaps still remain.
What is Go?
Go is a relatively young open-source programming language designed by Google. It was first introduced in 2009 and has since gained a large following in tech circles. By the end of 2018, it was the fastest growing language on GitHub.
Go combines the best features of other popular programming languages. It matches the performance of C while natively offering features like memory safety, garbage collection and CSP-style currency.
As a result, it takes care of some big under-the-hood details affecting program execution right out of the box. Users are freed up to focus on the more innovative parts of their code. So, to a large extent, Go merges the efficiency of C with the development speed of Python.
Also, the syntax of Go looks and reads quite similar to C. This makes it easier for most developers to pick up the language as the C-family of languages is already dominant in the programming community.
This ease of adoption has turned Go into a popular choice for many enterprises and large-scale projects in recent years. Google, Dropbox, Netflix, eBay and BBC are just a few of the prominent businesses that have adopted Go. Docker, the most widely used containerisation platform in the industry, is entirely crafted in Go. So are Kubernetes and Prometheus. We’ve embraced it ourselves: snapd, one of the primary pieces of technology behind snaps, is written in Go.
What are ROS client libraries?
Robot Operating System (ROS) is a middleware for building robots. It defines a set of protocols for different programs to communicate with each other and exchange information in a structured way.
A ROS client library is an API that exposes the core functionality of ROS to developers. Client libraries let programmers write ROS nodes, publish and subscribe to topics, write and call services, and access other ROS concepts without diving into the framework’s source code.
ROS 1 currently has three main client libraries:
- roscpp, a C++ client designed for high runtime performance,
- rospy, a Python client designed for quick prototyping, and
- roslisp, a LISP client designed for planning libraries.
Although the official project only provides support for C++ and Python, client libraries can in practice be implemented in any programming language. The ROS community currently maintains more than a dozen experimental client libraries that offer APIs for Ruby, Java, Julia, C# and Go, among others.
So why have a ROS client for Go?
For starters, Go is a flexible language that is useful for building several major components vital in robotics. These include distributed microservices, system and networking applications, machine learning algorithms, signal processing routines, and computer vision programs.
At a more granular level, Go’s native garbage collector significantly decreases the chances of memory leaks, and its mastery of concurrency operations allows apps to properly harness the full potential of multi-core systems.
This mitigates the risk of a Go program crashing in the field or corrupting shared memory resources; a boon to mission critical systems where reliability is key.
Go also has a nimble design that makes it less demanding on system resources. The standard C++ and Python clients for ROS download over 1GB of dependencies, and work only with computationally intensive buildchains. A Go client instead allows users to build much lighter nodes that have the size of only a few megabytes. This makes it a great choice for resource-constrained devices operating at the edge.
Besides this lightweight nature, Go emphasises code readability and requires little effort to learn, as explained previously. Its default collection of tools for static code analysis, testing and profiling, and detecting race conditions further simplify development tasks.
All this translates to less money spent in developing a robot, fewer resources spent on running and maintaining it, and notably less time spent on making the robot do just what we want.
What clients are out there?
As of April 2020, there are two client libraries for ROS 1 that provide varying levels of support for Go:
- rosgo – A pure Go implementation of basic ROS functionality maintained by Fetch Robotics. This library lacks any tutorials or setup guides for beginners. Note that this is a fork of the original library from Akio Ochiai. The official page for rosgo on the ROS Wiki still points to this older unmaintained repository.
- goroslib – Another implementation of ROS concepts written entirely in Go. This library has good documentation, and offers some nice short examples for new users. However, this library was introduced only earlier this year, so it is still quite fresh. There may be issues in the code that have yet to be reported from the field.
There is also work being done to build a Go wrapper for ROS 2 under the rclgo project, but this client is not completely functional yet.
Where to next?
These existing client libraries are a good start. But there is large room for improvement in what is currently available for Go in ROS.
The benefits of a pure Go implementation are watered down if other packages on the robot are in another language. So developing Go libraries for commonly used packages like pcl, opencv and moveit would help users to better exploit the advantages of Go.
We should also keep in mind that Go is still a youngling in the programming world. Additional tutorials and getting started guides will help the more traditional roboticists get on board quickly, and encourage greater adoption in the developer community. Gobot, a framework for robots and IoT written in Go, does this part pretty well.
And lastly, community participation is key. If you’re a ROS user, consider joining the Gophers and playing around with the language. Explore how it can be used to enhance the performance and user experience of ROS, and start a discussion around it. And if you’re up for the challenge, help out the community by contributing code and expanding Go usage in ROS.
Given its nifty software features and its relatively gentle learning curve, Go offers an interesting opportunity for more graceful robotics engineering. An opportunity certainly worth digging into!