rclnodejs 1.8.1 → 1.8.3
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 +33 -23
- package/lib/action/client.js +6 -0
- package/lib/action/server.js +1 -3
- package/lib/distro.js +2 -1
- package/lib/lifecycle.js +2 -1
- package/lib/lifecycle_publisher.js +2 -2
- package/lib/node.js +37 -11
- package/lib/parameter.js +6 -10
- package/lib/service.js +8 -4
- package/lib/time_source.js +3 -20
- package/package.json +4 -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/rosidl_gen/generate_worker.js +3 -13
- package/rosidl_gen/idl_generator.js +210 -0
- package/rosidl_gen/index.js +3 -12
- package/rosidl_gen/packages.js +7 -4
- package/rosidl_gen/primitive_types.js +2 -2
- package/rosidl_parser/idl_parser.py +437 -0
- package/rosidl_parser/parser.py +2 -4
- package/rosidl_parser/rosidl_parser.js +27 -0
- package/src/executor.cpp +1 -0
- package/src/macros.h +2 -2
- package/src/rcl_action_client_bindings.cpp +18 -11
- package/src/rcl_action_server_bindings.cpp +24 -13
- package/src/rcl_bindings.cpp +1 -1
- package/src/rcl_client_bindings.cpp +13 -5
- package/src/rcl_context_bindings.cpp +7 -8
- package/src/rcl_guard_condition_bindings.cpp +12 -3
- package/src/rcl_lifecycle_bindings.cpp +53 -11
- package/src/rcl_node_bindings.cpp +11 -4
- package/src/rcl_publisher_bindings.cpp +12 -3
- package/src/rcl_service_bindings.cpp +12 -3
- package/src/rcl_subscription_bindings.cpp +24 -21
- package/src/rcl_timer_bindings.cpp +24 -9
- package/src/rcl_type_description_service_bindings.cpp +9 -1
- package/test_data_integrity.js +108 -0
- package/test_repro_exact.js +57 -0
- package/test_repro_hz.js +86 -0
- package/test_repro_pub.js +36 -0
- package/test_repro_stress.js +83 -0
- package/test_repro_sub.js +64 -0
- package/test_xproc_data.js +64 -0
- package/rosidl_convertor/README.md +0 -298
- package/rosidl_convertor/idl_convertor.js +0 -50
- package/rosidl_convertor/idl_convertor.py +0 -1250
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Thorough latency/throughput test matching the exact issue scenario
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const rclnodejs = require('./index.js');
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
await rclnodejs.init();
|
|
8
|
+
|
|
9
|
+
const node = new rclnodejs.Node('test_node');
|
|
10
|
+
|
|
11
|
+
let lastTs;
|
|
12
|
+
let msgCount = 0;
|
|
13
|
+
const hzSamples = [];
|
|
14
|
+
|
|
15
|
+
node.createSubscription(
|
|
16
|
+
'std_msgs/msg/Float64MultiArray',
|
|
17
|
+
'/map_to_base_link_pose2d',
|
|
18
|
+
(msg) => {
|
|
19
|
+
const now = Date.now();
|
|
20
|
+
msgCount++;
|
|
21
|
+
if (lastTs) {
|
|
22
|
+
const hz = 1000 / (now - lastTs);
|
|
23
|
+
hzSamples.push(hz);
|
|
24
|
+
console.log('Raw Hz:', hz.toFixed(2));
|
|
25
|
+
}
|
|
26
|
+
lastTs = now;
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
rclnodejs.spin(node);
|
|
31
|
+
|
|
32
|
+
console.log('Waiting for messages on /map_to_base_link_pose2d at ~10Hz...');
|
|
33
|
+
console.log('Run this in another terminal:');
|
|
34
|
+
console.log(
|
|
35
|
+
' ros2 topic pub -r 10 /map_to_base_link_pose2d std_msgs/msg/Float64MultiArray "{data: [1.0, 2.0, 3.0]}"'
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
if (hzSamples.length > 0) {
|
|
40
|
+
const avgHz = hzSamples.reduce((a, b) => a + b, 0) / hzSamples.length;
|
|
41
|
+
console.log(`\n--- Summary ---`);
|
|
42
|
+
console.log(`Messages: ${msgCount}, Avg Hz: ${avgHz.toFixed(2)}`);
|
|
43
|
+
if (avgHz < 5) {
|
|
44
|
+
console.log('*** REGRESSION DETECTED ***');
|
|
45
|
+
} else {
|
|
46
|
+
console.log('Performance OK');
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
console.log('No messages received');
|
|
50
|
+
}
|
|
51
|
+
node.stop();
|
|
52
|
+
rclnodejs.shutdown();
|
|
53
|
+
process.exit(0);
|
|
54
|
+
}, 15000);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
main().catch(console.error);
|
package/test_repro_hz.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Reprocer for https://github.com/RobotWebTools/rclnodejs/issues/1394
|
|
2
|
+
// Tests subscription throughput at ~10Hz publishing rate
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
const rclnodejs = require('./index.js');
|
|
6
|
+
|
|
7
|
+
const PUBLISH_HZ = 10;
|
|
8
|
+
const TEST_DURATION_SEC = 10;
|
|
9
|
+
|
|
10
|
+
async function main() {
|
|
11
|
+
await rclnodejs.init();
|
|
12
|
+
|
|
13
|
+
const pubNode = new rclnodejs.Node('test_pub_node');
|
|
14
|
+
const subNode = new rclnodejs.Node('test_sub_node');
|
|
15
|
+
|
|
16
|
+
const publisher = pubNode.createPublisher(
|
|
17
|
+
'std_msgs/msg/Float64MultiArray',
|
|
18
|
+
'/test_hz_topic'
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
let msgCount = 0;
|
|
22
|
+
let lastTs = null;
|
|
23
|
+
const hzSamples = [];
|
|
24
|
+
|
|
25
|
+
subNode.createSubscription(
|
|
26
|
+
'std_msgs/msg/Float64MultiArray',
|
|
27
|
+
'/test_hz_topic',
|
|
28
|
+
(msg) => {
|
|
29
|
+
const now = Date.now();
|
|
30
|
+
msgCount++;
|
|
31
|
+
if (lastTs) {
|
|
32
|
+
const hz = 1000 / (now - lastTs);
|
|
33
|
+
hzSamples.push(hz);
|
|
34
|
+
}
|
|
35
|
+
lastTs = now;
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
pubNode.spin();
|
|
40
|
+
subNode.spin();
|
|
41
|
+
|
|
42
|
+
// Publish at target Hz
|
|
43
|
+
let pubCount = 0;
|
|
44
|
+
const pubInterval = setInterval(() => {
|
|
45
|
+
publisher.publish({ data: [1.0, 2.0, 3.0] });
|
|
46
|
+
pubCount++;
|
|
47
|
+
}, 1000 / PUBLISH_HZ);
|
|
48
|
+
|
|
49
|
+
// Wait for test duration then report
|
|
50
|
+
setTimeout(() => {
|
|
51
|
+
clearInterval(pubInterval);
|
|
52
|
+
|
|
53
|
+
if (hzSamples.length > 0) {
|
|
54
|
+
const avgHz =
|
|
55
|
+
hzSamples.reduce((a, b) => a + b, 0) / hzSamples.length;
|
|
56
|
+
const minHz = Math.min(...hzSamples);
|
|
57
|
+
const maxHz = Math.max(...hzSamples);
|
|
58
|
+
|
|
59
|
+
console.log(`Published: ${pubCount} messages`);
|
|
60
|
+
console.log(`Received: ${msgCount} messages`);
|
|
61
|
+
console.log(`Avg Hz: ${avgHz.toFixed(2)}`);
|
|
62
|
+
console.log(`Min Hz: ${minHz.toFixed(2)}`);
|
|
63
|
+
console.log(`Max Hz: ${maxHz.toFixed(2)}`);
|
|
64
|
+
console.log(
|
|
65
|
+
`Expected: ~${PUBLISH_HZ} Hz`
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
if (avgHz < PUBLISH_HZ * 0.5) {
|
|
69
|
+
console.log(
|
|
70
|
+
`\n*** REGRESSION DETECTED: Average Hz (${avgHz.toFixed(2)}) is less than 50% of expected (${PUBLISH_HZ}) ***`
|
|
71
|
+
);
|
|
72
|
+
} else {
|
|
73
|
+
console.log('\nPerformance looks OK.');
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
console.log('No messages received!');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
pubNode.stop();
|
|
80
|
+
subNode.stop();
|
|
81
|
+
rclnodejs.shutdown();
|
|
82
|
+
process.exit(0);
|
|
83
|
+
}, TEST_DURATION_SEC * 1000);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Publisher for repro test - runs in separate process
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const rclnodejs = require('./index.js');
|
|
5
|
+
|
|
6
|
+
const PUBLISH_HZ = parseInt(process.argv[2] || '100');
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
await rclnodejs.init();
|
|
10
|
+
|
|
11
|
+
const node = new rclnodejs.Node('test_publisher_node');
|
|
12
|
+
const publisher = node.createPublisher(
|
|
13
|
+
'std_msgs/msg/Float64MultiArray',
|
|
14
|
+
'/test_hz_topic'
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
node.spin();
|
|
18
|
+
|
|
19
|
+
let pubCount = 0;
|
|
20
|
+
console.log(`Publishing at ${PUBLISH_HZ} Hz...`);
|
|
21
|
+
|
|
22
|
+
const pubInterval = setInterval(() => {
|
|
23
|
+
publisher.publish({ data: [1.0, 2.0, 3.0] });
|
|
24
|
+
pubCount++;
|
|
25
|
+
}, 1000 / PUBLISH_HZ);
|
|
26
|
+
|
|
27
|
+
setTimeout(() => {
|
|
28
|
+
clearInterval(pubInterval);
|
|
29
|
+
console.log(`Published ${pubCount} messages total`);
|
|
30
|
+
node.stop();
|
|
31
|
+
rclnodejs.shutdown();
|
|
32
|
+
process.exit(0);
|
|
33
|
+
}, 15000);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// Multi-frequency stress test for subscription performance
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const rclnodejs = require('./index.js');
|
|
5
|
+
|
|
6
|
+
const PUBLISH_HZ = parseInt(process.argv[2] || '100');
|
|
7
|
+
const TEST_DURATION_SEC = 10;
|
|
8
|
+
|
|
9
|
+
async function main() {
|
|
10
|
+
await rclnodejs.init();
|
|
11
|
+
|
|
12
|
+
const pubNode = new rclnodejs.Node('stress_pub_node');
|
|
13
|
+
const subNode = new rclnodejs.Node('stress_sub_node');
|
|
14
|
+
|
|
15
|
+
const publisher = pubNode.createPublisher(
|
|
16
|
+
'std_msgs/msg/Float64MultiArray',
|
|
17
|
+
'/stress_test_topic'
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
let msgCount = 0;
|
|
21
|
+
let lastTs = null;
|
|
22
|
+
const hzSamples = [];
|
|
23
|
+
|
|
24
|
+
subNode.createSubscription(
|
|
25
|
+
'std_msgs/msg/Float64MultiArray',
|
|
26
|
+
'/stress_test_topic',
|
|
27
|
+
(msg) => {
|
|
28
|
+
const now = Date.now();
|
|
29
|
+
msgCount++;
|
|
30
|
+
if (lastTs) {
|
|
31
|
+
const hz = 1000 / (now - lastTs);
|
|
32
|
+
hzSamples.push(hz);
|
|
33
|
+
}
|
|
34
|
+
lastTs = now;
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
pubNode.spin();
|
|
39
|
+
subNode.spin();
|
|
40
|
+
|
|
41
|
+
let pubCount = 0;
|
|
42
|
+
|
|
43
|
+
// Use high-resolution timer for more precise publishing
|
|
44
|
+
const intervalMs = 1000 / PUBLISH_HZ;
|
|
45
|
+
const pubInterval = setInterval(() => {
|
|
46
|
+
publisher.publish({ data: [1.0, 2.0, 3.0, 4.0, 5.0] });
|
|
47
|
+
pubCount++;
|
|
48
|
+
}, intervalMs);
|
|
49
|
+
|
|
50
|
+
setTimeout(() => {
|
|
51
|
+
clearInterval(pubInterval);
|
|
52
|
+
|
|
53
|
+
if (hzSamples.length > 0) {
|
|
54
|
+
const avgHz = hzSamples.reduce((a, b) => a + b, 0) / hzSamples.length;
|
|
55
|
+
const minHz = Math.min(...hzSamples);
|
|
56
|
+
const maxHz = Math.max(...hzSamples);
|
|
57
|
+
const dropRate = ((pubCount - msgCount) / pubCount * 100);
|
|
58
|
+
|
|
59
|
+
console.log(`Target: ${PUBLISH_HZ} Hz`);
|
|
60
|
+
console.log(`Published: ${pubCount}`);
|
|
61
|
+
console.log(`Received: ${msgCount}`);
|
|
62
|
+
console.log(`Avg Hz: ${avgHz.toFixed(2)}`);
|
|
63
|
+
console.log(`Min Hz: ${minHz.toFixed(2)}`);
|
|
64
|
+
console.log(`Max Hz: ${maxHz.toFixed(2)}`);
|
|
65
|
+
console.log(`Drop rate: ${dropRate.toFixed(1)}%`);
|
|
66
|
+
|
|
67
|
+
if (avgHz < PUBLISH_HZ * 0.5) {
|
|
68
|
+
console.log(`FAIL: Avg Hz significantly below target`);
|
|
69
|
+
} else {
|
|
70
|
+
console.log(`PASS`);
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
console.log('No messages received!');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
pubNode.stop();
|
|
77
|
+
subNode.stop();
|
|
78
|
+
rclnodejs.shutdown();
|
|
79
|
+
process.exit(0);
|
|
80
|
+
}, TEST_DURATION_SEC * 1000);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Subscriber for repro test - runs in separate process
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const rclnodejs = require('./index.js');
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
await rclnodejs.init();
|
|
8
|
+
|
|
9
|
+
const node = new rclnodejs.Node('test_subscriber_node');
|
|
10
|
+
|
|
11
|
+
let msgCount = 0;
|
|
12
|
+
let lastTs = null;
|
|
13
|
+
const hzSamples = [];
|
|
14
|
+
let startTime = null;
|
|
15
|
+
|
|
16
|
+
node.createSubscription(
|
|
17
|
+
'std_msgs/msg/Float64MultiArray',
|
|
18
|
+
'/test_hz_topic',
|
|
19
|
+
(msg) => {
|
|
20
|
+
const now = Date.now();
|
|
21
|
+
msgCount++;
|
|
22
|
+
if (!startTime) startTime = now;
|
|
23
|
+
if (lastTs) {
|
|
24
|
+
const hz = 1000 / (now - lastTs);
|
|
25
|
+
hzSamples.push(hz);
|
|
26
|
+
if (msgCount % 50 === 0) {
|
|
27
|
+
const recentSamples = hzSamples.slice(-50);
|
|
28
|
+
const recentAvg =
|
|
29
|
+
recentSamples.reduce((a, b) => a + b, 0) / recentSamples.length;
|
|
30
|
+
console.log(
|
|
31
|
+
`msg#${msgCount} recent avg Hz: ${recentAvg.toFixed(2)}`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
lastTs = now;
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
node.spin();
|
|
40
|
+
|
|
41
|
+
setTimeout(() => {
|
|
42
|
+
if (hzSamples.length > 0) {
|
|
43
|
+
const avgHz =
|
|
44
|
+
hzSamples.reduce((a, b) => a + b, 0) / hzSamples.length;
|
|
45
|
+
const minHz = Math.min(...hzSamples);
|
|
46
|
+
const maxHz = Math.max(...hzSamples);
|
|
47
|
+
const elapsed = (Date.now() - startTime) / 1000;
|
|
48
|
+
|
|
49
|
+
console.log(`\n--- Results ---`);
|
|
50
|
+
console.log(`Received: ${msgCount} messages in ${elapsed.toFixed(1)}s`);
|
|
51
|
+
console.log(`Avg Hz: ${avgHz.toFixed(2)}`);
|
|
52
|
+
console.log(`Min Hz: ${minHz.toFixed(2)}`);
|
|
53
|
+
console.log(`Max Hz: ${maxHz.toFixed(2)}`);
|
|
54
|
+
} else {
|
|
55
|
+
console.log('No messages received!');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
node.stop();
|
|
59
|
+
rclnodejs.shutdown();
|
|
60
|
+
process.exit(0);
|
|
61
|
+
}, 12000);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Cross-process data integrity test: validates data from external ROS2 publisher
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const rclnodejs = require('./index.js');
|
|
5
|
+
|
|
6
|
+
const EXPECTED_DATA = [1.0, 2.0, 3.0];
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
await rclnodejs.init();
|
|
10
|
+
|
|
11
|
+
const node = new rclnodejs.Node('xproc_data_sub');
|
|
12
|
+
let msgCount = 0;
|
|
13
|
+
let errCount = 0;
|
|
14
|
+
const errors = [];
|
|
15
|
+
|
|
16
|
+
node.createSubscription(
|
|
17
|
+
'std_msgs/msg/Float64MultiArray',
|
|
18
|
+
'/xproc_data_topic',
|
|
19
|
+
(msg) => {
|
|
20
|
+
msgCount++;
|
|
21
|
+
|
|
22
|
+
if (!msg || !msg.data) {
|
|
23
|
+
errCount++;
|
|
24
|
+
errors.push(`msg#${msgCount}: missing data`);
|
|
25
|
+
} else {
|
|
26
|
+
const arr = Array.from(msg.data);
|
|
27
|
+
for (let i = 0; i < EXPECTED_DATA.length; i++) {
|
|
28
|
+
if (Math.abs(arr[i] - EXPECTED_DATA[i]) > 1e-9) {
|
|
29
|
+
errCount++;
|
|
30
|
+
errors.push(
|
|
31
|
+
`msg#${msgCount}: data[${i}] expected ${EXPECTED_DATA[i]}, got ${arr[i]}`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (arr.length !== EXPECTED_DATA.length) {
|
|
36
|
+
errCount++;
|
|
37
|
+
errors.push(
|
|
38
|
+
`msg#${msgCount}: expected ${EXPECTED_DATA.length} elements, got ${arr.length}`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
rclnodejs.spin(node);
|
|
46
|
+
|
|
47
|
+
console.log('Listening on /xproc_data_topic for 10s...');
|
|
48
|
+
|
|
49
|
+
setTimeout(() => {
|
|
50
|
+
console.log(`\n=== Cross-Process Data Integrity ===`);
|
|
51
|
+
console.log(`Received: ${msgCount} messages`);
|
|
52
|
+
console.log(`Data errors: ${errCount}`);
|
|
53
|
+
if (errors.length > 0) {
|
|
54
|
+
errors.slice(0, 10).forEach((e) => console.log(` ${e}`));
|
|
55
|
+
}
|
|
56
|
+
const pass = errCount === 0 && msgCount > 0;
|
|
57
|
+
console.log(`Result: ${pass ? 'PASS' : 'FAIL'}`);
|
|
58
|
+
node.stop();
|
|
59
|
+
rclnodejs.shutdown();
|
|
60
|
+
process.exit(0);
|
|
61
|
+
}, 10000);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
main().catch(console.error);
|
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
# ROS2 IDL to Interface Converter
|
|
2
|
-
|
|
3
|
-
This Python tool converts ROS2 `.idl` files to corresponding `.msg`, `.srv`, and `.action` files.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- **Complete IDL Parsing**: Parses ROS2 IDL syntax including modules, structs, sequences, and arrays
|
|
8
|
-
- **Type Mapping**: Automatically maps IDL types to ROS2 types (e.g., `double` → `float64`, `sequence<T>` → `T[]`)
|
|
9
|
-
- **Typedef Support**: Handles both simple and array typedefs for complex type definitions
|
|
10
|
-
- **Constants and Default Values**: Supports constant definitions and field default values with `@default` annotations
|
|
11
|
-
- **Comment Preservation**: Extracts and preserves comments from `@verbatim` blocks
|
|
12
|
-
- **Key Annotation Detection**: Automatically skips IDL files with `@key` annotations (not supported in ROS2)
|
|
13
|
-
- **Multi-Interface Support**: Handles messages, services, and actions in a single IDL file
|
|
14
|
-
- **Namespace Support**: Properly handles namespaced types (e.g., `std_msgs::msg::Header` → `std_msgs/Header`)
|
|
15
|
-
- **Command Line Interface**: Easy to use with command line arguments
|
|
16
|
-
- **Verbose Output**: Optional detailed output showing parsed structures and generated files
|
|
17
|
-
|
|
18
|
-
## Usage
|
|
19
|
-
|
|
20
|
-
### Basic Usage
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
python3 idl_convertor.py <idl_file>
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
### With Options
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
python3 idl_convertor.py <idl_file> [options]
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
### Options
|
|
33
|
-
|
|
34
|
-
- `-o, --output DIR`: Output directory name for generated files (default: `ros_interfaces`)
|
|
35
|
-
- `-r, --root PATH`: Root path where the generated files will be located (default: current directory)
|
|
36
|
-
- `-p, --package NAME`: Package name to use for generated files (overrides package name from IDL)
|
|
37
|
-
- `-v, --verbose`: Enable verbose output showing parsed structures and file contents
|
|
38
|
-
- `-h, --help`: Show help message
|
|
39
|
-
|
|
40
|
-
### Advanced Examples
|
|
41
|
-
|
|
42
|
-
#### Custom Output Directory
|
|
43
|
-
|
|
44
|
-
```bash
|
|
45
|
-
python3 idl_convertor.py JointState.idl -o my_interfaces
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
#### Custom Root Path
|
|
49
|
-
|
|
50
|
-
```bash
|
|
51
|
-
python3 idl_convertor.py SetCameraInfo.idl -r /path/to/workspace -o sensor_msgs
|
|
52
|
-
# Generates files in: /path/to/workspace/sensor_msgs/srv/SetCameraInfo.srv
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
#### Custom Package Name
|
|
56
|
-
|
|
57
|
-
```bash
|
|
58
|
-
python3 idl_convertor.py JointState.idl -p my_package_name
|
|
59
|
-
# Overrides the package name from the IDL file
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
#### Combined Options
|
|
63
|
-
|
|
64
|
-
```bash
|
|
65
|
-
python3 idl_convertor.py SetCameraInfo.idl -r ~/ros2_ws/src -o sensor_msgs -p sensor_msgs -v
|
|
66
|
-
# Generates: ~/ros2_ws/src/sensor_msgs/srv/SetCameraInfo.srv with package name "sensor_msgs"
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
## Examples
|
|
70
|
-
|
|
71
|
-
### 1. Convert a Message IDL
|
|
72
|
-
|
|
73
|
-
Input file `JointState.idl`:
|
|
74
|
-
|
|
75
|
-
```idl
|
|
76
|
-
#include "std_msgs/msg/Header.idl"
|
|
77
|
-
|
|
78
|
-
module sensor_msgs {
|
|
79
|
-
module msg {
|
|
80
|
-
struct JointState {
|
|
81
|
-
std_msgs::msg::Header header;
|
|
82
|
-
sequence<string> name;
|
|
83
|
-
sequence<double> position;
|
|
84
|
-
sequence<double> velocity;
|
|
85
|
-
sequence<double> effort;
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
Output `JointState.msg`:
|
|
92
|
-
|
|
93
|
-
```
|
|
94
|
-
# JointState.msg
|
|
95
|
-
# Generated from IDL file
|
|
96
|
-
|
|
97
|
-
std_msgs/Header header
|
|
98
|
-
string[] name
|
|
99
|
-
float64[] position
|
|
100
|
-
float64[] velocity
|
|
101
|
-
float64[] effort
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
### 2. Convert a Service IDL
|
|
105
|
-
|
|
106
|
-
Input file `SetCameraInfo.idl`:
|
|
107
|
-
|
|
108
|
-
```idl
|
|
109
|
-
#include "sensor_msgs/msg/CameraInfo.idl"
|
|
110
|
-
|
|
111
|
-
module sensor_msgs {
|
|
112
|
-
module srv {
|
|
113
|
-
struct SetCameraInfo_Request {
|
|
114
|
-
sensor_msgs::msg::CameraInfo camera_info;
|
|
115
|
-
};
|
|
116
|
-
struct SetCameraInfo_Response {
|
|
117
|
-
boolean success;
|
|
118
|
-
string status_message;
|
|
119
|
-
};
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
Output `SetCameraInfo.srv`:
|
|
125
|
-
|
|
126
|
-
```
|
|
127
|
-
# SetCameraInfo.srv
|
|
128
|
-
# Generated from IDL file
|
|
129
|
-
|
|
130
|
-
# Request
|
|
131
|
-
sensor_msgs/CameraInfo camera_info
|
|
132
|
-
---
|
|
133
|
-
# Response
|
|
134
|
-
bool success
|
|
135
|
-
string status_message
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
### 3. Convert an Action IDL
|
|
139
|
-
|
|
140
|
-
Input file `Fibonacci.idl`:
|
|
141
|
-
|
|
142
|
-
```idl
|
|
143
|
-
module example_interfaces {
|
|
144
|
-
module action {
|
|
145
|
-
struct FibonacciGoal {
|
|
146
|
-
int32 order;
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
struct FibonacciResult {
|
|
150
|
-
sequence<int32> sequence;
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
struct FibonacciFeedback {
|
|
154
|
-
sequence<int32> partial_sequence;
|
|
155
|
-
};
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
Generates separate message files for goal, result, and feedback components.
|
|
161
|
-
|
|
162
|
-
## Type Mappings
|
|
163
|
-
|
|
164
|
-
### Basic Type Mappings
|
|
165
|
-
|
|
166
|
-
| IDL Type | ROS2 Type |
|
|
167
|
-
| ---------------- | ---------- |
|
|
168
|
-
| `boolean` | `bool` |
|
|
169
|
-
| `octet` | `uint8` |
|
|
170
|
-
| `int8` | `int8` |
|
|
171
|
-
| `uint8` | `uint8` |
|
|
172
|
-
| `int16` | `int16` |
|
|
173
|
-
| `uint16` | `uint16` |
|
|
174
|
-
| `int32` | `int32` |
|
|
175
|
-
| `uint32` | `uint32` |
|
|
176
|
-
| `int64` | `int64` |
|
|
177
|
-
| `uint64` | `uint64` |
|
|
178
|
-
| `float` | `float32` |
|
|
179
|
-
| `double` | `float64` |
|
|
180
|
-
| `string` | `string` |
|
|
181
|
-
| `wstring` | `wstring` |
|
|
182
|
-
| `sequence<T>` | `T[]` |
|
|
183
|
-
| `T[N]` | `T[N]` |
|
|
184
|
-
| `pkg::msg::Type` | `pkg/Type` |
|
|
185
|
-
|
|
186
|
-
### Typedef Support
|
|
187
|
-
|
|
188
|
-
The tool supports both simple and array typedefs:
|
|
189
|
-
|
|
190
|
-
- **Simple typedef**: `typedef double MyDouble;` → Maps `MyDouble` to `float64`
|
|
191
|
-
- **Array typedef**: `typedef double MyArray[9];` → Maps `MyArray` to `float64[9]`
|
|
192
|
-
- **Namespaced typedef**: `typedef std_msgs::msg::Header HeaderType;` → Maps `HeaderType` to `std_msgs/Header`
|
|
193
|
-
|
|
194
|
-
## Output Structure
|
|
195
|
-
|
|
196
|
-
The tool creates the following directory structure:
|
|
197
|
-
|
|
198
|
-
```
|
|
199
|
-
<root>/<output>/
|
|
200
|
-
├── msg/ # Generated .msg files
|
|
201
|
-
├── srv/ # Generated .srv files
|
|
202
|
-
└── action/ # Generated .action files
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
### ROS2 Workspace Integration
|
|
206
|
-
|
|
207
|
-
For proper ROS2 workspace integration, you can use the parameters to match the expected structure:
|
|
208
|
-
|
|
209
|
-
```bash
|
|
210
|
-
# Generate files for a ROS2 package in a workspace
|
|
211
|
-
python3 idl_convertor.py MyMessage.idl \
|
|
212
|
-
-r ~/ros2_ws/src \
|
|
213
|
-
-o my_package_name \
|
|
214
|
-
-p my_package_name
|
|
215
|
-
|
|
216
|
-
# This creates:
|
|
217
|
-
# ~/ros2_ws/src/my_package_name/msg/MyMessage.msg
|
|
218
|
-
# ~/ros2_ws/src/my_package_name/srv/MyService.srv
|
|
219
|
-
# ~/ros2_ws/src/my_package_name/action/MyAction.action
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
The generated files will be compatible with ROS2 build tools like `colcon build`.
|
|
223
|
-
|
|
224
|
-
## Important Notes
|
|
225
|
-
|
|
226
|
-
### DDS @key Annotation Handling
|
|
227
|
-
|
|
228
|
-
The tool automatically detects and skips IDL files that contain:
|
|
229
|
-
|
|
230
|
-
- Direct `@key` annotations (e.g., `@key string identifier;`)
|
|
231
|
-
- References to types that use `@key` annotations (e.g., `KeyedString`, `KeyedLong`)
|
|
232
|
-
|
|
233
|
-
This is because `@key` annotations are DDS-specific features that are not supported in ROS2 .msg files. When such files are encountered, the tool will print a warning and skip processing:
|
|
234
|
-
|
|
235
|
-
```
|
|
236
|
-
Warning: Skipping MyFile.idl - contains @key annotations which are not supported in ROS2 .msg files
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
or
|
|
240
|
-
|
|
241
|
-
```
|
|
242
|
-
Warning: Skipping MyFile.idl - references keyed types which are not supported in ROS2 .msg files
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
## Implementation Details
|
|
246
|
-
|
|
247
|
-
### Classes
|
|
248
|
-
|
|
249
|
-
- **`IdlParser`**: Parses IDL files and extracts interface definitions
|
|
250
|
-
- **`RosInterfaceGenerator`**: Generates ROS2 interface files from parsed data
|
|
251
|
-
- **`IdlField`**: Represents a field in an IDL structure (with support for comments and default values)
|
|
252
|
-
- **`IdlConstant`**: Represents a constant definition in an IDL structure
|
|
253
|
-
- **`IdlStructure`**: Represents an IDL structure (message, service part, etc.)
|
|
254
|
-
- **`IdlInterface`**: Represents a complete IDL interface definition
|
|
255
|
-
|
|
256
|
-
### Key Features
|
|
257
|
-
|
|
258
|
-
- **Robust Parsing**: Handles comments, nested modules, typedefs, and complex type definitions
|
|
259
|
-
- **Key Annotation Detection**: Automatically detects and skips files with `@key` annotations
|
|
260
|
-
- **Comment Preservation**: Extracts comments from `@verbatim` blocks and associates them with fields
|
|
261
|
-
- **Default Value Support**: Processes `@default` annotations and formats them for ROS2
|
|
262
|
-
- **Error Handling**: Graceful error handling with informative messages
|
|
263
|
-
- **Extensible**: Easy to extend for additional IDL features or output formats
|
|
264
|
-
|
|
265
|
-
## Testing
|
|
266
|
-
|
|
267
|
-
The tool has been tested with:
|
|
268
|
-
|
|
269
|
-
- ✅ Basic message types (JointState)
|
|
270
|
-
- ✅ Service definitions (SetCameraInfo) - generates proper .srv files
|
|
271
|
-
- ✅ Action definitions (Fibonacci) - generates proper .action files
|
|
272
|
-
- ✅ Array and sequence types
|
|
273
|
-
- ✅ Namespaced types
|
|
274
|
-
- ✅ Typedef declarations (simple and array types)
|
|
275
|
-
- ✅ Constants and default values with `@default` annotations
|
|
276
|
-
- ✅ Comment preservation from `@verbatim` blocks
|
|
277
|
-
- ✅ `@key` annotation detection and file skipping
|
|
278
|
-
- ✅ Command line interface with all options
|
|
279
|
-
- ✅ Request/Response combination for services
|
|
280
|
-
- ✅ Goal/Result/Feedback combination for actions
|
|
281
|
-
- ✅ Field order preservation from IDL to generated files
|
|
282
|
-
|
|
283
|
-
## Future Enhancements
|
|
284
|
-
|
|
285
|
-
- [ ] Support for nested structures and complex type inheritance
|
|
286
|
-
- [ ] Support for enums and unions
|
|
287
|
-
- [ ] Support for IDL annotations beyond `@verbatim`, `@default`, and `@key`
|
|
288
|
-
- [ ] Validation of generated files against ROS2 interface specifications
|
|
289
|
-
- [ ] Support for composition and inheritance patterns
|
|
290
|
-
- [ ] Batch processing of multiple IDL files
|
|
291
|
-
- [ ] Integration with ROS2 build tools (ament, colcon)
|
|
292
|
-
|
|
293
|
-
## Requirements
|
|
294
|
-
|
|
295
|
-
- Python 3.6+
|
|
296
|
-
- No external dependencies (uses only standard library)
|
|
297
|
-
|
|
298
|
-
This tool provides a robust solution for converting ROS2 IDL files to standard ROS2 interface formats, making it easier to work with interface definitions across different ROS2 tools and languages.
|