rclnodejs 1.8.3 → 1.9.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/README.md +46 -37
- package/index.js +39 -0
- package/lib/action/client.js +61 -3
- package/lib/action/server_goal_handle.js +26 -1
- package/lib/message_info.js +94 -0
- package/lib/node.js +260 -13
- package/lib/parameter_event_handler.js +566 -0
- package/lib/parameter_watcher.js +12 -12
- package/lib/qos_overriding_options.js +358 -0
- package/lib/subscription.js +38 -5
- package/lib/timer.js +3 -2
- package/lib/wait_for_message.js +111 -0
- package/package.json +7 -4
- package/prebuilds/linux-arm64/humble-jammy-arm64-rclnodejs.node +0 -0
- package/prebuilds/linux-arm64/jazzy-noble-arm64-rclnodejs.node +0 -0
- package/prebuilds/linux-arm64/kilted-noble-arm64-rclnodejs.node +0 -0
- package/prebuilds/linux-x64/humble-jammy-x64-rclnodejs.node +0 -0
- package/prebuilds/linux-x64/jazzy-noble-x64-rclnodejs.node +0 -0
- package/prebuilds/linux-x64/kilted-noble-x64-rclnodejs.node +0 -0
- package/scripts/run_asan_test.sh +118 -0
- package/src/executor.cpp +36 -2
- package/src/executor.h +11 -0
- package/src/rcl_action_client_bindings.cpp +70 -1
- package/src/rcl_context_bindings.cpp +3 -3
- package/src/rcl_graph_bindings.cpp +2 -2
- package/src/rcl_subscription_bindings.cpp +70 -2
- package/src/rcl_timer_bindings.cpp +21 -2
- package/src/rcl_utilities.cpp +2 -2
- package/tools/jsdoc/Makefile +5 -0
- package/tools/jsdoc/README.md +96 -0
- package/tools/jsdoc/build-index.js +610 -0
- package/tools/jsdoc/publish.js +854 -0
- package/tools/jsdoc/regenerate-published-docs.js +605 -0
- package/tools/jsdoc/static/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/tools/jsdoc/static/fonts/OpenSans-Bold-webfont.svg +1830 -0
- package/tools/jsdoc/static/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/tools/jsdoc/static/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/tools/jsdoc/static/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
- package/tools/jsdoc/static/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/tools/jsdoc/static/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/tools/jsdoc/static/fonts/OpenSans-Italic-webfont.svg +1830 -0
- package/tools/jsdoc/static/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/tools/jsdoc/static/fonts/OpenSans-Light-webfont.eot +0 -0
- package/tools/jsdoc/static/fonts/OpenSans-Light-webfont.svg +1831 -0
- package/tools/jsdoc/static/fonts/OpenSans-Light-webfont.woff +0 -0
- package/tools/jsdoc/static/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/tools/jsdoc/static/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
- package/tools/jsdoc/static/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/tools/jsdoc/static/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/tools/jsdoc/static/fonts/OpenSans-Regular-webfont.svg +1831 -0
- package/tools/jsdoc/static/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/tools/jsdoc/static/scripts/linenumber.js +25 -0
- package/tools/jsdoc/static/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/tools/jsdoc/static/scripts/prettify/lang-css.js +36 -0
- package/tools/jsdoc/static/scripts/prettify/prettify.js +738 -0
- package/tools/jsdoc/static/styles/jsdoc-default.css +1012 -0
- package/tools/jsdoc/static/styles/prettify-jsdoc.css +111 -0
- package/tools/jsdoc/static/styles/prettify-tomorrow.css +132 -0
- package/tools/jsdoc/tmpl/augments.tmpl +10 -0
- package/tools/jsdoc/tmpl/container.tmpl +193 -0
- package/tools/jsdoc/tmpl/details.tmpl +143 -0
- package/tools/jsdoc/tmpl/example.tmpl +2 -0
- package/tools/jsdoc/tmpl/examples.tmpl +13 -0
- package/tools/jsdoc/tmpl/exceptions.tmpl +17 -0
- package/tools/jsdoc/tmpl/layout.tmpl +83 -0
- package/tools/jsdoc/tmpl/mainpage.tmpl +163 -0
- package/tools/jsdoc/tmpl/members.tmpl +43 -0
- package/tools/jsdoc/tmpl/method.tmpl +124 -0
- package/tools/jsdoc/tmpl/params.tmpl +133 -0
- package/tools/jsdoc/tmpl/properties.tmpl +110 -0
- package/tools/jsdoc/tmpl/returns.tmpl +12 -0
- package/tools/jsdoc/tmpl/source.tmpl +8 -0
- package/tools/jsdoc/tmpl/tutorial.tmpl +19 -0
- package/tools/jsdoc/tmpl/type.tmpl +7 -0
- package/types/action_client.d.ts +8 -0
- package/types/index.d.ts +34 -0
- package/types/message_info.d.ts +72 -0
- package/types/node.d.ts +90 -5
- package/types/parameter_event_handler.d.ts +150 -0
- package/types/qos.d.ts +55 -0
- package/types/subscription.d.ts +14 -2
- package/types/timer.d.ts +3 -2
- package/test_data_integrity.js +0 -108
- package/test_repro_exact.js +0 -57
- package/test_repro_hz.js +0 -86
- package/test_repro_pub.js +0 -36
- package/test_repro_stress.js +0 -83
- package/test_repro_sub.js +0 -64
- package/test_xproc_data.js +0 -64
- package/types/interfaces.d.ts +0 -8895
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
// Copyright (c) 2026 The Robot Web Tools Contributors. 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
|
+
'use strict';
|
|
16
|
+
|
|
17
|
+
const QoS = require('./qos.js');
|
|
18
|
+
const {
|
|
19
|
+
Parameter,
|
|
20
|
+
ParameterType,
|
|
21
|
+
ParameterDescriptor,
|
|
22
|
+
} = require('./parameter.js');
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Enum of overridable QoS policy kinds.
|
|
26
|
+
* Each value corresponds to a QoS property on the {@link QoS} class.
|
|
27
|
+
* @enum {number}
|
|
28
|
+
*/
|
|
29
|
+
const QoSPolicyKind = Object.freeze({
|
|
30
|
+
HISTORY: 1,
|
|
31
|
+
DEPTH: 2,
|
|
32
|
+
RELIABILITY: 3,
|
|
33
|
+
DURABILITY: 4,
|
|
34
|
+
LIVELINESS: 5,
|
|
35
|
+
AVOID_ROS_NAMESPACE_CONVENTIONS: 6,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Maps QoSPolicyKind -> { qosProp, paramKey, paramType, toParam, fromParam }
|
|
39
|
+
const POLICY_MAP = {
|
|
40
|
+
[QoSPolicyKind.HISTORY]: {
|
|
41
|
+
qosProp: 'history',
|
|
42
|
+
paramKey: 'history',
|
|
43
|
+
enumObj: QoS.HistoryPolicy,
|
|
44
|
+
paramType: ParameterType.PARAMETER_STRING,
|
|
45
|
+
toParam: (val, enumObj) => _enumToString(val, enumObj),
|
|
46
|
+
fromParam: (val, enumObj) => _stringToEnum(val, enumObj),
|
|
47
|
+
},
|
|
48
|
+
[QoSPolicyKind.DEPTH]: {
|
|
49
|
+
qosProp: 'depth',
|
|
50
|
+
paramKey: 'depth',
|
|
51
|
+
paramType: ParameterType.PARAMETER_INTEGER,
|
|
52
|
+
toParam: (val) => BigInt(val),
|
|
53
|
+
fromParam: (val) => Number(val),
|
|
54
|
+
},
|
|
55
|
+
[QoSPolicyKind.RELIABILITY]: {
|
|
56
|
+
qosProp: 'reliability',
|
|
57
|
+
paramKey: 'reliability',
|
|
58
|
+
enumObj: QoS.ReliabilityPolicy,
|
|
59
|
+
paramType: ParameterType.PARAMETER_STRING,
|
|
60
|
+
toParam: (val, enumObj) => _enumToString(val, enumObj),
|
|
61
|
+
fromParam: (val, enumObj) => _stringToEnum(val, enumObj),
|
|
62
|
+
},
|
|
63
|
+
[QoSPolicyKind.DURABILITY]: {
|
|
64
|
+
qosProp: 'durability',
|
|
65
|
+
paramKey: 'durability',
|
|
66
|
+
enumObj: QoS.DurabilityPolicy,
|
|
67
|
+
paramType: ParameterType.PARAMETER_STRING,
|
|
68
|
+
toParam: (val, enumObj) => _enumToString(val, enumObj),
|
|
69
|
+
fromParam: (val, enumObj) => _stringToEnum(val, enumObj),
|
|
70
|
+
},
|
|
71
|
+
[QoSPolicyKind.LIVELINESS]: {
|
|
72
|
+
qosProp: 'liveliness',
|
|
73
|
+
paramKey: 'liveliness',
|
|
74
|
+
enumObj: QoS.LivelinessPolicy,
|
|
75
|
+
paramType: ParameterType.PARAMETER_STRING,
|
|
76
|
+
toParam: (val, enumObj) => _enumToString(val, enumObj),
|
|
77
|
+
fromParam: (val, enumObj) => _stringToEnum(val, enumObj),
|
|
78
|
+
},
|
|
79
|
+
[QoSPolicyKind.AVOID_ROS_NAMESPACE_CONVENTIONS]: {
|
|
80
|
+
qosProp: 'avoidRosNameSpaceConventions',
|
|
81
|
+
paramKey: 'avoid_ros_namespace_conventions',
|
|
82
|
+
paramType: ParameterType.PARAMETER_BOOL,
|
|
83
|
+
toParam: (val) => val,
|
|
84
|
+
fromParam: (val) => Boolean(val),
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Convert a numeric enum value to a lowercase string name.
|
|
90
|
+
* @param {number} val - enum numeric value
|
|
91
|
+
* @param {Object} enumObj - the enum object (e.g. QoS.HistoryPolicy)
|
|
92
|
+
* @returns {string}
|
|
93
|
+
*/
|
|
94
|
+
function _enumToString(val, enumObj) {
|
|
95
|
+
for (const [key, v] of Object.entries(enumObj)) {
|
|
96
|
+
if (v === val) {
|
|
97
|
+
// Strip the RMW prefix: "RMW_QOS_POLICY_HISTORY_KEEP_LAST" -> "keep_last"
|
|
98
|
+
const parts = key.split('_');
|
|
99
|
+
// Find the index after the policy name (HISTORY, RELIABILITY, etc.)
|
|
100
|
+
// Pattern: RMW_QOS_POLICY_<POLICY>_<VALUE>
|
|
101
|
+
const policyNames = [
|
|
102
|
+
'HISTORY',
|
|
103
|
+
'RELIABILITY',
|
|
104
|
+
'DURABILITY',
|
|
105
|
+
'LIVELINESS',
|
|
106
|
+
];
|
|
107
|
+
let valueStart = 4; // default: skip RMW_QOS_POLICY_<X>_
|
|
108
|
+
for (let i = 3; i < parts.length; i++) {
|
|
109
|
+
if (policyNames.includes(parts[i])) {
|
|
110
|
+
valueStart = i + 1;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return parts.slice(valueStart).join('_').toLowerCase();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return String(val);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Convert a lowercase string back to a numeric enum value.
|
|
122
|
+
* @param {string} str - the string value (e.g. "keep_last")
|
|
123
|
+
* @param {Object} enumObj - the enum object
|
|
124
|
+
* @returns {number}
|
|
125
|
+
*/
|
|
126
|
+
function _stringToEnum(str, enumObj) {
|
|
127
|
+
const upper = str.toUpperCase();
|
|
128
|
+
for (const [key, val] of Object.entries(enumObj)) {
|
|
129
|
+
if (key.endsWith('_' + upper)) {
|
|
130
|
+
return val;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
throw new Error(`Unknown QoS policy value: "${str}"`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Options for overriding QoS policies via ROS parameters.
|
|
138
|
+
*
|
|
139
|
+
* When passed to `createPublisher()` or `createSubscription()`, the node
|
|
140
|
+
* will declare read-only parameters for each specified policy kind. These
|
|
141
|
+
* parameters can be set via command-line arguments, launch files, or
|
|
142
|
+
* parameter files to override the QoS profile at startup.
|
|
143
|
+
*
|
|
144
|
+
* Parameter naming convention:
|
|
145
|
+
* `qos_overrides.<topic>.<publisher|subscription>[_<entityId>].<policy>`
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* // Override history, depth, and reliability via parameters
|
|
149
|
+
* const sub = node.createSubscription(
|
|
150
|
+
* 'std_msgs/msg/String', '/chatter',
|
|
151
|
+
* { qos: rclnodejs.QoS.profileDefault,
|
|
152
|
+
* qosOverridingOptions: QoSOverridingOptions.withDefaultPolicies() },
|
|
153
|
+
* (msg) => console.log(msg.data)
|
|
154
|
+
* );
|
|
155
|
+
* // Now you can override via CLI:
|
|
156
|
+
* // --ros-args -p "qos_overrides./chatter.subscription.depth:=20"
|
|
157
|
+
*/
|
|
158
|
+
class QoSOverridingOptions {
|
|
159
|
+
/**
|
|
160
|
+
* @param {Array<QoSPolicyKind>} policyKinds - Which QoS policies to expose as parameters.
|
|
161
|
+
* @param {Object} [opts]
|
|
162
|
+
* @param {function} [opts.callback] - Optional validation callback. Receives the
|
|
163
|
+
* final QoS profile after overrides are applied. Should return
|
|
164
|
+
* `{successful: true}` or `{successful: false, reason: '...'}`.
|
|
165
|
+
* @param {string} [opts.entityId] - Optional suffix to disambiguate multiple
|
|
166
|
+
* publishers/subscriptions on the same topic.
|
|
167
|
+
*/
|
|
168
|
+
constructor(policyKinds, opts = {}) {
|
|
169
|
+
this._policyKinds = Array.from(policyKinds);
|
|
170
|
+
this._callback = opts.callback || null;
|
|
171
|
+
this._entityId = opts.entityId || null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
get policyKinds() {
|
|
175
|
+
return this._policyKinds;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
get callback() {
|
|
179
|
+
return this._callback;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
get entityId() {
|
|
183
|
+
return this._entityId;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Create options that override history, depth, and reliability —
|
|
188
|
+
* the most commonly tuned policies.
|
|
189
|
+
* @param {Object} [opts]
|
|
190
|
+
* @param {function} [opts.callback] - Validation callback.
|
|
191
|
+
* @param {string} [opts.entityId] - Entity disambiguation suffix.
|
|
192
|
+
* @returns {QoSOverridingOptions}
|
|
193
|
+
*/
|
|
194
|
+
static withDefaultPolicies(opts = {}) {
|
|
195
|
+
return new QoSOverridingOptions(
|
|
196
|
+
[QoSPolicyKind.HISTORY, QoSPolicyKind.DEPTH, QoSPolicyKind.RELIABILITY],
|
|
197
|
+
opts
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Resolve QoS profile string to a mutable QoS object.
|
|
204
|
+
* If already a QoS instance, return as-is.
|
|
205
|
+
* @param {QoS|string} qos
|
|
206
|
+
* @returns {QoS}
|
|
207
|
+
*/
|
|
208
|
+
function _resolveQoS(qos) {
|
|
209
|
+
if (qos instanceof QoS) {
|
|
210
|
+
return qos;
|
|
211
|
+
}
|
|
212
|
+
// Plain object with QoS fields — construct a QoS from its properties
|
|
213
|
+
if (typeof qos === 'object' && qos !== null && !Array.isArray(qos)) {
|
|
214
|
+
return new QoS(
|
|
215
|
+
qos.history,
|
|
216
|
+
qos.depth,
|
|
217
|
+
qos.reliability,
|
|
218
|
+
qos.durability,
|
|
219
|
+
qos.liveliness,
|
|
220
|
+
qos.avoidRosNameSpaceConventions
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
// Profile string: create a QoS with the corresponding defaults
|
|
224
|
+
// Values must match the rmw_qos_profile_* definitions in rmw/types.h
|
|
225
|
+
switch (qos) {
|
|
226
|
+
case QoS.profileDefault:
|
|
227
|
+
return new QoS(
|
|
228
|
+
QoS.HistoryPolicy.RMW_QOS_POLICY_HISTORY_KEEP_LAST,
|
|
229
|
+
10,
|
|
230
|
+
QoS.ReliabilityPolicy.RMW_QOS_POLICY_RELIABILITY_RELIABLE,
|
|
231
|
+
QoS.DurabilityPolicy.RMW_QOS_POLICY_DURABILITY_VOLATILE
|
|
232
|
+
);
|
|
233
|
+
case QoS.profileSystemDefault:
|
|
234
|
+
return new QoS(
|
|
235
|
+
QoS.HistoryPolicy.RMW_QOS_POLICY_HISTORY_SYSTEM_DEFAULT,
|
|
236
|
+
0,
|
|
237
|
+
QoS.ReliabilityPolicy.RMW_QOS_POLICY_RELIABILITY_SYSTEM_DEFAULT,
|
|
238
|
+
QoS.DurabilityPolicy.RMW_QOS_POLICY_DURABILITY_SYSTEM_DEFAULT,
|
|
239
|
+
QoS.LivelinessPolicy.RMW_QOS_POLICY_LIVELINESS_SYSTEM_DEFAULT
|
|
240
|
+
);
|
|
241
|
+
case QoS.profileSensorData:
|
|
242
|
+
return new QoS(
|
|
243
|
+
QoS.HistoryPolicy.RMW_QOS_POLICY_HISTORY_KEEP_LAST,
|
|
244
|
+
5,
|
|
245
|
+
QoS.ReliabilityPolicy.RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT,
|
|
246
|
+
QoS.DurabilityPolicy.RMW_QOS_POLICY_DURABILITY_VOLATILE
|
|
247
|
+
);
|
|
248
|
+
case QoS.profileServicesDefault:
|
|
249
|
+
return new QoS(
|
|
250
|
+
QoS.HistoryPolicy.RMW_QOS_POLICY_HISTORY_KEEP_LAST,
|
|
251
|
+
10,
|
|
252
|
+
QoS.ReliabilityPolicy.RMW_QOS_POLICY_RELIABILITY_RELIABLE,
|
|
253
|
+
QoS.DurabilityPolicy.RMW_QOS_POLICY_DURABILITY_VOLATILE
|
|
254
|
+
);
|
|
255
|
+
case QoS.profileParameters:
|
|
256
|
+
return new QoS(
|
|
257
|
+
QoS.HistoryPolicy.RMW_QOS_POLICY_HISTORY_KEEP_LAST,
|
|
258
|
+
1000,
|
|
259
|
+
QoS.ReliabilityPolicy.RMW_QOS_POLICY_RELIABILITY_RELIABLE,
|
|
260
|
+
QoS.DurabilityPolicy.RMW_QOS_POLICY_DURABILITY_VOLATILE
|
|
261
|
+
);
|
|
262
|
+
case QoS.profileParameterEvents:
|
|
263
|
+
return new QoS(
|
|
264
|
+
QoS.HistoryPolicy.RMW_QOS_POLICY_HISTORY_KEEP_LAST,
|
|
265
|
+
1000,
|
|
266
|
+
QoS.ReliabilityPolicy.RMW_QOS_POLICY_RELIABILITY_RELIABLE,
|
|
267
|
+
QoS.DurabilityPolicy.RMW_QOS_POLICY_DURABILITY_VOLATILE
|
|
268
|
+
);
|
|
269
|
+
case QoS.profileActionStatusDefault:
|
|
270
|
+
return new QoS(
|
|
271
|
+
QoS.HistoryPolicy.RMW_QOS_POLICY_HISTORY_KEEP_LAST,
|
|
272
|
+
1,
|
|
273
|
+
QoS.ReliabilityPolicy.RMW_QOS_POLICY_RELIABILITY_RELIABLE,
|
|
274
|
+
QoS.DurabilityPolicy.RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL
|
|
275
|
+
);
|
|
276
|
+
default:
|
|
277
|
+
return new QoS(
|
|
278
|
+
QoS.HistoryPolicy.RMW_QOS_POLICY_HISTORY_KEEP_LAST,
|
|
279
|
+
10,
|
|
280
|
+
QoS.ReliabilityPolicy.RMW_QOS_POLICY_RELIABILITY_RELIABLE,
|
|
281
|
+
QoS.DurabilityPolicy.RMW_QOS_POLICY_DURABILITY_VOLATILE
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Declare QoS override parameters on the node and apply any overrides
|
|
288
|
+
* to the QoS profile in-place.
|
|
289
|
+
*
|
|
290
|
+
* @param {'publisher'|'subscription'} entityType
|
|
291
|
+
* @param {Node} node
|
|
292
|
+
* @param {string} topic - Fully resolved topic name.
|
|
293
|
+
* @param {QoS} qos - Mutable QoS object (will be modified in-place).
|
|
294
|
+
* @param {QoSOverridingOptions} options
|
|
295
|
+
*/
|
|
296
|
+
function declareQosParameters(entityType, node, topic, qos, options) {
|
|
297
|
+
if (!options || options.policyKinds.length === 0) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const idSuffix = options.entityId ? `_${options.entityId}` : '';
|
|
302
|
+
const namePrefix = `qos_overrides.${topic}.${entityType}${idSuffix}`;
|
|
303
|
+
|
|
304
|
+
for (const policyKind of options.policyKinds) {
|
|
305
|
+
const mapping = POLICY_MAP[policyKind];
|
|
306
|
+
if (!mapping) {
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const paramName = `${namePrefix}.${mapping.paramKey}`;
|
|
311
|
+
const currentValue = qos[mapping.qosProp];
|
|
312
|
+
const paramValue = mapping.toParam(currentValue, mapping.enumObj);
|
|
313
|
+
|
|
314
|
+
const descriptor = new ParameterDescriptor(
|
|
315
|
+
paramName,
|
|
316
|
+
mapping.paramType,
|
|
317
|
+
`QoS override for ${mapping.qosProp}`,
|
|
318
|
+
true // readOnly
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
let param;
|
|
322
|
+
try {
|
|
323
|
+
param = node.declareParameter(
|
|
324
|
+
new Parameter(paramName, mapping.paramType, paramValue),
|
|
325
|
+
descriptor
|
|
326
|
+
);
|
|
327
|
+
} catch (e) {
|
|
328
|
+
// Already declared (e.g. multiple entities on same topic) — reuse
|
|
329
|
+
if (node.hasParameter(paramName)) {
|
|
330
|
+
param = node.getParameter(paramName);
|
|
331
|
+
} else {
|
|
332
|
+
throw e;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// Apply the (possibly overridden) parameter value back to QoS
|
|
337
|
+
if (param && param.value !== paramValue) {
|
|
338
|
+
qos[mapping.qosProp] = mapping.fromParam(param.value, mapping.enumObj);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// Run validation callback if provided
|
|
343
|
+
if (options.callback) {
|
|
344
|
+
const result = options.callback(qos);
|
|
345
|
+
if (result && !result.successful) {
|
|
346
|
+
throw new Error(
|
|
347
|
+
`QoS override validation failed: ${result.reason || 'unknown reason'}`
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
module.exports = {
|
|
354
|
+
QoSPolicyKind,
|
|
355
|
+
QoSOverridingOptions,
|
|
356
|
+
declareQosParameters,
|
|
357
|
+
_resolveQoS,
|
|
358
|
+
};
|
package/lib/subscription.js
CHANGED
|
@@ -16,14 +16,16 @@
|
|
|
16
16
|
|
|
17
17
|
const rclnodejs = require('./native_loader.js');
|
|
18
18
|
const Entity = require('./entity.js');
|
|
19
|
+
const DistroUtils = require('./distro.js');
|
|
19
20
|
const { applySerializationMode } = require('./message_serialization.js');
|
|
20
21
|
const debug = require('debug')('rclnodejs:subscription');
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* @class - Class representing a ROS 2 Subscription
|
|
24
|
-
* @hideconstructor
|
|
25
25
|
* Includes support for content-filtering topics beginning with the
|
|
26
|
-
* ROS Humble release. To learn more about content-filtering
|
|
26
|
+
* ROS Humble release. To learn more about content-filtering topics,
|
|
27
|
+
* see the references below.
|
|
28
|
+
* @hideconstructor
|
|
27
29
|
* @see {@link Node#options}
|
|
28
30
|
* @see {@link Node#createSubscription}
|
|
29
31
|
* @see {@link https://www.omg.org/spec/DDS/1.4/PDF|DDS 1.4 specification, Annex B}
|
|
@@ -45,6 +47,7 @@ class Subscription extends Entity {
|
|
|
45
47
|
this._isRaw = options.isRaw || false;
|
|
46
48
|
this._serializationMode = options.serializationMode || 'default';
|
|
47
49
|
this._node = node;
|
|
50
|
+
this._wantsMessageInfo = callback.length >= 2;
|
|
48
51
|
|
|
49
52
|
if (node && eventCallbacks) {
|
|
50
53
|
this._events = eventCallbacks.createEventHandlers(this.handle);
|
|
@@ -52,10 +55,24 @@ class Subscription extends Entity {
|
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
57
|
|
|
55
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Whether this subscription's callback wants MessageInfo as a second argument.
|
|
60
|
+
* Determined by callback.length >= 2.
|
|
61
|
+
* @type {boolean}
|
|
62
|
+
* @readonly
|
|
63
|
+
*/
|
|
64
|
+
get wantsMessageInfo() {
|
|
65
|
+
return this._wantsMessageInfo;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
processResponse(msg, messageInfo) {
|
|
56
69
|
debug(`Message of topic ${this._topic} received.`);
|
|
57
70
|
if (this._isRaw) {
|
|
58
|
-
this.
|
|
71
|
+
if (this._wantsMessageInfo && messageInfo) {
|
|
72
|
+
this._callback(msg, messageInfo);
|
|
73
|
+
} else {
|
|
74
|
+
this._callback(msg);
|
|
75
|
+
}
|
|
59
76
|
} else {
|
|
60
77
|
let message = msg.toPlainObject(this.typedArrayEnabled);
|
|
61
78
|
|
|
@@ -63,7 +80,11 @@ class Subscription extends Entity {
|
|
|
63
80
|
message = applySerializationMode(message, this._serializationMode);
|
|
64
81
|
}
|
|
65
82
|
|
|
66
|
-
this.
|
|
83
|
+
if (this._wantsMessageInfo && messageInfo) {
|
|
84
|
+
this._callback(message, messageInfo);
|
|
85
|
+
} else {
|
|
86
|
+
this._callback(message);
|
|
87
|
+
}
|
|
67
88
|
}
|
|
68
89
|
}
|
|
69
90
|
|
|
@@ -124,6 +145,18 @@ class Subscription extends Entity {
|
|
|
124
145
|
return this._serializationMode;
|
|
125
146
|
}
|
|
126
147
|
|
|
148
|
+
/**
|
|
149
|
+
* Check if content filtering is supported for this subscription.
|
|
150
|
+
* Requires ROS 2 Rolling or later.
|
|
151
|
+
* @returns {boolean} True if the subscription instance supports content filtering; otherwise false.
|
|
152
|
+
*/
|
|
153
|
+
isContentFilterSupported() {
|
|
154
|
+
if (DistroUtils.getDistroId() < DistroUtils.DistroId.ROLLING) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
return rclnodejs.isContentFilterSupported(this.handle);
|
|
158
|
+
}
|
|
159
|
+
|
|
127
160
|
/**
|
|
128
161
|
* Test if the RMW supports content-filtered topics and that this subscription
|
|
129
162
|
* has an active wellformed content-filter.
|
package/lib/timer.js
CHANGED
|
@@ -30,7 +30,8 @@ class Timer {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* The period of the timer in nanoseconds.
|
|
34
|
+
* @type {bigint}
|
|
34
35
|
*/
|
|
35
36
|
get period() {
|
|
36
37
|
return this._period;
|
|
@@ -149,7 +150,7 @@ class Timer {
|
|
|
149
150
|
|
|
150
151
|
/**
|
|
151
152
|
* Call a timer and starts counting again, retrieves actual and expected call time.
|
|
152
|
-
* @return {
|
|
153
|
+
* @return {{expectedCallTime: bigint, actualCallTime: bigint}} - The timer information.
|
|
153
154
|
*/
|
|
154
155
|
callTimerWithInfo() {
|
|
155
156
|
if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('humble')) {
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Copyright (c) 2026, The Robot Web Tools Contributors
|
|
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
|
+
'use strict';
|
|
16
|
+
|
|
17
|
+
const { TimeoutError } = require('./errors.js');
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Wait for a single message on a topic.
|
|
21
|
+
*
|
|
22
|
+
* Creates a temporary subscription, waits for the first message to arrive,
|
|
23
|
+
* and returns it. The temporary subscription is always cleaned up, even on
|
|
24
|
+
* timeout or error. The node must be spinning before calling this function.
|
|
25
|
+
*
|
|
26
|
+
* This is the rclnodejs equivalent of rclpy's `wait_for_message`.
|
|
27
|
+
*
|
|
28
|
+
* @param {function|string|object} typeClass - The ROS message type class.
|
|
29
|
+
* @param {Node} node - The node to create the temporary subscription on.
|
|
30
|
+
* @param {string} topic - The topic name to listen on.
|
|
31
|
+
* @param {object} [options] - Options.
|
|
32
|
+
* @param {number} [options.timeout] - Timeout in milliseconds. If omitted, waits indefinitely.
|
|
33
|
+
* @param {object} [options.qos] - QoS profile for the subscription.
|
|
34
|
+
* @returns {Promise<object>} - Resolves with the received message.
|
|
35
|
+
* @throws {Error} If timeout expires before a message arrives.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* node.spin();
|
|
39
|
+
* const msg = await waitForMessage(
|
|
40
|
+
* 'std_msgs/msg/String',
|
|
41
|
+
* node,
|
|
42
|
+
* '/my_topic',
|
|
43
|
+
* { timeout: 5000 }
|
|
44
|
+
* );
|
|
45
|
+
* console.log('Received:', msg.data);
|
|
46
|
+
*/
|
|
47
|
+
function waitForMessage(typeClass, node, topic, options = {}) {
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
let subscription = null;
|
|
50
|
+
let timer = null;
|
|
51
|
+
let settled = false;
|
|
52
|
+
|
|
53
|
+
const cleanup = () => {
|
|
54
|
+
if (timer) {
|
|
55
|
+
clearTimeout(timer);
|
|
56
|
+
timer = null;
|
|
57
|
+
}
|
|
58
|
+
if (subscription) {
|
|
59
|
+
try {
|
|
60
|
+
node.destroySubscription(subscription);
|
|
61
|
+
} catch {
|
|
62
|
+
// Subscription may already be destroyed if node is shutting down
|
|
63
|
+
}
|
|
64
|
+
subscription = null;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const settle = (err, msg) => {
|
|
69
|
+
if (settled) return;
|
|
70
|
+
settled = true;
|
|
71
|
+
cleanup();
|
|
72
|
+
if (err) {
|
|
73
|
+
reject(err);
|
|
74
|
+
} else {
|
|
75
|
+
resolve(msg);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
const subOptions = {};
|
|
81
|
+
if (options.qos) {
|
|
82
|
+
subOptions.qos = options.qos;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
subscription = node.createSubscription(
|
|
86
|
+
typeClass,
|
|
87
|
+
topic,
|
|
88
|
+
subOptions,
|
|
89
|
+
(msg) => {
|
|
90
|
+
settle(null, msg);
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
if (options.timeout != null && options.timeout >= 0) {
|
|
95
|
+
timer = setTimeout(() => {
|
|
96
|
+
settle(
|
|
97
|
+
new TimeoutError(
|
|
98
|
+
`waitForMessage timed out after ${options.timeout}ms on topic '${topic}'`,
|
|
99
|
+
{ entityType: 'topic', entityName: topic }
|
|
100
|
+
)
|
|
101
|
+
);
|
|
102
|
+
}, options.timeout);
|
|
103
|
+
}
|
|
104
|
+
} catch (err) {
|
|
105
|
+
cleanup();
|
|
106
|
+
reject(err);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
module.exports = waitForMessage;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rclnodejs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "ROS2.0 JavaScript client with Node.js",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -24,10 +24,13 @@
|
|
|
24
24
|
"clean": "node-gyp clean && npx rimraf ./generated",
|
|
25
25
|
"install": "node scripts/install.js",
|
|
26
26
|
"postinstall": "npm run generate-messages",
|
|
27
|
-
"docs": "
|
|
27
|
+
"docs": "make -C tools/jsdoc",
|
|
28
|
+
"docs:gh-pages": "node tools/jsdoc/regenerate-published-docs.js --branch origin/gh-pages --preserve-published",
|
|
29
|
+
"docs:gh-pages:full": "node tools/jsdoc/regenerate-published-docs.js --branch origin/gh-pages --full-rebuild",
|
|
28
30
|
"test": "nyc node --expose-gc ./scripts/run_test.js && tsd && npm install --no-save electron && node test/electron/run_test.js",
|
|
29
31
|
"test-idl": "nyc node --expose-gc ./scripts/run_test.js --idl",
|
|
30
32
|
"lint": "eslint && node ./scripts/cpplint.js",
|
|
33
|
+
"test:asan": "bash scripts/run_asan_test.sh",
|
|
31
34
|
"format": "clang-format -i -style=file ./src/*.cpp ./src/*.h && npx --yes prettier --write \"{lib,rosidl_gen,rostsd_gen,rosidl_parser,types,example,test,scripts,benchmark,rostsd_gen}/**/*.{js,md,ts}\" ./*.{js,md,ts}",
|
|
32
35
|
"prepare": "husky",
|
|
33
36
|
"coverage": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
|
|
@@ -64,14 +67,14 @@
|
|
|
64
67
|
"jsdoc": "^4.0.4",
|
|
65
68
|
"lint-staged": "^16.2.0",
|
|
66
69
|
"mocha": "^11.0.2",
|
|
67
|
-
"node-gyp": "^
|
|
70
|
+
"node-gyp": "^10.3.1",
|
|
68
71
|
"nyc": "^18.0.0",
|
|
69
72
|
"prebuildify": "^6.0.1",
|
|
70
73
|
"rimraf": "^6.0.1",
|
|
71
74
|
"sinon": "^21.0.0",
|
|
72
75
|
"tree-kill": "^1.2.2",
|
|
73
76
|
"tsd": "^0.33.0",
|
|
74
|
-
"typescript": "^
|
|
77
|
+
"typescript": "^6.0.2"
|
|
75
78
|
},
|
|
76
79
|
"dependencies": {
|
|
77
80
|
"@rclnodejs/ref-array-di": "^1.2.2",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|