Skip to content

sumin963/goroslib

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

goroslib

Test Lint PkgGoDev

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 with 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).

Features:

  • Subscribe and publish to topics, with TCP or UDP
  • Call and provide services
  • Get and set parameters
  • Get infos about other nodes, topics, services
  • Use namespaces and relative topics
  • IPv6 support (only stateful addresses, since stateless are not supported by the ROS master)
  • Compilation of .msg files is not necessary, message definitions are extracted from code
  • Compile or cross-compile ROS nodes for all Golang supported OSs (Linux, Windows, Mac OS X) and architectures
  • Examples provided for every feature, comprehensive test suite, continuous integration

Table of contents

Installation

  1. Install Go ≥ 1.13.

  2. Create an empty folder, open a terminal in it and initialize the Go modules system:

    go mod init main
    
  3. Download one of the example files and place it in the folder:

  4. Compile and run (a ROS master must be already running in the background)

    go run name-of-the-go-file.go
    

API Documentation

https://pkg.go.dev/github.com/aler9/goroslib#pkg-index

FAQs

Comparison with other libraries

goroslib vs official C++/Python libraries

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 with a fixed buildchain. 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.

goroslib vs rosgo

rosgo is currently unmaintained; furthermore, it requires compilation of .msg files and doesn't support UDP.

Full list of features

Current and missing features are described in the FEATURES document.

Use standard messages and services

Standard messages and services are available in folder pkg/msgs and described in the documentation.

Define custom messages

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/pkg/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

The name of a field must be in CamelCase, and is converted to snake_case when interacting with C++/Python nodes. If this conversion is impossible, the tag rosname can be used to override the field name:

type MessageName struct {
    msg.Package `ros:"my_package"`
    Field bool  `rosname:"FIELD"`
}

Import existing messages and services

A command-line utility is provided to convert existing .msg files into their equivalent Go structures:

go get github.com/aler9/goroslib/cmd/msg-import
msg-import --rospackage=my_package mymessage.msg > mymessage.go

Another one is provided to convert existing .srv files into their equivalent Go structures:

go get github.com/aler9/goroslib/cmd/srv-import
srv-import --rospackage=my_package myservice.srv > mymessage.go

Change namespace

There's a field Namespace in the Node configuration:

goroslib.NewNode(goroslib.NodeConf{
    Namespace:     "/mynamespace",
    Name:          "goroslib",
    MasterAddress: "127.0.0.1:11311",
})

The default namespace is / (global namespace).

Compile a node for another operating system

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

Edit the library

If you want to hack the library and test the results, unit tests can be launched with:

make test

Links

(v1) ROS Documentation

Other Go libraries

Other non-Go libraries

Conventions

About

ROS client library for the Go programming language

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 92.7%
  • CMake 2.4%
  • C++ 1.6%
  • Dockerfile 1.6%
  • Shell 1.1%
  • Makefile 0.6%