Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ rclnodejs.init().then(() => {
- [API Documentation](#api-documentation)
- [Using TypeScript](#using-typescript)
- [Examples](https://github.com/RobotWebTools/rclnodejs/tree/develop/example)
- [Efficient Usage Tips](./docs/EFFICIENCY.md)
- [FAQ and Known Issues](./docs/FAQ.md)
- [Building from Scratch](./docs/BUILDING.md)
- [Contributing](./docs/CONTRIBUTING.md)
Expand Down
28 changes: 28 additions & 0 deletions docs/EFFICIENCY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Tips for efficent use of rclnodejs
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.

## Tip-1: Disable Parameter Services
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:

```
let options = new NodeOptions(false);
// or
options.startParameterServices = false;

let node = new Node(nodeName, namespace, Context.defaultContext(), options);
```

## Tip-2: Disable LifecycleNode Lifecycle Services
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:

```
let enableLifecycleCommInterface = false;

let node = new LifecycleNode(
nodeName,
namespace,
Context.defaultContext,
NodeOptions.defaultOptions,
enableLifecycleCommInterface
);
```
18 changes: 9 additions & 9 deletions lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ class Node extends rclnodejs.ShadowNode {
* @param {string} nodeName - The name of the node.
* @param {string} namespace - The name of the namespace.
* @param {boolean} noDemangle - If true topic names and types returned will not be demangled, default: false.
* @return {array} - An array of the names and types.
* @return {Array<{name: string, types: Array<string>}>} - An array of the names and types.
*/
getPublisherNamesAndTypesByNode(nodeName, namespace, noDemangle = false) {
return rclnodejs.getPublisherNamesAndTypesByNode(
Expand All @@ -934,7 +934,7 @@ class Node extends rclnodejs.ShadowNode {
* @param {string} nodeName - The name of the node.
* @param {string} namespace - The name of the namespace.
* @param {boolean} noDemangle - If true topic names and types returned will not be demangled, default: false.
* @return {array} - An array of the names and types.
* @return {Array<{name: string, types: Array<string>}>} - An array of the names and types.
*/
getSubscriptionNamesAndTypesByNode(nodeName, namespace, noDemangle = false) {
return rclnodejs.getSubscriptionNamesAndTypesByNode(
Expand All @@ -949,7 +949,7 @@ class Node extends rclnodejs.ShadowNode {
* Get the list of service topics discovered by the provided node for the remote node name.
* @param {string} nodeName - The name of the node.
* @param {string} namespace - The name of the namespace.
* @return {array} - An array of the names and types.
* @return {Array<{name: string, types: Array<string>}>} - An array of the names and types.
*/
getServiceNamesAndTypesByNode(nodeName, namespace) {
return rclnodejs.getServiceNamesAndTypesByNode(
Expand All @@ -962,31 +962,31 @@ class Node extends rclnodejs.ShadowNode {
/**
* Get the list of topics discovered by the provided node.
* @param {boolean} noDemangle - If true topic names and types returned will not be demangled, default: false.
* @return {array} - An array of the names and types.
* @return {Array<{name: string, types: Array<string>}>} - An array of the names and types.
*/
getTopicNamesAndTypes(noDemangle = false) {
return rclnodejs.getTopicNamesAndTypes(this.handle, noDemangle);
}

/**
* Get the list of services discovered by the provided node.
* @return {array} - An array of the names and types.
* @return {Array<{name: string, types: Array<string>}>} - An array of the names and types.
*/
getServiceNamesAndTypes() {
return rclnodejs.getServiceNamesAndTypes(this.handle);
}

/**
* Get the list of nodes discovered by the provided node.
* @return {array} - An array of the names.
* @return {Array<string>} - An array of the names.
*/
getNodeNames() {
return this.getNodeNamesAndNamespaces().map((item) => item.name);
}

/**
* Get the list of nodes and their namespaces discovered by the provided node.
* @return {array} - An array of the names and namespaces.
* @return {Array<{name: string, namespace: string}>} An array of the names and namespaces.
*/
getNodeNamesAndNamespaces() {
return rclnodejs.getNodeNames(this.handle);
Expand Down Expand Up @@ -1028,7 +1028,7 @@ class Node extends rclnodejs.ShadowNode {
* Get the list of parameter-overrides found on the commandline and
* in the NodeOptions.parameter_overrides property.
*
* @return {array} - An array of Parameters
* @return {Array<Parameter>} - An array of Parameters.
*/
getParameterOverrides() {
return Array.from(this._parameterOverrides.values());
Expand Down Expand Up @@ -1242,7 +1242,7 @@ class Node extends rclnodejs.ShadowNode {
/**
* Get the names of all declared parameters.
*
* @return {string[]} - The declared parameter names or empty array if
* @return {Array<string>} - The declared parameter names or empty array if
* no parameters have been declared.
*/
getParameterNames() {
Expand Down