rclnodejs 1.4.1 → 1.5.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 +9 -1
- package/index.js +95 -0
- package/lib/client.js +8 -0
- package/lib/publisher.js +9 -0
- package/lib/service.js +8 -0
- package/lib/subscription.js +9 -0
- package/package.json +1 -1
- package/types/action_server.d.ts +1 -1
- package/types/client.d.ts +5 -0
- package/types/index.d.ts +28 -0
- package/types/publisher.d.ts +5 -0
- package/types/service.d.ts +5 -0
- package/types/subscription.d.ts +5 -0
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ npm i rclnodejs@x.y.z
|
|
|
45
45
|
|
|
46
46
|
| RCLNODEJS Version | Compatible ROS 2 LTS |
|
|
47
47
|
| :----------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
|
|
48
|
-
| latest version (currently [v1.
|
|
48
|
+
| latest version (currently [v1.5.0](https://github.com/RobotWebTools/rclnodejs/tree/1.5.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
|
|
|
@@ -121,6 +121,8 @@ Send a request in a client
|
|
|
121
121
|
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
+
Check out more [examples](https://github.com/RobotWebTools/rclnodejs/tree/develop/example).
|
|
125
|
+
|
|
124
126
|
## Using rclnodejs with TypeScript
|
|
125
127
|
|
|
126
128
|
In your node project install the rclnodejs package as described above. You will also need the TypeScript compiler and node typings installed.
|
|
@@ -162,8 +164,14 @@ const msg: rclnodejs.std_msgs.msg.String = {
|
|
|
162
164
|
};
|
|
163
165
|
```
|
|
164
166
|
|
|
167
|
+
Check out more TypeScript [demos](https://github.com/RobotWebTools/rclnodejs/tree/develop/ts_demo).
|
|
168
|
+
|
|
165
169
|
**Note** that the interface.d.ts file is updated each time the generate_messages.js script is run.
|
|
166
170
|
|
|
171
|
+
## Using rclnodejs with Electron
|
|
172
|
+
|
|
173
|
+
Check out [demos](https://github.com/RobotWebTools/rclnodejs/tree/develop/electron_demo).
|
|
174
|
+
|
|
167
175
|
## License
|
|
168
176
|
|
|
169
177
|
Apache License Version 2.0
|
package/index.js
CHANGED
|
@@ -57,6 +57,7 @@ const {
|
|
|
57
57
|
serializeMessage,
|
|
58
58
|
deserializeMessage,
|
|
59
59
|
} = require('./lib/serialization.js');
|
|
60
|
+
const { spawn } = require('child_process');
|
|
60
61
|
|
|
61
62
|
/**
|
|
62
63
|
* Get the version of the generator that was used for the currently present interfaces.
|
|
@@ -89,6 +90,82 @@ async function getCurrentGeneratorVersion() {
|
|
|
89
90
|
|
|
90
91
|
let _rosVersionChecked = false;
|
|
91
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Run a ROS2 package executable using 'ros2 run' command.
|
|
95
|
+
* @param {string} packageName - The name of the ROS2 package.
|
|
96
|
+
* @param {string} executableName - The name of the executable to run.
|
|
97
|
+
* @param {string[]} [args=[]] - Additional arguments to pass to the executable.
|
|
98
|
+
* @return {Promise<{process: ChildProcess}>} A Promise that resolves with the process.
|
|
99
|
+
*/
|
|
100
|
+
function ros2Run(packageName, executableName, args = []) {
|
|
101
|
+
return new Promise((resolve, reject) => {
|
|
102
|
+
if (typeof packageName !== 'string' || !packageName.trim()) {
|
|
103
|
+
reject(new Error('Package name must be a non-empty string'));
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (typeof executableName !== 'string' || !executableName.trim()) {
|
|
108
|
+
reject(new Error('Executable name must be a non-empty string'));
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!Array.isArray(args)) {
|
|
113
|
+
reject(new Error('Arguments must be an array'));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const command = 'ros2';
|
|
118
|
+
const cmdArgs = ['run', packageName, executableName, ...args];
|
|
119
|
+
const childProcess = spawn(command, cmdArgs);
|
|
120
|
+
|
|
121
|
+
childProcess.on('error', (error) => {
|
|
122
|
+
reject(new Error(`Failed to start ros2 run: ${error.message}`));
|
|
123
|
+
});
|
|
124
|
+
childProcess.on('spawn', () => {
|
|
125
|
+
resolve({
|
|
126
|
+
process: childProcess,
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Run a ROS2 launch file using 'ros2 launch' command.
|
|
134
|
+
* @param {string} packageName - The name of the ROS2 package.
|
|
135
|
+
* @param {string} launchFile - The name of the launch file to run.
|
|
136
|
+
* @param {string[]} [args=[]] - Additional arguments to pass to the launch file.
|
|
137
|
+
* @return {Promise<{process: ChildProcess}>} A Promise that resolves with the process.
|
|
138
|
+
*/
|
|
139
|
+
function ros2Launch(packageName, launchFile, args = []) {
|
|
140
|
+
return new Promise((resolve, reject) => {
|
|
141
|
+
if (typeof packageName !== 'string' || !packageName.trim()) {
|
|
142
|
+
reject(new Error('Package name must be a non-empty string'));
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (typeof launchFile !== 'string' || !launchFile.trim()) {
|
|
146
|
+
reject(new Error('Launch file name must be a non-empty string'));
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (!Array.isArray(args)) {
|
|
150
|
+
reject(new Error('Arguments must be an array'));
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const command = 'ros2';
|
|
154
|
+
const cmdArgs = ['launch', packageName, launchFile, ...args];
|
|
155
|
+
const childProcess = spawn(command, cmdArgs);
|
|
156
|
+
|
|
157
|
+
childProcess.on('error', (error) => {
|
|
158
|
+
reject(new Error(`Failed to start ros2 launch: ${error.message}`));
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
childProcess.on('spawn', () => {
|
|
162
|
+
resolve({
|
|
163
|
+
process: childProcess,
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
92
169
|
/**
|
|
93
170
|
* A module that exposes the rclnodejs interfaces.
|
|
94
171
|
* @exports rclnodejs
|
|
@@ -444,6 +521,24 @@ let rcl = {
|
|
|
444
521
|
// this will not throw even if the handler is already removed
|
|
445
522
|
process.removeListener('SIGINT', _sigHandler);
|
|
446
523
|
},
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Run a ROS2 package executable using 'ros2 run' command.
|
|
527
|
+
* @param {string} packageName - The name of the ROS2 package.
|
|
528
|
+
* @param {string} executableName - The name of the executable to run.
|
|
529
|
+
* @param {string[]} [args=[]] - Additional arguments to pass to the executable.
|
|
530
|
+
* @return {Promise<{process: ChildProcess}>} A Promise that resolves with the process.
|
|
531
|
+
*/
|
|
532
|
+
ros2Run: ros2Run,
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Run a ROS2 launch file using 'ros2 launch' command.
|
|
536
|
+
* @param {string} packageName - The name of the ROS2 package.
|
|
537
|
+
* @param {string} launchFile - The name of the launch file to run.
|
|
538
|
+
* @param {string[]} [args=[]] - Additional arguments to pass to the launch file.
|
|
539
|
+
* @return {Promise<{process: ChildProcess}>} A Promise that resolves with the process.
|
|
540
|
+
*/
|
|
541
|
+
ros2Launch: ros2Launch,
|
|
447
542
|
};
|
|
448
543
|
|
|
449
544
|
const _sigHandler = () => {
|
package/lib/client.js
CHANGED
|
@@ -157,6 +157,14 @@ class Client extends Entity {
|
|
|
157
157
|
introspectionState
|
|
158
158
|
);
|
|
159
159
|
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Get the logger name for this client.
|
|
163
|
+
* @returns {string} The logger name for this client.
|
|
164
|
+
*/
|
|
165
|
+
get loggerName() {
|
|
166
|
+
return rclnodejs.getNodeLoggerName(this._nodeHandle);
|
|
167
|
+
}
|
|
160
168
|
}
|
|
161
169
|
|
|
162
170
|
module.exports = Client;
|
package/lib/publisher.js
CHANGED
|
@@ -26,6 +26,7 @@ const Entity = require('./entity.js');
|
|
|
26
26
|
class Publisher extends Entity {
|
|
27
27
|
constructor(handle, typeClass, topic, options, node, eventCallbacks) {
|
|
28
28
|
super(handle, typeClass, options);
|
|
29
|
+
this._node = node;
|
|
29
30
|
if (node && eventCallbacks) {
|
|
30
31
|
this._events = eventCallbacks.createEventHandlers(this.handle);
|
|
31
32
|
node._events.push(...this._events);
|
|
@@ -126,6 +127,14 @@ class Publisher extends Entity {
|
|
|
126
127
|
set events(events) {
|
|
127
128
|
this._events = events;
|
|
128
129
|
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Get the logger name for this publisher.
|
|
133
|
+
* @returns {string} The logger name for this publisher.
|
|
134
|
+
*/
|
|
135
|
+
get loggerName() {
|
|
136
|
+
return rclnodejs.getNodeLoggerName(this._node.handle);
|
|
137
|
+
}
|
|
129
138
|
}
|
|
130
139
|
|
|
131
140
|
module.exports = Publisher;
|
package/lib/service.js
CHANGED
|
@@ -149,6 +149,14 @@ class Service extends Entity {
|
|
|
149
149
|
getOptions() {
|
|
150
150
|
return rclnodejs.getOptions(this._handle);
|
|
151
151
|
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Get the logger name for this service.
|
|
155
|
+
* @returns {string} The logger name for this service.
|
|
156
|
+
*/
|
|
157
|
+
get loggerName() {
|
|
158
|
+
return rclnodejs.getNodeLoggerName(this._nodeHandle);
|
|
159
|
+
}
|
|
152
160
|
}
|
|
153
161
|
|
|
154
162
|
module.exports = Service;
|
package/lib/subscription.js
CHANGED
|
@@ -42,6 +42,7 @@ class Subscription extends Entity {
|
|
|
42
42
|
this._topic = topic;
|
|
43
43
|
this._callback = callback;
|
|
44
44
|
this._isRaw = options.isRaw || false;
|
|
45
|
+
this._node = node;
|
|
45
46
|
|
|
46
47
|
if (node && eventCallbacks) {
|
|
47
48
|
this._events = eventCallbacks.createEventHandlers(this.handle);
|
|
@@ -168,6 +169,14 @@ class Subscription extends Entity {
|
|
|
168
169
|
set events(events) {
|
|
169
170
|
this._events = events;
|
|
170
171
|
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Get the logger name for this subscription.
|
|
175
|
+
* @returns {string} The logger name for this subscription.
|
|
176
|
+
*/
|
|
177
|
+
get loggerName() {
|
|
178
|
+
return rclnodejs.getNodeLoggerName(this._node.handle);
|
|
179
|
+
}
|
|
171
180
|
}
|
|
172
181
|
|
|
173
182
|
module.exports = Subscription;
|
package/package.json
CHANGED
package/types/action_server.d.ts
CHANGED
|
@@ -78,7 +78,7 @@ declare module 'rclnodejs' {
|
|
|
78
78
|
goalHandle: ServerGoalHandle<T>
|
|
79
79
|
) => Promise<ActionResult<T>> | ActionResult<T>;
|
|
80
80
|
type GoalCallback<T extends TypeClass<ActionTypeClassName>> = (
|
|
81
|
-
|
|
81
|
+
goal: ActionGoal<T>
|
|
82
82
|
) => GoalResponse;
|
|
83
83
|
type HandleAcceptedCallback<T extends TypeClass<ActionTypeClassName>> = (
|
|
84
84
|
goalHandle: ServerGoalHandle<T>
|
package/types/client.d.ts
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/// <reference path="./base.d.ts" />
|
|
2
2
|
|
|
3
|
+
import { ChildProcess } from 'child_process';
|
|
4
|
+
|
|
3
5
|
declare module 'rclnodejs' {
|
|
4
6
|
type Class = new (...args: any[]) => any;
|
|
5
7
|
|
|
@@ -207,4 +209,30 @@ declare module 'rclnodejs' {
|
|
|
207
209
|
* @returns An Object representing the deserialized message.
|
|
208
210
|
*/
|
|
209
211
|
function deserializeMessage(buffer: Buffer, typeClass: Class): object;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Run a ROS2 package executable using 'ros2 run' command.
|
|
215
|
+
* @param {string} packageName - The name of the ROS2 package.
|
|
216
|
+
* @param {string} executableName - The name of the executable to run.
|
|
217
|
+
* @param {string[]} [args=[]] - Additional arguments to pass to the executable.
|
|
218
|
+
* @return {Promise<{process: ChildProcess}>} A Promise that resolves with the process.
|
|
219
|
+
*/
|
|
220
|
+
function ros2Run(
|
|
221
|
+
packageName: string,
|
|
222
|
+
executableName: string,
|
|
223
|
+
args: string[]
|
|
224
|
+
): Promise<{ process: ChildProcess }>;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Run a ROS2 launch file using 'ros2 launch' command.
|
|
228
|
+
* @param {string} packageName - The name of the ROS2 package.
|
|
229
|
+
* @param {string} launchFile - The name of the launch file to run.
|
|
230
|
+
* @param {string[]} [args=[]] - Additional arguments to pass to the launch file.
|
|
231
|
+
* @return {Promise<{process: ChildProcess}>} A Promise that resolves with the process.
|
|
232
|
+
*/
|
|
233
|
+
function ros2Launch(
|
|
234
|
+
packageName: string,
|
|
235
|
+
launchFile: string,
|
|
236
|
+
args: string[]
|
|
237
|
+
): Promise<{ process: ChildProcess }>;
|
|
210
238
|
}
|
package/types/publisher.d.ts
CHANGED
|
@@ -37,5 +37,10 @@ declare module 'rclnodejs' {
|
|
|
37
37
|
* @return {boolean} `true` if all published message data is acknowledged before the timeout, otherwise `false`.
|
|
38
38
|
*/
|
|
39
39
|
waitForAllAcked(timeout: bigint): boolean;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Get the logger name for this publisher.
|
|
43
|
+
*/
|
|
44
|
+
readonly loggerName: string;
|
|
40
45
|
}
|
|
41
46
|
}
|
package/types/service.d.ts
CHANGED