rclnodejs 1.0.0 → 1.2.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 +6 -6
- package/binding.gyp +12 -0
- package/lib/action/client.js +40 -0
- package/lib/action/server.js +21 -0
- package/lib/client.js +1 -1
- package/lib/distro.js +2 -0
- package/lib/event_handler.js +474 -0
- package/lib/lifecycle.js +9 -0
- package/lib/lifecycle_publisher.js +2 -2
- package/lib/node.js +85 -11
- package/lib/node_options.js +21 -1
- package/lib/publisher.js +50 -4
- package/lib/service.js +1 -1
- package/lib/subscription.js +48 -4
- package/lib/type_description_service.js +82 -0
- package/package.json +1 -1
- package/scripts/npmjs-readme.md +6 -6
- package/src/addon.cpp +8 -0
- package/src/executor.cpp +3 -4
- package/src/handle_manager.cpp +13 -2
- package/src/handle_manager.h +4 -1
- package/src/rcl_action_client_bindings.cpp +99 -24
- package/src/rcl_action_server_bindings.cpp +69 -19
- package/src/rcl_event_handle_bindings.cpp +294 -0
- package/src/rcl_event_handle_bindings.h +26 -0
- package/src/rcl_lifecycle_bindings.cpp +13 -0
- package/src/rcl_node_bindings.cpp +43 -8
- package/src/rcl_publisher_bindings.cpp +19 -0
- package/src/rcl_type_description_service_bindings.cpp +79 -0
- package/src/rcl_type_description_service_bindings.h +27 -0
- package/types/action_client.d.ts +18 -0
- package/types/action_server.d.ts +12 -0
- package/types/lifecycle.d.ts +7 -0
- package/types/node.d.ts +44 -2
- package/types/publisher.d.ts +17 -0
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# rclnodejs ](https://github.com/RobotWebTools/rclnodejs/actions/workflows/linux-x64-build-and-test.yml?query=branch%3Adevelop)[](https://github.com/RobotWebTools/rclnodejs/actions/workflows/linux-arm64-build-and-test.yml?query=branch%3Adevelop)
|
|
2
2
|
|
|
3
3
|
`rclnodejs` is a Node.js client for the Robot Operating System (ROS 2). It provides a simple and easy JavaScript API for ROS 2 programming. TypeScript declarations are included to support use of rclnodejs in TypeScript projects.
|
|
4
4
|
|
|
@@ -22,8 +22,8 @@ rclnodejs.init().then(() => {
|
|
|
22
22
|
|
|
23
23
|
**ROS 2 SDK**
|
|
24
24
|
|
|
25
|
-
- See the ROS 2 SDK [Installation Guide](https://docs.ros.org/en/
|
|
26
|
-
- **DON'T FORGET TO [SOURCE THE ROS 2 STARTUP FILES](https://docs.ros.org/en/
|
|
25
|
+
- See the ROS 2 SDK [Installation Guide](https://docs.ros.org/en/kilted/Installation.html) for details.
|
|
26
|
+
- **DON'T FORGET TO [SOURCE THE ROS 2 STARTUP FILES](https://docs.ros.org/en/kilted/Tutorials/Beginner-CLI-Tools/Configuring-ROS2-Environment.htmls)**
|
|
27
27
|
|
|
28
28
|
## Install rclnodejs
|
|
29
29
|
|
|
@@ -43,9 +43,9 @@ npm i rclnodejs@x.y.z
|
|
|
43
43
|
|
|
44
44
|
#### RCLNODEJS - ROS 2 Version Compatibility
|
|
45
45
|
|
|
46
|
-
| RCLNODEJS Version |
|
|
47
|
-
| :----------------------------------------------------------------------------------------: |
|
|
48
|
-
| latest version (currently [v1.
|
|
46
|
+
| RCLNODEJS Version | Compatible ROS 2 LTS |
|
|
47
|
+
| :----------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
|
|
48
|
+
| latest version (currently [v1.2.0](https://github.com/RobotWebTools/rclnodejs/tree/1.2.0)) | [Kilted](https://github.com/RobotWebTools/rclnodejs/tree/kilted)<br>[Jazzy](https://github.com/RobotWebTools/rclnodejs/tree/jazzy)<br>[Humble](https://github.com/RobotWebTools/rclnodejs/tree/humble-hawksbill) |
|
|
49
49
|
|
|
50
50
|
## Documentation
|
|
51
51
|
|
package/binding.gyp
CHANGED
|
@@ -120,6 +120,9 @@
|
|
|
120
120
|
'include_dirs': [
|
|
121
121
|
'./src/third_party/dlfcn-win32/',
|
|
122
122
|
],
|
|
123
|
+
'libraries': [
|
|
124
|
+
'-lrmw_fastrtps_cpp',
|
|
125
|
+
],
|
|
123
126
|
'msvs_settings': {
|
|
124
127
|
'VCCLCompilerTool': {
|
|
125
128
|
'ExceptionHandling': '2', # /EHsc
|
|
@@ -166,6 +169,15 @@
|
|
|
166
169
|
]
|
|
167
170
|
}
|
|
168
171
|
],
|
|
172
|
+
[
|
|
173
|
+
# After Humble, e.g., Jazzy, Kilted.
|
|
174
|
+
'ros_version > 2205', {
|
|
175
|
+
'sources': [
|
|
176
|
+
'./src/rcl_event_handle_bindings.cpp',
|
|
177
|
+
'./src/rcl_type_description_service_bindings.cpp',
|
|
178
|
+
]
|
|
179
|
+
}
|
|
180
|
+
],
|
|
169
181
|
[
|
|
170
182
|
'runtime=="electron"', {
|
|
171
183
|
"defines": ["NODE_RUNTIME_ELECTRON=1"]
|
package/lib/action/client.js
CHANGED
|
@@ -19,6 +19,7 @@ const ActionInterfaces = require('./interfaces.js');
|
|
|
19
19
|
const ActionUuid = require('./uuid.js');
|
|
20
20
|
const ClientGoalHandle = require('./client_goal_handle.js');
|
|
21
21
|
const Deferred = require('./deferred.js');
|
|
22
|
+
const DistroUtils = require('../distro.js');
|
|
22
23
|
const Entity = require('../entity.js');
|
|
23
24
|
const loader = require('../interface_loader.js');
|
|
24
25
|
const QoS = require('../qos.js');
|
|
@@ -371,6 +372,45 @@ class ActionClient extends Entity {
|
|
|
371
372
|
|
|
372
373
|
this._node._destroyEntity(this, this._node._actionClients);
|
|
373
374
|
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Get the number of wait set entities that make up an action entity.
|
|
378
|
+
* @return {object} - An object containing the number of various entities.
|
|
379
|
+
* @property {number} subscriptionsNumber - The number of subscriptions.
|
|
380
|
+
* @property {number} guardConditionsNumber - The number of guard conditions.
|
|
381
|
+
* @property {number} timersNumber - The number of timers.
|
|
382
|
+
* @property {number} clientsNumber - The number of clients.
|
|
383
|
+
* @property {number} servicesNumber - The number of services.
|
|
384
|
+
*/
|
|
385
|
+
getNumEntities() {
|
|
386
|
+
return rclnodejs.getNumEntities(this.handle);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Configure introspection.
|
|
391
|
+
* @param {Clock} clock - Clock to use for service event timestamps
|
|
392
|
+
* @param {QoS} qos - QoSProfile for the service event publisher
|
|
393
|
+
* @param {ServiceIntrospectionState} introspectionState - State to set introspection to
|
|
394
|
+
*/
|
|
395
|
+
configureIntrospection(clock, qos, introspectionState) {
|
|
396
|
+
if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('jazzy')) {
|
|
397
|
+
console.warn(
|
|
398
|
+
'Configure action client introspection is not supported by this version of ROS 2'
|
|
399
|
+
);
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
let type = this.typeClass.type();
|
|
404
|
+
rclnodejs.configureActionClientIntrospection(
|
|
405
|
+
this.handle,
|
|
406
|
+
this._node.handle,
|
|
407
|
+
clock.handle,
|
|
408
|
+
type.interfaceName,
|
|
409
|
+
type.pkgName,
|
|
410
|
+
qos,
|
|
411
|
+
introspectionState
|
|
412
|
+
);
|
|
413
|
+
}
|
|
374
414
|
}
|
|
375
415
|
|
|
376
416
|
module.exports = ActionClient;
|
package/lib/action/server.js
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
const rclnodejs = require('bindings')('rclnodejs');
|
|
18
18
|
const ActionInterfaces = require('./interfaces.js');
|
|
19
19
|
const ActionUuid = require('./uuid.js');
|
|
20
|
+
const DistroUtils = require('../distro.js');
|
|
20
21
|
const Entity = require('../entity.js');
|
|
21
22
|
const { CancelResponse, GoalEvent, GoalResponse } = require('./response.js');
|
|
22
23
|
const loader = require('../interface_loader.js');
|
|
@@ -454,6 +455,26 @@ class ActionServer extends Entity {
|
|
|
454
455
|
|
|
455
456
|
this._node._destroyEntity(this, this._node._actionServers);
|
|
456
457
|
}
|
|
458
|
+
|
|
459
|
+
configureIntrospection(clock, qos, introspectionState) {
|
|
460
|
+
if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('jazzy')) {
|
|
461
|
+
console.warn(
|
|
462
|
+
'Configure action server introspection is not supported by this version of ROS 2'
|
|
463
|
+
);
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
let type = this.typeClass.type();
|
|
468
|
+
rclnodejs.configureActionServerIntrospection(
|
|
469
|
+
this.handle,
|
|
470
|
+
this._node.handle,
|
|
471
|
+
clock.handle,
|
|
472
|
+
type.interfaceName,
|
|
473
|
+
type.pkgName,
|
|
474
|
+
qos,
|
|
475
|
+
introspectionState
|
|
476
|
+
);
|
|
477
|
+
}
|
|
457
478
|
}
|
|
458
479
|
|
|
459
480
|
module.exports = ActionServer;
|
package/lib/client.js
CHANGED
|
@@ -141,7 +141,7 @@ class Client extends Entity {
|
|
|
141
141
|
configureIntrospection(clock, qos, introspectionState) {
|
|
142
142
|
if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('humble')) {
|
|
143
143
|
console.warn(
|
|
144
|
-
'Service introspection is not supported by this
|
|
144
|
+
'Service introspection is not supported by this version of ROS 2'
|
|
145
145
|
);
|
|
146
146
|
return;
|
|
147
147
|
}
|
package/lib/distro.js
CHANGED
|
@@ -25,6 +25,7 @@ const DistroId = {
|
|
|
25
25
|
HUMBLE: 2205,
|
|
26
26
|
IRON: 2305,
|
|
27
27
|
JAZZY: 2405,
|
|
28
|
+
KILTED: 2505,
|
|
28
29
|
ROLLING: 5000,
|
|
29
30
|
};
|
|
30
31
|
|
|
@@ -35,6 +36,7 @@ DistroNameIdMap.set('galactic', DistroId.GALACTIC);
|
|
|
35
36
|
DistroNameIdMap.set('humble', DistroId.HUMBLE);
|
|
36
37
|
DistroNameIdMap.set('iron', DistroId.IRON);
|
|
37
38
|
DistroNameIdMap.set('jazzy', DistroId.JAZZY);
|
|
39
|
+
DistroNameIdMap.set('kilted', DistroId.KILTED);
|
|
38
40
|
DistroNameIdMap.set('rolling', DistroId.ROLLING);
|
|
39
41
|
|
|
40
42
|
const DistroUtils = {
|
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
// Copyright (c) 2025, 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 rclnodejs = require('bindings')('rclnodejs');
|
|
18
|
+
const DistroUtils = require('./distro.js');
|
|
19
|
+
const Entity = require('./entity.js');
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Enumeration for PublisherEventCallbacks event types.
|
|
23
|
+
* @enum {number}
|
|
24
|
+
*/
|
|
25
|
+
const PublisherEventType = {
|
|
26
|
+
/** @member {number} */
|
|
27
|
+
PUBLISHER_OFFERED_DEADLINE_MISSED: 0,
|
|
28
|
+
/** @member {number} */
|
|
29
|
+
PUBLISHER_LIVELINESS_LOST: 1,
|
|
30
|
+
/** @member {number} */
|
|
31
|
+
PUBLISHER_OFFERED_INCOMPATIBLE_QOS: 2,
|
|
32
|
+
/** @member {number} */
|
|
33
|
+
PUBLISHER_INCOMPATIBLE_TYPE: 3,
|
|
34
|
+
/** @member {number} */
|
|
35
|
+
PUBLISHER_MATCHED: 4,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Enumeration for SubscriptionEventCallbacks event types.
|
|
40
|
+
* @enum {number}
|
|
41
|
+
*/
|
|
42
|
+
const SubscriptionEventType = {
|
|
43
|
+
/** @member {number} */
|
|
44
|
+
SUBSCRIPTION_REQUESTED_DEADLINE_MISSED: 0,
|
|
45
|
+
/** @member {number} */
|
|
46
|
+
SUBSCRIPTION_LIVELINESS_CHANGED: 1,
|
|
47
|
+
/** @member {number} */
|
|
48
|
+
SUBSCRIPTION_REQUESTED_INCOMPATIBLE_QOS: 2,
|
|
49
|
+
/** @member {number} */
|
|
50
|
+
SUBSCRIPTION_MESSAGE_LOST: 3,
|
|
51
|
+
/** @member {number} */
|
|
52
|
+
SUBSCRIPTION_INCOMPATIBLE_TYPE: 4,
|
|
53
|
+
/** @member {number} */
|
|
54
|
+
SUBSCRIPTION_MATCHED: 5,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
class EventHandler extends Entity {
|
|
58
|
+
constructor(handle, callback, eventType, eventTypeName) {
|
|
59
|
+
super(handle, null, null);
|
|
60
|
+
this._callback = callback;
|
|
61
|
+
this._eventType = eventType;
|
|
62
|
+
this._eventTypeName = eventTypeName;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
takeData() {
|
|
66
|
+
const data = rclnodejs.takeEvent(this._handle, {
|
|
67
|
+
[this._eventTypeName]: this._eventType,
|
|
68
|
+
});
|
|
69
|
+
if (this._callback) {
|
|
70
|
+
this._callback(data);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @class - Class representing a ROS 2 PublisherEventCallbacks
|
|
77
|
+
* @hideconstructor
|
|
78
|
+
*/
|
|
79
|
+
class PublisherEventCallbacks {
|
|
80
|
+
constructor() {
|
|
81
|
+
if (DistroUtils.getDistroId() < DistroUtils.getDistroId('jazzy')) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
'PublisherEventCallbacks is only available in ROS 2 Jazzy and later.'
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
this._deadline = null;
|
|
87
|
+
this._incompatible_qos = null;
|
|
88
|
+
this._liveliness = null;
|
|
89
|
+
this._incompatible_type = null;
|
|
90
|
+
this._matched = null;
|
|
91
|
+
this._eventHandlers = [];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Set deadline missed callback.
|
|
96
|
+
* @param {function} callback - The callback function to be called.
|
|
97
|
+
*/
|
|
98
|
+
set deadline(callback) {
|
|
99
|
+
this._deadline = callback;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Get deadline missed callback.
|
|
104
|
+
* @return {function} - The callback function.
|
|
105
|
+
*/
|
|
106
|
+
get deadline() {
|
|
107
|
+
return this._deadline;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Set incompatible QoS callback.
|
|
112
|
+
* @param {function} callback - The callback function to be called.
|
|
113
|
+
*/
|
|
114
|
+
set incompatibleQos(callback) {
|
|
115
|
+
this._incompatible_qos = callback;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Get incompatible QoS callback.
|
|
120
|
+
* @return {function} - The callback function.
|
|
121
|
+
*/
|
|
122
|
+
get incompatibleQos() {
|
|
123
|
+
return this._incompatible_qos;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Set liveliness lost callback.
|
|
128
|
+
* @param {function} callback - The callback function to be called.
|
|
129
|
+
*/
|
|
130
|
+
set liveliness(callback) {
|
|
131
|
+
this._liveliness = callback;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Get liveliness lost callback.
|
|
136
|
+
* @return {function} - The callback function.
|
|
137
|
+
*/
|
|
138
|
+
get liveliness() {
|
|
139
|
+
return this._liveliness;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Set incompatible type callback.
|
|
144
|
+
* @param {function} callback - The callback function to be called.
|
|
145
|
+
*/
|
|
146
|
+
set incompatibleType(callback) {
|
|
147
|
+
this._incompatible_type = callback;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Get incompatible type callback.
|
|
152
|
+
* @return {function} - The callback function.
|
|
153
|
+
*/
|
|
154
|
+
get incompatibleType() {
|
|
155
|
+
return this._incompatible_type;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Set matched callback.
|
|
160
|
+
* @param {function} callback - The callback function to be called.
|
|
161
|
+
*/
|
|
162
|
+
set matched(callback) {
|
|
163
|
+
this._matched = callback;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Get matched callback.
|
|
168
|
+
* @return {function} - The callback function.
|
|
169
|
+
*/
|
|
170
|
+
get matched() {
|
|
171
|
+
return this._matched;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
createEventHandlers(publisherHandle) {
|
|
175
|
+
if (this._deadline) {
|
|
176
|
+
const deadlineHandle = rclnodejs.createPublisherEventHandle(
|
|
177
|
+
publisherHandle,
|
|
178
|
+
PublisherEventType.PUBLISHER_OFFERED_DEADLINE_MISSED
|
|
179
|
+
);
|
|
180
|
+
this._eventHandlers.push(
|
|
181
|
+
new EventHandler(
|
|
182
|
+
deadlineHandle,
|
|
183
|
+
this._deadline,
|
|
184
|
+
PublisherEventType.PUBLISHER_OFFERED_DEADLINE_MISSED,
|
|
185
|
+
'publisher_event_type'
|
|
186
|
+
)
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (this._incompatible_qos) {
|
|
191
|
+
const incompatibleQosHandle = rclnodejs.createPublisherEventHandle(
|
|
192
|
+
publisherHandle,
|
|
193
|
+
PublisherEventType.PUBLISHER_OFFERED_INCOMPATIBLE_QOS
|
|
194
|
+
);
|
|
195
|
+
this._eventHandlers.push(
|
|
196
|
+
new EventHandler(
|
|
197
|
+
incompatibleQosHandle,
|
|
198
|
+
this._incompatible_qos,
|
|
199
|
+
PublisherEventType.PUBLISHER_OFFERED_INCOMPATIBLE_QOS,
|
|
200
|
+
'publisher_event_type'
|
|
201
|
+
)
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (this._liveliness) {
|
|
206
|
+
const livelinessHandle = rclnodejs.createPublisherEventHandle(
|
|
207
|
+
publisherHandle,
|
|
208
|
+
PublisherEventType.PUBLISHER_LIVELINESS_LOST
|
|
209
|
+
);
|
|
210
|
+
this._eventHandlers.push(
|
|
211
|
+
new EventHandler(
|
|
212
|
+
livelinessHandle,
|
|
213
|
+
this._liveliness,
|
|
214
|
+
PublisherEventType.PUBLISHER_LIVELINESS_LOST,
|
|
215
|
+
'publisher_event_type'
|
|
216
|
+
)
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (this._incompatible_type) {
|
|
221
|
+
const incompatibleTypeHandle = rclnodejs.createPublisherEventHandle(
|
|
222
|
+
publisherHandle,
|
|
223
|
+
PublisherEventType.PUBLISHER_INCOMPATIBLE_TYPE
|
|
224
|
+
);
|
|
225
|
+
this._eventHandlers.push(
|
|
226
|
+
new EventHandler(
|
|
227
|
+
incompatibleTypeHandle,
|
|
228
|
+
this._incompatible_type,
|
|
229
|
+
PublisherEventType.PUBLISHER_INCOMPATIBLE_TYPE,
|
|
230
|
+
'publisher_event_type'
|
|
231
|
+
)
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (this._matched) {
|
|
236
|
+
const matchedHandle = rclnodejs.createPublisherEventHandle(
|
|
237
|
+
publisherHandle,
|
|
238
|
+
PublisherEventType.PUBLISHER_MATCHED
|
|
239
|
+
);
|
|
240
|
+
this._eventHandlers.push(
|
|
241
|
+
new EventHandler(
|
|
242
|
+
matchedHandle,
|
|
243
|
+
this._matched,
|
|
244
|
+
PublisherEventType.PUBLISHER_MATCHED,
|
|
245
|
+
'publisher_event_type'
|
|
246
|
+
)
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return this._eventHandlers;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
get eventHandlers() {
|
|
254
|
+
return this._eventHandlers;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* @class - Class representing a ROS 2 SubscriptionEventCallbacks
|
|
260
|
+
* @hideconstructor
|
|
261
|
+
*/
|
|
262
|
+
class SubscriptionEventCallbacks {
|
|
263
|
+
constructor() {
|
|
264
|
+
if (DistroUtils.getDistroId() < DistroUtils.getDistroId('jazzy')) {
|
|
265
|
+
throw new Error(
|
|
266
|
+
'SubscriptionEventCallbacks is only available in ROS 2 Jazzy and later.'
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
this._deadline = null;
|
|
270
|
+
this._incompatible_qos = null;
|
|
271
|
+
this._liveliness = null;
|
|
272
|
+
this._message_lost = null;
|
|
273
|
+
this._incompatible_type = null;
|
|
274
|
+
this._matched = null;
|
|
275
|
+
this._eventHandlers = [];
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Set the callback for deadline missed event.
|
|
280
|
+
* @param {function} callback - The callback function to be called.
|
|
281
|
+
*/
|
|
282
|
+
set deadline(callback) {
|
|
283
|
+
this._deadline = callback;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Get the callback for deadline missed event.
|
|
288
|
+
* @return {function} - The callback function.
|
|
289
|
+
*/
|
|
290
|
+
get deadline() {
|
|
291
|
+
return this._deadline;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Set the callback for incompatible QoS event.
|
|
296
|
+
* @param {function} callback - The callback function to be called.
|
|
297
|
+
*/
|
|
298
|
+
set incompatibleQos(callback) {
|
|
299
|
+
this._incompatible_qos = callback;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Get the callback for incompatible QoS event.
|
|
304
|
+
* @return {function} - The callback function.
|
|
305
|
+
*/
|
|
306
|
+
get incompatibleQos() {
|
|
307
|
+
return this._incompatible_qos;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Set the callback for liveliness changed event.
|
|
312
|
+
* @param {function} callback - The callback function to be called.
|
|
313
|
+
*/
|
|
314
|
+
set liveliness(callback) {
|
|
315
|
+
this._liveliness = callback;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Get the callback for liveliness changed event.
|
|
320
|
+
* @return {function} - The callback function.
|
|
321
|
+
*/
|
|
322
|
+
get liveliness() {
|
|
323
|
+
return this._liveliness;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Set the callback for message lost event.
|
|
328
|
+
* @param {function} callback - The callback function to be called.
|
|
329
|
+
*/
|
|
330
|
+
set messageLost(callback) {
|
|
331
|
+
this._message_lost = callback;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Get the callback for message lost event.
|
|
336
|
+
* @return {function} - The callback function.
|
|
337
|
+
*/
|
|
338
|
+
get messageLost() {
|
|
339
|
+
return this._message_lost;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Set the callback for incompatible type event.
|
|
344
|
+
* @param {function} callback - The callback function to be called.
|
|
345
|
+
*/
|
|
346
|
+
set incompatibleType(callback) {
|
|
347
|
+
this._incompatible_type = callback;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Get the callback for incompatible type event.
|
|
352
|
+
* @return {function} - The callback function.
|
|
353
|
+
*/
|
|
354
|
+
get incompatibleType() {
|
|
355
|
+
return this._incompatible_type;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Set the callback for matched event.
|
|
360
|
+
* @param {function} callback - The callback function to be called.
|
|
361
|
+
*/
|
|
362
|
+
set matched(callback) {
|
|
363
|
+
this._matched = callback;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Get the callback for matched event.
|
|
368
|
+
* @return {function} - The callback function.
|
|
369
|
+
*/
|
|
370
|
+
get matched() {
|
|
371
|
+
return this._matched;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
createEventHandlers(subscriptionHandle) {
|
|
375
|
+
if (this._deadline) {
|
|
376
|
+
const deadlineHandle = rclnodejs.createSubscriptionEventHandle(
|
|
377
|
+
subscriptionHandle,
|
|
378
|
+
SubscriptionEventType.SUBSCRIPTION_REQUESTED_DEADLINE_MISSED
|
|
379
|
+
);
|
|
380
|
+
this._eventHandlers.push(
|
|
381
|
+
new EventHandler(
|
|
382
|
+
deadlineHandle,
|
|
383
|
+
this._deadline,
|
|
384
|
+
SubscriptionEventType.SUBSCRIPTION_REQUESTED_DEADLINE_MISSED,
|
|
385
|
+
'subscription_event_type'
|
|
386
|
+
)
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if (this._incompatible_qos) {
|
|
391
|
+
const incompatibleQosHandle = rclnodejs.createSubscriptionEventHandle(
|
|
392
|
+
subscriptionHandle,
|
|
393
|
+
SubscriptionEventType.SUBSCRIPTION_REQUESTED_INCOMPATIBLE_QOS
|
|
394
|
+
);
|
|
395
|
+
this._eventHandlers.push(
|
|
396
|
+
new EventHandler(
|
|
397
|
+
incompatibleQosHandle,
|
|
398
|
+
this._incompatible_qos,
|
|
399
|
+
SubscriptionEventType.SUBSCRIPTION_REQUESTED_INCOMPATIBLE_QOS,
|
|
400
|
+
'subscription_event_type'
|
|
401
|
+
)
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (this._liveliness) {
|
|
406
|
+
const livelinessHandle = rclnodejs.createSubscriptionEventHandle(
|
|
407
|
+
subscriptionHandle,
|
|
408
|
+
SubscriptionEventType.SUBSCRIPTION_LIVELINESS_CHANGED
|
|
409
|
+
);
|
|
410
|
+
this._eventHandlers.push(
|
|
411
|
+
new EventHandler(
|
|
412
|
+
livelinessHandle,
|
|
413
|
+
this._liveliness,
|
|
414
|
+
SubscriptionEventType.SUBSCRIPTION_LIVELINESS_CHANGED,
|
|
415
|
+
'subscription_event_type'
|
|
416
|
+
)
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
if (this._message_lost) {
|
|
421
|
+
const messageLostHandle = rclnodejs.createSubscriptionEventHandle(
|
|
422
|
+
subscriptionHandle,
|
|
423
|
+
SubscriptionEventType.SUBSCRIPTION_MESSAGE_LOST
|
|
424
|
+
);
|
|
425
|
+
this._eventHandlers.push(
|
|
426
|
+
new EventHandler(
|
|
427
|
+
messageLostHandle,
|
|
428
|
+
this._message_lost,
|
|
429
|
+
SubscriptionEventType.SUBSCRIPTION_MESSAGE_LOST,
|
|
430
|
+
'subscription_event_type'
|
|
431
|
+
)
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (this._incompatible_type) {
|
|
436
|
+
const incompatibleTypeHandle = rclnodejs.createSubscriptionEventHandle(
|
|
437
|
+
subscriptionHandle,
|
|
438
|
+
SubscriptionEventType.SUBSCRIPTION_INCOMPATIBLE_TYPE
|
|
439
|
+
);
|
|
440
|
+
this._eventHandlers.push(
|
|
441
|
+
new EventHandler(
|
|
442
|
+
incompatibleTypeHandle,
|
|
443
|
+
this._incompatible_type,
|
|
444
|
+
SubscriptionEventType.SUBSCRIPTION_INCOMPATIBLE_TYPE,
|
|
445
|
+
'subscription_event_type'
|
|
446
|
+
)
|
|
447
|
+
);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
if (this._matched) {
|
|
451
|
+
const matchedHandle = rclnodejs.createSubscriptionEventHandle(
|
|
452
|
+
subscriptionHandle,
|
|
453
|
+
SubscriptionEventType.SUBSCRIPTION_MATCHED
|
|
454
|
+
);
|
|
455
|
+
this._eventHandlers.push(
|
|
456
|
+
new EventHandler(
|
|
457
|
+
matchedHandle,
|
|
458
|
+
this._matched,
|
|
459
|
+
SubscriptionEventType.SUBSCRIPTION_MATCHED,
|
|
460
|
+
'subscription_event_type'
|
|
461
|
+
)
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
return this._eventHandlers;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
module.exports = {
|
|
470
|
+
PublisherEventCallbacks,
|
|
471
|
+
PublisherEventType,
|
|
472
|
+
SubscriptionEventCallbacks,
|
|
473
|
+
SubscriptionEventType,
|
|
474
|
+
};
|
package/lib/lifecycle.js
CHANGED
|
@@ -591,6 +591,15 @@ class LifecycleNode extends Node {
|
|
|
591
591
|
return this._changeState(SHUTDOWN_TRANSITION_LABEL, callbackReturnValue);
|
|
592
592
|
}
|
|
593
593
|
|
|
594
|
+
/**
|
|
595
|
+
* Check if state machine is initialized.
|
|
596
|
+
*
|
|
597
|
+
* @returns {boolean} true if the state machine is initialized; otherwise false.
|
|
598
|
+
*/
|
|
599
|
+
get isInitialized() {
|
|
600
|
+
return rclnodejs.isInitialized(this._stateMachineHandle);
|
|
601
|
+
}
|
|
602
|
+
|
|
594
603
|
/**
|
|
595
604
|
* The GetState service handler.
|
|
596
605
|
* @param {Object} request - The GetState service request.
|
|
@@ -93,10 +93,10 @@ class LifecyclePublisher extends Publisher {
|
|
|
93
93
|
this.deactivate();
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
static createPublisher(
|
|
96
|
+
static createPublisher(node, typeClass, topic, options) {
|
|
97
97
|
let type = typeClass.type();
|
|
98
98
|
let handle = rclnodejs.createPublisher(
|
|
99
|
-
|
|
99
|
+
node.handle,
|
|
100
100
|
type.pkgName,
|
|
101
101
|
type.subFolder,
|
|
102
102
|
type.interfaceName,
|