Code Monkey home page Code Monkey logo

rclgo's Introduction

rclgo the ROS2 client library Golang wrapper

Go Reference

Getting started

rclgo is used with the Go module system like most Go libraries. It also requires a ROS 2 installation as well as C bindings to any ROS interface type used with the library. The ROS core components can be installed by installing the Debian package ros-galactic-ros-core. C bindings for ROS interfaces are also usually distributed as Debian packages.

API documentation is available at pkg.go.dev.

ROS 2 interface bindings

rclgo requires Go bindings of all the ROS 2 interfaces to exist. rclgo-gen is used to generate Go bindings to existing interface types installed. The generated Go bindings depend on the corresponding C bindings to be installed.

rclgo-gen can be installed globally by running

go install github.com/tiiuae/rclgo/cmd/rclgo-gen@latest

but it is recommended to add rclgo-gen as a dependency to the project to ensure the version matches that of rclgo. This can be done by adding a file tools.go to the main package of the project containing something similar to the following:

//go:build tools

package main

import _ "github.com/tiiuae/rclgo/cmd/rclgo-gen"

Then run go mod tidy. This version of rclgo-gen can be used by running

go run github.com/tiiuae/rclgo/cmd/rclgo-gen generate -d msgs

in the project directory. The command can be added as a go generate comment to one of the source files in the project, such as main.go, as follows:

//go:generate go run github.com/tiiuae/rclgo/cmd/rclgo-gen generate -d msgs

Developing with custom interface types

By default rclgo-gen generate looks for interface definitions in $AMENT_PREFIX_PATH and generates Go bindings for all interfaces it finds. $AMENT_PREFIX_PATH contains a list of paths to the ROS 2 underlay and overlays you have sourced. If you want to use interfaces which are not available in $AMENT_PREFIX_PATH, you can either add the directories to $AMENT_PREFIX_PATH (use the package as an overlay) or pass paths using the --root-path option. If multiple --root-path options are passed, the paths are searched in the order the options are passed. If multiple identically named package and interface name combinations are found the first one is used. When --root-path is used, rclgo-gen generate won't look for interface definitions from $AMENT_PREFIX_PATH. If you want to generate bindings for files using both $AMENT_PREFIX_PATH and custom paths, you can pass --root-path="$AMENT_PREFIX_PATH" in addition to the other paths.

In addition to generating the Go bindings, you must also generate the C bindings, compile them and make them available to the Go tool. Generated Go bindings include the include and lib subdirectories of the root paths used when generating the bindings in the header and library search paths, respectively. When building a package using the Go bindings the environment variables CGO_CFLAGS and CGO_LDFLAGS can be used to pass additional -I and -L options, respectively, if needed.

An example is available in examples/custom_message_package.

rclgo's People

Contributors

ezzkoram avatar kivilahtio avatar lassilaiho avatar lime008 avatar solita-ilkkas avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.