-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ROS Humble introduced the content-filtering topics feature. This PR
makes makes this feature available to rclnodejs developers. node.js - added contentFilter to Options - added static getDefaultOptions() - updated createSubscription() to support contentFilter node.d.ts - added content-filter types subscription.js - isContentFilteringEnabled() - setContentFilter() - clearContentFilter() subscription.d.ts - updated with content-filter api rcl_bindings.cpp - added content-filtering to CreateSubscription() rmw.js - new class for identifying the current ROS middleware test-subscription-content-filter.js - test cases for content-filters test/blocklist.json - added test-subscription-content-filter.js for Windows and Mac OS examples: - publisher-content-filtering-example.js - subscription-content-filtering-example.js package.json - added build/rebuild scripts for convenience
- Loading branch information
1 parent
feb8e03
commit 6c63a81
Showing
17 changed files
with
1,064 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) 2017 Intel Corporation. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
/* eslint-disable camelcase */ | ||
|
||
const rclnodejs = require('../index.js'); | ||
|
||
async function main() { | ||
await rclnodejs.init(); | ||
const node = new rclnodejs.Node('publisher_content_filter_example_node'); | ||
const publisher = node.createPublisher( | ||
'sensor_msgs/msg/Temperature', | ||
'temperature' | ||
); | ||
|
||
let count = 0; | ||
setInterval(function () { | ||
let temperature = (Math.random() * 100).toFixed(2); | ||
|
||
publisher.publish({ | ||
header: { | ||
stamp: { | ||
sec: 123456, | ||
nanosec: 789, | ||
}, | ||
frame_id: 'main frame', | ||
}, | ||
temperature: temperature, | ||
variance: 0, | ||
}); | ||
|
||
console.log( | ||
`Publish temerature message-${++count}: ${temperature} degrees` | ||
); | ||
}, 750); | ||
|
||
node.spin(); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright (c) 2023 Wayne Parrott. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
const { assertDefined } = require('dtslint/bin/util.js'); | ||
const rclnodejs = require('../index.js'); | ||
|
||
/** | ||
* This example demonstrates the use of content-filtering | ||
* topics (subscriptions) that were introduced in ROS 2 Humble. | ||
* See the following resources for content-filtering in ROS: | ||
* @see {@link Node#options} | ||
* @see {@link Node#createSubscription} | ||
* @see {@link https://www.omg.org/spec/DDS/1.4/PDF|DDS 1.4 specification, Annex B} | ||
* | ||
* Use publisher-content-filter-example.js to generate example messages. | ||
* | ||
* To see all published messages (filterd + unfiltered) run this | ||
* from commandline: | ||
* | ||
* ros2 topic echo temperature | ||
* | ||
* @return {undefined} | ||
*/ | ||
async function main() { | ||
await rclnodejs.init(); | ||
const node = new rclnodejs.Node('subscription_message_example_node'); | ||
|
||
let param = 50; | ||
|
||
// create a content-filter to limit incoming messages to | ||
// only those with temperature > paramC. | ||
const options = rclnodejs.Node.getDefaultOptions(); | ||
options.contentFilter = { | ||
expression: 'temperature > %0', | ||
parameters: [param], | ||
}; | ||
|
||
let count = 0; | ||
let subscription; | ||
try { | ||
subscription = node.createSubscription( | ||
'sensor_msgs/msg/Temperature', | ||
'temperature', | ||
options, | ||
(temperatureMsg) => { | ||
console.log(`Received temperature message-${++count}: | ||
${temperatureMsg.temperature}C`); | ||
if (count % 5 === 0) { | ||
if (subscription.isContentFilteringEnabled()) { | ||
console.log('Clearing filter'); | ||
subscription.clearContentFilter(); | ||
} else { | ||
param += 10; | ||
console.log('Update topic content-filter, temperature > ', param); | ||
const contentFilter = { | ||
expression: 'temperature > %0', | ||
parameters: [param], | ||
}; | ||
subscription.setContentFilter(contentFilter); | ||
} | ||
console.log( | ||
'Content-filtering enabled: ', | ||
subscription.isContentFilteringEnabled() | ||
); | ||
} | ||
} | ||
); | ||
|
||
if (!subscription.isContentFilteringEnabled()) { | ||
console.log('Content-filtering is not enabled on subscription.'); | ||
} | ||
} catch (error) { | ||
console.error('Unable to create content-filtering subscription.'); | ||
console.error( | ||
'Please ensure your content-filter expression and parameters are well-formed.' | ||
); | ||
} | ||
|
||
node.spin(); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
const DistroUtils = require('./distro'); | ||
|
||
const RMWNames = { | ||
FASTRTPS: 'rmw_fastrtps_cpp', | ||
CONNEXT: 'rmw_connext_cpp', | ||
CYCLONEDDS: 'rmw_cyclonedds_cpp', | ||
GURUMDDS: 'rmw_gurumdds_cpp', | ||
}; | ||
|
||
const DefaultRosRMWNameMap = new Map(); | ||
DefaultRosRMWNameMap.set('eloquent', RMWNames.FASTRTPS); | ||
DefaultRosRMWNameMap.set('foxy', RMWNames.FASTRTPS); | ||
DefaultRosRMWNameMap.set('galactic', RMWNames.CYCLONEDDS); | ||
DefaultRosRMWNameMap.set('humble', RMWNames.FASTRTPS); | ||
DefaultRosRMWNameMap.set('rolling', RMWNames.FASTRTPS); | ||
|
||
const RMWUtils = { | ||
RMWNames: RMWNames, | ||
|
||
getRMWName: function () { | ||
return process.env.RMW_IMPLEMENTATION | ||
? process.env.RMW_IMPLEMENTATION | ||
: DefaultRosRMWNameMap.get(DistroUtils.getDistroName()); | ||
}, | ||
}; | ||
|
||
module.exports = RMWUtils; |
Oops, something went wrong.