Coder Social home page Coder Social logo

cbr_ros's Introduction

cbr_ros

foxy ci galactic ci coverage

Utility headers to make life easier for ROS2 C++ development.

  • parameters: declare/read/write nested data structures as ROS2 parameters via boost::hana introspection
  • clock_traits_ros: use ROS clocks with the clock_traits header from cbr_utils
  • msg_utils: conversions between ROS2 interfaces and std::chrono and Eigen types

Parameters

Including cbr_ros/parameters.hpp makes it possible to declare whole data structures as ROS parameters.

Supported data format

Handle nested data structures of

  • Regular ROS parameter types
  • std::array
  • std::tuple
  • boost::hana-registered struct
  • std::vector, with the exception that multiple levels of std::vector is not supported

Example

For example, consider the following C++ struct:

struct MyParameters
{
  double d{1};
  int i{2};
  std::string s{"3"};
};

We wish to declare the members of the struct as ROS parameters. Using the regular rclcpp API would require three calls to declare and three calls to read read those parameters.

MyParameters prm{};

node->declare_parameter<double>("myprm.d", prm.d);
node->declare_parameter<int>("myprm.i", prm.i);
node->declare_parameter<std::string>("myprm.s", prm.s);

prm.d = node->get_parameter("myprm.d").as_double();
prm.i = node->get_parameter("myprm.i").as_int();
prm.s = node->get_parameter("myprm.s").as_string();

This becomes very verbose for large, nested structures.

As a remedy, declareParams in cbr_ros/parameter.hpp makes it possible to handle MyParameters as a single object. The caveat is that it must first be registered with boost::hana to enable data structure introspection.

#include <boost/hana/define_struct.hpp>

BOOST_HANA_ADAPT_STRUCT(MyParameters, d, i, s);  // option: register just a subset of the members

Now parameter handling becomes much more succinct:

#include <cbr_ros/parameters.hpp>

MyParameters prm{};

cbr::declareParams(*node, "myprm", prm);
cbr::getParams(*node, "myprm", prm);

Even shorter is cbr::initParams(*node, "myprm", prm); which both declares and reads values.

Nested structures

See test/test_parameters.cpp for more complex examples.

Shortcomings

There is no support in these methods for declaring parameter descriptors.

cbr_ros's People

Contributors

pettni avatar tgurriet avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

hakiwen

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.