Skip to content

Commit f21546d

Browse files
committed
Update the README for npmjs (#1233)
This PR updates the npmjs README to provide a cleaner, more concise documentation structure for the rclnodejs package. The update simplifies the README content while maintaining essential information for users. Key changes: - Adds a note about ROS 2 LTS support and development scope - Streamlines installation and prerequisites sections with updated ROS 2 references - Removes verbose example code sections in favor of directing users to example repositories - Updates TypeScript configuration recommendations and examples Fix: #1232
1 parent 4d2c6ed commit f21546d

File tree

1 file changed

+19
-114
lines changed

1 file changed

+19
-114
lines changed

scripts/npmjs-readme.md

Lines changed: 19 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
`rclnodejs` is a Node.js client for the Robot Operating System (ROS 2). It provides a simple and easy JavaScript API for ROS 2 programming. TypeScript declarations are included to support use of rclnodejs in TypeScript projects.
44

5+
\* rclnodejs development and maintenance is limited to all active ROS 2 LTS releases and the Rolling development branch
6+
57
Here's an example for how to create a ROS 2 node that publishes a string message in a few lines of JavaScript.
68

79
```JavaScript
@@ -14,137 +16,44 @@ rclnodejs.init().then(() => {
1416
});
1517
```
1618

17-
## Prerequisites
18-
19-
**Node.js**
20-
21-
- [Node.js](https://nodejs.org/en/) version >= 16.13.0.
19+
## Installation
2220

23-
**ROS 2 SDK**
21+
### Prerequisites
2422

25-
- See the ROS 2 SDK [Installation Guide](https://docs.ros.org/en/kilted/Installation.html) for details.
26-
- **DON'T FORGET TO [SOURCE THE ROS 2 STARTUP FILES](https://docs.ros.org/en/kilted/Tutorials/Beginner-CLI-Tools/Configuring-ROS2-Environment.htmls)**
23+
- [Node.js](https://nodejs.org/en/) version >= 16.13.0
24+
- [ROS 2 SDK](https://docs.ros.org/en/jazzy/Installation.html) - **Don't forget to [source the setup file](https://docs.ros.org/en/jazzy/Tutorials/Beginner-CLI-Tools/Configuring-ROS2-Environment.html#source-the-setup-files)**
2725

28-
## Install rclnodejs
29-
30-
Install the rclnodejs version that is compatible with your installed version of ROS 2 (see table below).
31-
32-
Run the following command for the most current version of rclnodejs
26+
### Install rclnodejs
3327

3428
```bash
3529
npm i rclnodejs
3630
```
3731

38-
or to install a specific version of rclnodejs use
39-
40-
```bash
41-
42-
```
43-
44-
#### RCLNODEJS - ROS 2 Version Compatibility
45-
46-
| RCLNODEJS Version | Compatible ROS 2 LTS |
47-
| :----------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
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) |
32+
- **Note:** to install rclnodejs from GitHub: add `"rclnodejs":"RobotWebTools/rclnodejs#<branch>"` to your `package.json` dependency section.
4933

5034
## Documentation
5135

5236
API [documentation](https://robotwebtools.github.io/rclnodejs/docs/index.html) is available online.
5337

5438
## JavaScript Examples
5539

56-
The source for the following examples and many others can be found [here](https://github.com/RobotWebTools/rclnodejs/tree/develop/example).
57-
58-
Use complex message
59-
60-
```JavaScript
61-
const publisher = node.createPublisher('sensor_msgs/msg/JointState', 'topic');
62-
publisher.publish({
63-
header: {
64-
stamp: {
65-
sec: 123456,
66-
nanosec: 789,
67-
},
68-
frame_id: 'main frame',
69-
},
70-
name: ['Tom', 'Jerry'],
71-
position: [1, 2],
72-
velocity: [2, 3],
73-
effort: [4, 5, 6],
74-
});
75-
76-
```
77-
78-
Create a subscription
79-
80-
```JavaScript
81-
const rclnodejs = require('../index.js');
82-
83-
// Create a ROS node and then print out the string message received from publishers
84-
rclnodejs.init().then(() => {
85-
const node = rclnodejs.createNode('subscription_example_node');
86-
87-
node.createSubscription('std_msgs/msg/String', 'topic', (msg) => {
88-
console.log(`Received message: ${typeof msg}`, msg);
89-
});
90-
91-
rclnodejs.spin(node);
92-
});
93-
```
94-
95-
Create a service
96-
97-
```JavaScript
98-
node.createService('example_interfaces/srv/AddTwoInts', 'add_two_ints', (request, response) => {
99-
console.log(`Incoming request: ${typeof request}`, request);
100-
let result = response.template;
101-
result.sum = request.a + request.b;
102-
console.log(`Sending response: ${typeof result}`, result, '\n--');
103-
response.send(result);
104-
});
105-
106-
```
107-
108-
Send a request in a client
109-
110-
```JavaScript
111-
const client = node.createClient('example_interfaces/srv/AddTwoInts', 'add_two_ints');
112-
const request = {
113-
a: Math.floor(Math.random() * 100),
114-
b: Math.floor(Math.random() * 100),
115-
};
116-
117-
console.log(`Sending: ${typeof request}`, request);
118-
client.sendRequest(request, (response) => {
119-
console.log(`Result: ${typeof response}`, response);
120-
});
121-
122-
```
123-
124-
Check out more [examples](https://github.com/RobotWebTools/rclnodejs/tree/develop/example).
40+
Try the [examples](https://github.com/RobotWebTools/rclnodejs/tree/develop/example) to get started.
12541

12642
## Using rclnodejs with TypeScript
12743

128-
In your node project install the rclnodejs package as described above. You will also need the TypeScript compiler and node typings installed.
129-
130-
```
131-
npm install typescript @types/node -D
132-
```
133-
134-
In your project's tsconfig.json file include the following compiler options:
44+
TypeScript declaration files are included in the `types/` folder. Configure your `tsconfig.json`:
13545

13646
```jsonc
13747
{
13848
"compilerOptions": {
13949
"module": "commonjs",
14050
"moduleResolution": "node",
141-
"target": "es6",
142-
...
143-
}
51+
"target": "es2020",
52+
},
14453
}
14554
```
14655

147-
Here's an earlier JavaScript example reimplemented in TypeScript.
56+
TypeScript example:
14857

14958
```typescript
15059
import * as rclnodejs from 'rclnodejs';
@@ -156,21 +65,17 @@ rclnodejs.init().then(() => {
15665
});
15766
```
15867

159-
Type-aliases for the ROS2 messages can be found in the `types/interfaces.d.ts` file. To use a message type-alias follow the naming pattern <pkg_name>.[msg|srv].<type>, e.g., sensor_msgs.msg.LaserScan or the std_msgs.msg.String as shown below.
68+
See [TypeScript demos](https://github.com/RobotWebTools/rclnodejs/tree/develop/ts_demo) for more examples.
16069

161-
```typescript
162-
const msg: rclnodejs.std_msgs.msg.String = {
163-
data: 'hello ROS2 from rclnodejs',
164-
};
165-
```
70+
**Note** that the interface.d.ts file is updated each time the generate_messages.js script is run.
16671

167-
Check out more TypeScript [demos](https://github.com/RobotWebTools/rclnodejs/tree/develop/ts_demo).
72+
## Electron-based Visualization
16873

169-
**Note** that the interface.d.ts file is updated each time the generate_messages.js script is run.
74+
Create rich, interactive desktop applications using Electron and web technologies like Three.js. Build 3D visualizations, monitoring dashboards, and control interfaces that run on Windows, macOS, and Linux.
17075

171-
## Using rclnodejs with Electron
76+
Try the `electron_demo/turtle_tf2` demo for real-time coordinate frame visualization with dynamic transforms and keyboard-controlled turtle movement. More examples in [electron_demo](https://github.com/RobotWebTools/rclnodejs/tree/develop/electron_demo).
17277

173-
Check out [demos](https://github.com/RobotWebTools/rclnodejs/tree/develop/electron_demo).
78+
![demo screenshot](https://github.com/RobotWebTools/rclnodejs/blob/develop/electron_demo/turtle_tf2/turtle-tf2-demo.gif?raw=true)
17479

17580
## License
17681

0 commit comments

Comments
 (0)