You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* 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
* Delete obsolete ./test.js
* implements recommended PR feedback
While our benchmarks place rclnodejs performance at or above that of [rclpy](https://github.com/ros2/rclpy) we recommend appyling efficient coding and configuration practices where applicable.
2
+
3
+
While our benchmarks place rclnodejs performance at or above that of [rclpy](https://github.com/ros2/rclpy) we recommend appyling efficient coding and configuration practices where applicable.
3
4
4
5
## Tip-1: Disable Parameter Services
6
+
5
7
The typical ROS 2 node creation process includes creating an internal parameter service who's job is to fulfill requests for parameter meta-data and to set and update node parameters. If your ROS 2 node does not support public parameters then you can save the resources consumed by the parameter service. Disable the node parameter service by setting the `NodeOption.startParameterServices` property to false as shown below:
6
8
7
9
```
@@ -13,16 +15,54 @@ let node = new Node(nodeName, namespace, Context.defaultContext(), options);
The LifecycleNode constructor creates 5 life-cycle services to support the ROS 2 lifecycle specification. If your LifecycleNode instance will not be operating in a managed-node context consider disabling the lifecycle services via the LifecycleNode constructor as shown:
17
20
18
21
```
19
22
let enableLifecycleCommInterface = false;
20
23
21
24
let node = new LifecycleNode(
22
-
nodeName,
25
+
nodeName,
23
26
namespace,
24
-
Context.defaultContext,
27
+
Context.defaultContext,
25
28
NodeOptions.defaultOptions,
26
-
enableLifecycleCommInterface
29
+
enableLifecycleCommInterface
27
30
);
28
31
```
32
+
33
+
## Tip-3: Use Content-filtering Subscriptions
34
+
35
+
The ROS Humble release introduced content-filtering topics
36
+
which enable a subscription to limit the messages it receives
37
+
to a subset of interest. While the application of the a content-filter
38
+
is specific to the DDS/RMW vendor, the general approach is to apply
39
+
filtering on the publisher side. This can reduce network bandwidth
40
+
for pub-sub communications and message processing and memory
41
+
overhead of rclnodejs nodes.
42
+
43
+
Note: Be sure to confirm that your RMW implementation supports
44
+
content-filter before attempting to use it. In cases where content-filtering
45
+
is not supported your Subscription will simply ignore your filter and
46
+
continue operating with no filtering.
47
+
48
+
Example:
49
+
50
+
```
51
+
// create a content-filter to limit incoming messages to
Copy file name to clipboardExpand all lines: lib/node.js
+32-7Lines changed: 32 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -464,12 +464,7 @@ class Node extends rclnodejs.ShadowNode {
464
464
}
465
465
466
466
if(options===undefined){
467
-
options={
468
-
enableTypedArray: true,
469
-
isRaw: false,
470
-
qos: QoS.profileDefault,
471
-
};
472
-
returnoptions;
467
+
returnNode.getDefaultOptions();
473
468
}
474
469
475
470
if(options.enableTypedArray===undefined){
@@ -608,7 +603,7 @@ class Node extends rclnodejs.ShadowNode {
608
603
*/
609
604
610
605
/**
611
-
* Create a Subscription.
606
+
* Create a Subscription with optional content-filtering.
612
607
* @param {function|string|object} typeClass - The ROS message class,
613
608
OR a string representing the message class, e.g. 'std_msgs/msg/String',
614
609
OR an object representing the message class, e.g. {package: 'std_msgs', type: 'msg', name: 'String'}
@@ -617,9 +612,18 @@ class Node extends rclnodejs.ShadowNode {
617
612
* @param {boolean} options.enableTypedArray - The topic will use TypedArray if necessary, default: true.
618
613
* @param {QoS} options.qos - ROS Middleware "quality of service" settings for the subscription, default: QoS.profileDefault.
619
614
* @param {boolean} options.isRaw - The topic is serialized when true, default: false.
615
+
* @param {object} [options.contentFilter=undefined] - The content-filter, default: undefined.
616
+
* Confirm that your RMW supports content-filtered topics before use.
617
+
* @param {string} options.contentFilter.expression - Specifies the criteria to select the data samples of
618
+
* interest. It is similar to the WHERE part of an SQL clause.
619
+
* @param {string[]} [options.contentFilter.parameters=undefined] - Array of strings that give values to
620
+
* the ‘parameters’ (i.e., "%n" tokens) in the filter_expression. The number of supplied parameters must
621
+
* fit with the requested values in the filter_expression (i.e., the number of %n tokens). default: undefined.
620
622
* @param {SubscriptionCallback} callback - The callback to be call when receiving the topic subscribed. The topic will be an instance of null-terminated Buffer when options.isRaw is true.
621
623
* @return {Subscription} - An instance of Subscription.
624
+
* @throws {ERROR} - May throw an RMW error if content-filter is malformed.
0 commit comments