Skip to content

Commit

Permalink
Monitor parameter changes: Add note to save callback handle (#3102)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
(cherry picked from commit 1d24955)
  • Loading branch information
clalancette authored and mergify[bot] committed Oct 17, 2022
1 parent da3794a commit 80f409f
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,14 @@ The first statement, ``#include <memory>`` is included so that the code can util
The next, ``#include "rclcpp/rclcpp.hpp"`` is included to allow the code to reference the various functionality provided by the rclcpp interface, including the ParameterEventHandler class.

After the class declaration, the code defines a class, ``SampleNodeWithParameters``.
The constructor for the class, declares an integer parameter ``an_int_param``, with a default value of 0.
The constructor for the class declares an integer parameter ``an_int_param``, with a default value of 0.
Next, the code creates a ``ParameterEventHandler`` that will be used to monitor changes to parameters.
Finally, the code creates a lambda function and sets it as the callback to invoke whenever ``an_int_param`` is updated.

.. note::

It is very important to save the handle that is returned by ``add_parameter_callback``; otherwise, the callback will not be properly registered.

.. code-block:: C++

SampleNodeWithParameters()
Expand All @@ -154,7 +158,7 @@ Following the ``SampleNodeWithParameters`` is a typical ``main`` function which

.. code-block:: C++

int main(int argc, char** argv)
int main(int argc, char ** argv)
{
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared<SampleNodeWithParameters>());
Expand Down

0 comments on commit 80f409f

Please sign in to comment.