Giter VIP home page Giter VIP logo

ros_parameter_collections's Introduction

title author date
ROS2 Parameter Collections Package
a.whit ([email](mailto:[email protected]))
July 2022

ROS2 Parameter Collections

A ROS2 package that provides an interface for treating ROS2 parameters (and parameter groups) like standard Python container data types (e.g., dict, list, set, and tuple).

For more information about Python containers, see the documentation for emulating container types, as well as the documentation for the collections package. The table of collection types in the collections.abc documentation can be especially informative.

For more information about working with ROS2 parameters, see the Understanding parameters tutorial.

Available collection types

At present, only the following classes from collections.abc are implemented:

  • Container
  • Iterable
  • Sized
  • Collection
  • Mapping
  • MutableMapping

In addition, the Dict class is defined as a child of MutableMapping that implements a subset of [dict] functionality. In particular, the setdefault method is implemented.

Installation

This package can be added to any ROS2 workspace. ROS2 workspaces are built using [colcon]. See the installation documentation for further information.

Testing

See the testing documentation for further information.

Getting started

Perhaps the best way to get started is via a simple example.

From within a configured ROS2 environment, initialize a ROS2 interface.

>>> import rclpy
>>> rclpy.init()

Use the ROS2 interface to create a ROS2 node.

>>> import rclpy.node
>>> node = rclpy.node.Node('test')

Add a parameter to the node.

>>> parameter = node.declare_parameter('parameter_a', 1.0)
>>> node.get_parameter('parameter_a').value
1.0

Create a mapping interface to the node parameters.

>>> from ros_parameter_collections import MutableMapping
>>> mapping = MutableMapping()
>>> mapping.node = node

This mapping can now be treated as a dict-like data structure, in order to access the parameters of the node.1

>>> mapping['parameter_b'] = 2
>>> mapping['parameter_a'] = 'one'
>>> list(mapping)
['parameter_b', 'parameter_a']
>>> {k: v for (k, v) in mapping.items()}
{'parameter_b': 2, 'parameter_a': 'one'}

Any modifications to the mapping data structure are reflected in the node parameters.

>>> node.get_parameter('parameter_a').value
'one'
>>> node.get_parameter('parameter_b').value
2

Clean up by destroying the node and shutting down the ROS2 interface.

>>> del mapping
>>> node.destroy_node()
>>> rclpy.shutdown()

Additional examples

Further examples are available in the docstrings of each Python module. Additional example documentation is forthcoming.

License

Copyright 2022 Neuromechatronics Lab, Carnegie Mellon University

Contributors:

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

Footnotes

  1. Note that the order of mapping keys is not guaranteed, which is consistent with legacy dict functionality, but not current dict functionality. In this example, the type of the parameter_a is changed, causing the keys to re-order (when the parameter is undeclared). โ†ฉ

ros_parameter_collections's People

Contributors

ricmua avatar

Watchers

 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.