@@ -110,6 +110,25 @@ Parameters are ideal for:
110110 - Lifecycle management
111111- ** Run Command** : ` node parameter-client-advanced-example.js `
112112
113+ #### 5. ParameterWatcher (` parameter-watcher-example.js ` )
114+
115+ ** Purpose** : Demonstrates watching parameter changes on a remote node in real-time.
116+
117+ - ** Functionality** :
118+ - Creates a watcher for turtlesim's background color parameters
119+ - Listens for parameter change events
120+ - Displays current parameter values
121+ - Shows real-time updates when parameters change
122+ - ** Features** :
123+ - Event-driven parameter monitoring
124+ - Automatic filtering by node and parameter names
125+ - Real-time change notifications
126+ - Built on top of ParameterClient
127+ - Simple EventEmitter API
128+ - ** Target Node** : ` turtlesim ` (run: ` ros2 run turtlesim turtlesim_node ` )
129+ - ** Run Command** : ` node parameter-watcher-example.js `
130+ - ** Test Changes** : In another terminal, run ` ros2 param set /turtlesim background_r 200 `
131+
113132** ParameterClient Key Features** :
114133
115134- ** Remote Access** : Query/modify parameters on any node
@@ -119,7 +138,7 @@ Parameters are ideal for:
119138- ** Cancellation** : AbortController integration for request cancellation
120139- ** Lifecycle Management** : Automatic cleanup when parent node is destroyed
121140
122- ** Public API** :
141+ ** ParameterClient Public API** :
123142
124143- ` remoteNodeName ` (getter) - Get the target node name
125144- ` waitForService(timeout?) ` - Wait for remote services to be available
@@ -133,6 +152,27 @@ Parameters are ideal for:
133152- ` isDestroyed() ` - Check if client has been destroyed
134153- ` destroy() ` - Clean up and destroy the client
135154
155+ ** ParameterWatcher Key Features** :
156+
157+ - ** Real-Time Monitoring** : Automatically notified when watched parameters change
158+ - ** Event-Driven** : Uses EventEmitter pattern for clean async code
159+ - ** Filtered** : Only notifies about relevant parameter changes
160+ - ** Flexible** : Add/remove parameters from watch list dynamically
161+ - ** Built on ParameterClient** : Can query current values at any time
162+ - ** Lifecycle Management** : Automatic cleanup when parent node is destroyed
163+
164+ ** ParameterWatcher Public API** :
165+
166+ - ` remoteNodeName ` (getter) - Get the target node name
167+ - ` watchedParameters ` (getter) - Get list of watched parameter names
168+ - ` start(timeout?) ` - Start watching for parameter changes
169+ - ` getCurrentValues(options?) ` - Get current values of all watched parameters
170+ - ` addParameter(name) ` - Add a parameter to the watch list
171+ - ` removeParameter(name) ` - Remove a parameter from the watch list
172+ - ` on('change', callback) ` - Listen for parameter change events
173+ - ` isDestroyed() ` - Check if watcher has been destroyed
174+ - ` destroy() ` - Clean up and destroy the watcher
175+
136176## How to Run the Examples
137177
138178### Prerequisites
@@ -245,6 +285,46 @@ max_speed descriptor: {
245285}
246286```
247287
288+ ### Running ParameterWatcher Example
289+
290+ First, in one terminal, run turtlesim:
291+
292+ ``` bash
293+ ros2 run turtlesim turtlesim_node
294+ ```
295+
296+ Then in another terminal:
297+
298+ ``` bash
299+ cd example/parameter
300+ node parameter-watcher-example.js
301+ ```
302+
303+ ** Expected Output** :
304+
305+ ```
306+ Watching: [ 'background_r', 'background_g' ]
307+ Added background_b. Now watching: [ 'background_r', 'background_g', 'background_b' ]
308+ Removed background_g. Now watching: [ 'background_r', 'background_b' ]
309+ ```
310+
311+ Now in a third terminal, change a parameter to see real-time updates:
312+
313+ ``` bash
314+ ros2 param set /turtlesim background_r 200
315+ ros2 param set /turtlesim background_b 100
316+ ros2 param set /turtlesim background_g 50 # This won't trigger (removed from watch list)
317+ ```
318+
319+ You'll see output like:
320+
321+ ```
322+ background_r changed to 200
323+ background_b changed to 100
324+ ```
325+
326+ Note: ` background_g ` changes won't be displayed since it was removed from the watch list.
327+
248328## Using ROS 2 Parameter Tools
249329
250330You can interact with these examples using standard ROS 2 parameter tools:
0 commit comments