Giter Club home page Giter Club logo

ros2_node_listener's Introduction

node_listener

This ROS2 package contains some example C++ applications which demonstrate how to listen for various events generated by an rclcpp::Node object.

Example Applications

events_listener

events_listener.cpp shows how to register callbacks on rclcpp::Publisher and rclcpp:Subscription objects to receive notification of DDS-level events which are exposed by the rclcpp layer.

Each callback must be specified through the options data-structures ( rclcpp::PublisherOptions, and rclcpp::SubscriptionOptions) when creating the endpoints.

The example uses a custom helper "listener class" to demonstrate how to tie this events with any custom C++ object. See node_listener.hpp.

In order to receive these notification the Node and its endpoints must be attached to a spinning executor.

graph_listener

graph_listener.cpp shows how to receive notification of changes to the "graph" database maintained by each Node.

This is achieved by using the rclcpp::Event interface along with various functions exposed by rclcpp::Node.

Contrary to other ROS2 events (data receival, publisher/subscription events, timers, etc...), "graph changed" events cannot be dispatched by an executor, and they thus require the application to spawn a thread to call rclcpp::Node::wait_for_graph_change() in parallel to a spinning executor.

Build & Run

  1. Clone (or symlink) repository in a new workspace:

    mkdir ws-node_listener
    cd ws-node_listener
    git clone https://github.com/asorbini/ros2_node_listener
  2. Load ROS2 Galactic, build the examples, and load them:

    source /opt/ros/galactic/setup.bash
    colcon build --symlink-install
    source install/setup.bash
  3. (Optional) Make sure to use RTI Connext DDS:

    export RMW_IMPLEMENTATION=rmw_connextdds
  4. Run events_listener example:

    ros2 run node_listener events_listener
    
    # Use ^C to terminate
  5. Run graph_listener example:

    # Start listener in backgroun
    ros2 run node_listener graph_listener &
    
    # Generate some "graph changes" with `ros2 topic pub`
    ros2 topic pub "chatter" example_interfaces/msg/String
    
    # Use ^C to terminate the publisher (more changes will print)
    
    # Terminate listener
    fg
    # then ^C

ros2_node_listener's People

Contributors

asorbini 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.