@@ -20,7 +20,9 @@ Parameters are ideal for:
2020
2121## Parameter Examples
2222
23- ### 1. Parameter Declaration (` parameter-declaration-example.js ` )
23+ ### Local Parameters (On Current Node)
24+
25+ #### 1. Parameter Declaration (` parameter-declaration-example.js ` )
2426
2527** Purpose** : Demonstrates how to declare and use parameters in a ROS 2 node.
2628
@@ -41,7 +43,7 @@ Parameters are ideal for:
4143 - ** Default Value** : ` "hello world" `
4244- ** Run Command** : ` node parameter-declaration-example.js `
4345
44- ### 2. Parameter Override (` parameter-override-example.js ` )
46+ #### 2. Parameter Override (` parameter-override-example.js ` )
4547
4648** Purpose** : Shows how to override parameter values using command-line arguments.
4749
@@ -63,6 +65,74 @@ Parameters are ideal for:
6365 - ** Override Value** : ` "hello ros2" ` (via command line)
6466- ** Run Command** : ` node parameter-override-example.js `
6567
68+ ### Remote Parameter Access (On Other Nodes)
69+
70+ #### 3. ParameterClient Basic (` parameter-client-basic-example.js ` )
71+
72+ ** Purpose** : Demonstrates accessing and modifying parameters on a remote node using ` ParameterClient ` .
73+
74+ - ** Functionality** :
75+ - Creates a client node and ParameterClient
76+ - Connects to turtlesim node's parameters
77+ - Lists all available parameters
78+ - Gets and sets individual parameters
79+ - Retrieves multiple parameters at once
80+ - ** Features** :
81+ - Service availability checking with ` waitForService() `
82+ - Parameter listing with ` listParameters() `
83+ - Single parameter get/set operations
84+ - Batch parameter retrieval
85+ - Automatic type inference for parameter values
86+ - ** Target Node** : ` turtlesim ` (run: ` ros2 run turtlesim turtlesim_node ` )
87+ - ** Run Command** : ` node parameter-client-basic-example.js `
88+
89+ #### 4. ParameterClient Advanced (` parameter-client-advanced-example.js ` )
90+
91+ ** Purpose** : Comprehensive example showing all ParameterClient features and capabilities.
92+
93+ - ** Functionality** :
94+ - Creates target and client nodes
95+ - Declares parameters on target node
96+ - Demonstrates all ParameterClient operations:
97+ - List parameters
98+ - Get single/multiple parameters
99+ - Set single/multiple parameters
100+ - Describe parameters (get metadata)
101+ - Get parameter types
102+ - Timeout handling
103+ - Request cancellation with AbortController
104+ - ** Features** :
105+ - Complete API coverage
106+ - Error handling examples
107+ - Timeout and cancellation patterns
108+ - Automatic BigInt conversion for integers
109+ - Type inference demonstrations
110+ - Lifecycle management
111+ - ** Run Command** : ` node parameter-client-advanced-example.js `
112+
113+ ** ParameterClient Key Features** :
114+
115+ - ** Remote Access** : Query/modify parameters on any node
116+ - ** Async/Await API** : Modern promise-based interface
117+ - ** Type-Safe** : Automatic type inference and BigInt conversion
118+ - ** Timeout Support** : Per-request or default timeout settings
119+ - ** Cancellation** : AbortController integration for request cancellation
120+ - ** Lifecycle Management** : Automatic cleanup when parent node is destroyed
121+
122+ ** Public API** :
123+
124+ - ` remoteNodeName ` (getter) - Get the target node name
125+ - ` waitForService(timeout?) ` - Wait for remote services to be available
126+ - ` getParameter(name, options?) ` - Get a single parameter
127+ - ` getParameters(names, options?) ` - Get multiple parameters
128+ - ` setParameter(name, value, options?) ` - Set a single parameter
129+ - ` setParameters(parameters, options?) ` - Set multiple parameters
130+ - ` listParameters(options?) ` - List all parameters with optional filtering
131+ - ` describeParameters(names, options?) ` - Get parameter descriptors
132+ - ` getParameterTypes(names, options?) ` - Get parameter types
133+ - ` isDestroyed() ` - Check if client has been destroyed
134+ - ` destroy() ` - Clean up and destroy the client
135+
66136## How to Run the Examples
67137
68138### Prerequisites
@@ -128,6 +198,53 @@ ParameterDescriptor {
128198
129199Notice how the value changed from "hello world" to "hello ros2" due to the command-line override.
130200
201+ ### Running ParameterClient Basic Example
202+
203+ First, in one terminal, run turtlesim:
204+
205+ ``` bash
206+ ros2 run turtlesim turtlesim_node
207+ ```
208+
209+ Then in another terminal:
210+
211+ ``` bash
212+ cd example/parameter
213+ node parameter-client-basic-example.js
214+ ```
215+
216+ ** Expected Output** :
217+
218+ ```
219+ Current background_b: 255n
220+ Updated background_b: 200n
221+ ```
222+
223+ ### Running ParameterClient Advanced Example
224+
225+ ``` bash
226+ cd example/parameter
227+ node parameter-client-advanced-example.js
228+ ```
229+
230+ ** Expected Output** :
231+
232+ ```
233+ Available parameters: [ 'use_sim_time', 'max_speed', 'debug_mode', 'retry_count' ]
234+ max_speed = 10.5
235+ Retrieved parameters: [ 'max_speed', 'debug_mode', 'retry_count' ]
236+ max_speed descriptor: {
237+ name: 'max_speed',
238+ type: 3,
239+ description: 'Maximum speed in m/s',
240+ additional_constraints: '',
241+ read_only: false,
242+ dynamic_typing: false,
243+ floating_point_range: [],
244+ integer_range: []
245+ }
246+ ```
247+
131248## Using ROS 2 Parameter Tools
132249
133250You can interact with these examples using standard ROS 2 parameter tools:
@@ -276,19 +393,16 @@ const doubleParam = new Parameter(
276393### Common Issues
277394
2783951 . ** Parameter Not Found** :
279-
280396 - Ensure parameter is declared before accessing
281397 - Check parameter name spelling
282398 - Verify node has been properly initialized
283399
2844002 . ** Type Mismatch** :
285-
286401 - Ensure parameter type matches declaration
287402 - Check ParameterType constants are correct
288403 - Verify value type matches parameter type
289404
2904053 . ** Override Not Working** :
291-
292406 - Check command-line syntax: ` --ros-args -p node_name:param_name:=value `
293407 - Ensure node name matches exactly
294408 - Verify rclnodejs.init() is called with argv
0 commit comments