rclnodejs 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +59 -0
- package/lib/action/client.js +55 -9
- package/lib/action/deferred.js +8 -2
- package/lib/action/server.js +10 -1
- package/lib/action/uuid.js +4 -1
- package/lib/client.js +152 -3
- package/lib/clock.js +4 -1
- package/lib/context.js +12 -2
- package/lib/duration.js +37 -12
- package/lib/errors.js +571 -0
- package/lib/event_handler.js +21 -4
- package/lib/interface_loader.js +52 -12
- package/lib/lifecycle.js +8 -2
- package/lib/logging.js +12 -3
- package/lib/message_serialization.js +10 -2
- package/lib/native_loader.js +9 -4
- package/lib/node.js +270 -49
- package/lib/parameter.js +172 -35
- package/lib/parameter_client.js +506 -0
- package/lib/parameter_watcher.js +309 -0
- package/lib/qos.js +22 -5
- package/lib/rate.js +6 -1
- package/lib/serialization.js +7 -2
- package/lib/time.js +136 -21
- package/lib/time_source.js +13 -4
- package/lib/utils.js +27 -1
- package/lib/validator.js +11 -12
- package/package.json +1 -1
- package/prebuilds/linux-x64/jazzy-noble-x64-rclnodejs.node +0 -0
- package/types/base.d.ts +3 -0
- package/types/client.d.ts +36 -0
- package/types/errors.d.ts +447 -0
- package/types/interfaces.d.ts +1910 -1
- package/types/node.d.ts +40 -0
- package/types/parameter_client.d.ts +252 -0
- package/types/parameter_watcher.d.ts +104 -0
package/types/node.d.ts
CHANGED
|
@@ -407,6 +407,32 @@ declare module 'rclnodejs' {
|
|
|
407
407
|
callback: ServiceRequestHandler<T>
|
|
408
408
|
): ServiceType<T>;
|
|
409
409
|
|
|
410
|
+
/**
|
|
411
|
+
* Create a ParameterClient for accessing parameters on a remote node.
|
|
412
|
+
*
|
|
413
|
+
* @param remoteNodeName - The name of the remote node whose parameters to access.
|
|
414
|
+
* @param options - Options for parameter client.
|
|
415
|
+
* @returns An instance of ParameterClient.
|
|
416
|
+
*/
|
|
417
|
+
createParameterClient(
|
|
418
|
+
remoteNodeName: string,
|
|
419
|
+
options?: { timeout?: number }
|
|
420
|
+
): ParameterClient;
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Create a ParameterWatcher for watching parameter changes on a remote node.
|
|
424
|
+
*
|
|
425
|
+
* @param remoteNodeName - The name of the remote node whose parameters to watch.
|
|
426
|
+
* @param parameterNames - Array of parameter names to watch.
|
|
427
|
+
* @param options - Options for parameter watcher.
|
|
428
|
+
* @returns An instance of ParameterWatcher.
|
|
429
|
+
*/
|
|
430
|
+
createParameterWatcher(
|
|
431
|
+
remoteNodeName: string,
|
|
432
|
+
parameterNames: string[],
|
|
433
|
+
options?: { timeout?: number }
|
|
434
|
+
): ParameterWatcher;
|
|
435
|
+
|
|
410
436
|
/**
|
|
411
437
|
* Create a guard condition.
|
|
412
438
|
*
|
|
@@ -454,6 +480,20 @@ declare module 'rclnodejs' {
|
|
|
454
480
|
*/
|
|
455
481
|
destroyService(service: Service): void;
|
|
456
482
|
|
|
483
|
+
/**
|
|
484
|
+
* Destroy a ParameterClient.
|
|
485
|
+
*
|
|
486
|
+
* @param parameterClient - ParameterClient to be destroyed.
|
|
487
|
+
*/
|
|
488
|
+
destroyParameterClient(parameterClient: ParameterClient): void;
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Destroy a ParameterWatcher.
|
|
492
|
+
*
|
|
493
|
+
* @param watcher - ParameterWatcher to be destroyed.
|
|
494
|
+
*/
|
|
495
|
+
destroyParameterWatcher(watcher: ParameterWatcher): void;
|
|
496
|
+
|
|
457
497
|
/**
|
|
458
498
|
* Destroy a Timer.
|
|
459
499
|
*
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
// Copyright (c) 2025 Mahmoud Alghalayini. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
declare module 'rclnodejs' {
|
|
16
|
+
/**
|
|
17
|
+
* Options for ParameterClient constructor.
|
|
18
|
+
*/
|
|
19
|
+
export interface ParameterClientOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Default timeout in milliseconds for service calls.
|
|
22
|
+
* @default 5000
|
|
23
|
+
*/
|
|
24
|
+
timeout?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Options for parameter service calls.
|
|
29
|
+
*/
|
|
30
|
+
export interface ParameterServiceCallOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Timeout in milliseconds for this specific call.
|
|
33
|
+
*/
|
|
34
|
+
timeout?: number;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* AbortSignal to cancel the request.
|
|
38
|
+
*/
|
|
39
|
+
signal?: AbortSignal;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Result of a parameter set operation.
|
|
44
|
+
*/
|
|
45
|
+
export interface ParameterSetResult {
|
|
46
|
+
/**
|
|
47
|
+
* The name of the parameter.
|
|
48
|
+
*/
|
|
49
|
+
name: string;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Whether the operation was successful.
|
|
53
|
+
*/
|
|
54
|
+
successful: boolean;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Reason message, typically populated on failure.
|
|
58
|
+
*/
|
|
59
|
+
reason: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Result of a list parameters operation.
|
|
64
|
+
*/
|
|
65
|
+
export interface ListParametersResult {
|
|
66
|
+
/**
|
|
67
|
+
* Array of parameter names found.
|
|
68
|
+
*/
|
|
69
|
+
names: string[];
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Array of parameter prefixes found.
|
|
73
|
+
*/
|
|
74
|
+
prefixes: string[];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Options for listing parameters.
|
|
79
|
+
*/
|
|
80
|
+
export interface ListParametersOptions extends ParameterServiceCallOptions {
|
|
81
|
+
/**
|
|
82
|
+
* Optional array of parameter name prefixes to filter by.
|
|
83
|
+
*/
|
|
84
|
+
prefixes?: string[];
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Depth of parameter namespace to list.
|
|
88
|
+
* @default 0 (unlimited)
|
|
89
|
+
*/
|
|
90
|
+
depth?: number;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Parameter to set with name and value.
|
|
95
|
+
*/
|
|
96
|
+
export interface ParameterToSet {
|
|
97
|
+
/**
|
|
98
|
+
* The name of the parameter.
|
|
99
|
+
*/
|
|
100
|
+
name: string;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The value to set. Type is automatically inferred.
|
|
104
|
+
*/
|
|
105
|
+
value: any;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Class for accessing parameters on remote ROS 2 nodes.
|
|
110
|
+
*
|
|
111
|
+
* Provides promise-based APIs to get, set, list, and describe parameters
|
|
112
|
+
* on other nodes in the ROS 2 system.
|
|
113
|
+
*/
|
|
114
|
+
export class ParameterClient {
|
|
115
|
+
/**
|
|
116
|
+
* Create a new ParameterClient for accessing parameters on a remote node.
|
|
117
|
+
*
|
|
118
|
+
* @param node - The node to use for creating service clients.
|
|
119
|
+
* @param remoteNodeName - The name of the remote node whose parameters to access.
|
|
120
|
+
* @param options - Optional configuration for the parameter client.
|
|
121
|
+
* @throws {TypeError} If node is not provided or remoteNodeName is not a valid string.
|
|
122
|
+
* @throws {Error} If remoteNodeName is not a valid ROS node name.
|
|
123
|
+
*/
|
|
124
|
+
constructor(
|
|
125
|
+
node: Node,
|
|
126
|
+
remoteNodeName: string,
|
|
127
|
+
options?: ParameterClientOptions
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Get the name of the remote node this client is connected to.
|
|
132
|
+
*/
|
|
133
|
+
readonly remoteNodeName: string;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Get a single parameter from the remote node.
|
|
137
|
+
*
|
|
138
|
+
* @param name - The name of the parameter to retrieve.
|
|
139
|
+
* @param options - Optional timeout and abort signal.
|
|
140
|
+
* @returns Promise that resolves with the Parameter object.
|
|
141
|
+
* @throws {Error} If the parameter is not found or service call fails.
|
|
142
|
+
*/
|
|
143
|
+
getParameter(
|
|
144
|
+
name: string,
|
|
145
|
+
options?: ParameterServiceCallOptions
|
|
146
|
+
): Promise<Parameter>;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Get multiple parameters from the remote node.
|
|
150
|
+
*
|
|
151
|
+
* @param names - Array of parameter names to retrieve.
|
|
152
|
+
* @param options - Optional timeout and abort signal.
|
|
153
|
+
* @returns Promise that resolves with an array of Parameter objects.
|
|
154
|
+
* @throws {Error} If the service call fails.
|
|
155
|
+
* @throws {TypeError} If names is not a non-empty array.
|
|
156
|
+
*/
|
|
157
|
+
getParameters(
|
|
158
|
+
names: string[],
|
|
159
|
+
options?: ParameterServiceCallOptions
|
|
160
|
+
): Promise<Parameter[]>;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Set a single parameter on the remote node.
|
|
164
|
+
*
|
|
165
|
+
* @param name - The name of the parameter to set.
|
|
166
|
+
* @param value - The value to set. Type is automatically inferred.
|
|
167
|
+
* @param options - Optional timeout and abort signal.
|
|
168
|
+
* @returns Promise that resolves with the result.
|
|
169
|
+
* @throws {Error} If the service call fails.
|
|
170
|
+
*/
|
|
171
|
+
setParameter(
|
|
172
|
+
name: string,
|
|
173
|
+
value: any,
|
|
174
|
+
options?: ParameterServiceCallOptions
|
|
175
|
+
): Promise<ParameterSetResult>;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Set multiple parameters on the remote node.
|
|
179
|
+
*
|
|
180
|
+
* @param parameters - Array of parameter objects with name and value.
|
|
181
|
+
* @param options - Optional timeout and abort signal.
|
|
182
|
+
* @returns Promise that resolves with an array of results.
|
|
183
|
+
* @throws {Error} If the service call fails.
|
|
184
|
+
* @throws {TypeError} If parameters is not a non-empty array.
|
|
185
|
+
*/
|
|
186
|
+
setParameters(
|
|
187
|
+
parameters: ParameterToSet[],
|
|
188
|
+
options?: ParameterServiceCallOptions
|
|
189
|
+
): Promise<ParameterSetResult[]>;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* List all parameters available on the remote node.
|
|
193
|
+
*
|
|
194
|
+
* @param options - Optional filters, depth, timeout and abort signal.
|
|
195
|
+
* @returns Promise that resolves with parameter names and prefixes.
|
|
196
|
+
* @throws {Error} If the service call fails.
|
|
197
|
+
*/
|
|
198
|
+
listParameters(
|
|
199
|
+
options?: ListParametersOptions
|
|
200
|
+
): Promise<ListParametersResult>;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Describe parameters on the remote node.
|
|
204
|
+
*
|
|
205
|
+
* @param names - Array of parameter names to describe.
|
|
206
|
+
* @param options - Optional timeout and abort signal.
|
|
207
|
+
* @returns Promise that resolves with an array of parameter descriptors.
|
|
208
|
+
* @throws {Error} If the service call fails.
|
|
209
|
+
* @throws {TypeError} If names is not a non-empty array.
|
|
210
|
+
*/
|
|
211
|
+
describeParameters(
|
|
212
|
+
names: string[],
|
|
213
|
+
options?: ParameterServiceCallOptions
|
|
214
|
+
): Promise<any[]>;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Get the types of parameters on the remote node.
|
|
218
|
+
*
|
|
219
|
+
* @param names - Array of parameter names.
|
|
220
|
+
* @param options - Optional timeout and abort signal.
|
|
221
|
+
* @returns Promise that resolves with an array of parameter types.
|
|
222
|
+
* @throws {Error} If the service call fails.
|
|
223
|
+
* @throws {TypeError} If names is not a non-empty array.
|
|
224
|
+
*/
|
|
225
|
+
getParameterTypes(
|
|
226
|
+
names: string[],
|
|
227
|
+
options?: ParameterServiceCallOptions
|
|
228
|
+
): Promise<ParameterType[]>;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Wait for the parameter services to be available on the remote node.
|
|
232
|
+
* This is useful to verify the remote node is running before making calls.
|
|
233
|
+
*
|
|
234
|
+
* @param timeout - Optional timeout in milliseconds.
|
|
235
|
+
* @returns Promise that resolves to true if services are available.
|
|
236
|
+
*/
|
|
237
|
+
waitForService(timeout?: number): Promise<boolean>;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Check if the parameter client has been destroyed.
|
|
241
|
+
*
|
|
242
|
+
* @returns True if destroyed, false otherwise.
|
|
243
|
+
*/
|
|
244
|
+
isDestroyed(): boolean;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Destroy the parameter client and clean up all service clients.
|
|
248
|
+
* After calling this method, the client cannot be used anymore.
|
|
249
|
+
*/
|
|
250
|
+
destroy(): void;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// Copyright (c) 2025 Mahmoud Alghalayini. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
declare module 'rclnodejs' {
|
|
16
|
+
import { EventEmitter } from 'events';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Options for ParameterWatcher constructor.
|
|
20
|
+
*/
|
|
21
|
+
export interface ParameterWatcherOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Default timeout in milliseconds for service calls.
|
|
24
|
+
* @default 5000
|
|
25
|
+
*/
|
|
26
|
+
timeout?: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* ParameterWatcher - Watches parameter changes on a remote node.
|
|
31
|
+
*
|
|
32
|
+
* Subscribes to /parameter_events and emits 'change' events when
|
|
33
|
+
* watched parameters on the target node are modified.
|
|
34
|
+
*/
|
|
35
|
+
class ParameterWatcher extends EventEmitter {
|
|
36
|
+
/**
|
|
37
|
+
* Get the remote node name being watched.
|
|
38
|
+
*/
|
|
39
|
+
readonly remoteNodeName: string;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Get the list of watched parameter names.
|
|
43
|
+
*/
|
|
44
|
+
readonly watchedParameters: string[];
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Start watching for parameter changes.
|
|
48
|
+
* Waits for the remote node's parameter services and subscribes to parameter events.
|
|
49
|
+
*
|
|
50
|
+
* @param timeout - Timeout in milliseconds to wait for services.
|
|
51
|
+
* @returns Promise that resolves to true when watching has started.
|
|
52
|
+
*/
|
|
53
|
+
start(timeout?: number): Promise<boolean>;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Get current values of all watched parameters.
|
|
57
|
+
*
|
|
58
|
+
* @param options - Optional request options (timeout, signal).
|
|
59
|
+
* @returns Promise that resolves to an array of Parameter objects.
|
|
60
|
+
*/
|
|
61
|
+
getCurrentValues(options?: {
|
|
62
|
+
timeout?: number;
|
|
63
|
+
signal?: AbortSignal;
|
|
64
|
+
}): Promise<Parameter[]>;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Add a parameter name to the watch list.
|
|
68
|
+
*
|
|
69
|
+
* @param name - Parameter name to watch.
|
|
70
|
+
*/
|
|
71
|
+
addParameter(name: string): void;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Remove a parameter name from the watch list.
|
|
75
|
+
*
|
|
76
|
+
* @param name - Parameter name to stop watching.
|
|
77
|
+
* @returns True if the parameter was in the watch list.
|
|
78
|
+
*/
|
|
79
|
+
removeParameter(name: string): boolean;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Check if the watcher has been destroyed.
|
|
83
|
+
*
|
|
84
|
+
* @returns True if destroyed.
|
|
85
|
+
*/
|
|
86
|
+
isDestroyed(): boolean;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Destroy the watcher and clean up resources.
|
|
90
|
+
* Unsubscribes from parameter events and destroys the parameter client.
|
|
91
|
+
*/
|
|
92
|
+
destroy(): void;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Event emitted when watched parameters change.
|
|
96
|
+
*
|
|
97
|
+
* @event change
|
|
98
|
+
* @param params - Array of changed parameters (ParameterValue messages).
|
|
99
|
+
*/
|
|
100
|
+
on(event: 'change', listener: (params: any[]) => void): this;
|
|
101
|
+
once(event: 'change', listener: (params: any[]) => void): this;
|
|
102
|
+
emit(event: 'change', params: any[]): boolean;
|
|
103
|
+
}
|
|
104
|
+
}
|