Skip to content

Commit a4d2623

Browse files
committed
[Docs] Refine README and npmjs landing page
1 parent 23d88fb commit a4d2623

2 files changed

Lines changed: 78 additions & 117 deletions

File tree

README.md

Lines changed: 58 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
**rclnodejs** is a Node.js client library for [ROS 2](https://www.ros.org/) that provides comprehensive JavaScript and TypeScript APIs for developing ROS 2 solutions.
1515

16-
**Key features:** Topics, Services, Actions, Parameters, Lifecycle Nodes, TypeScript support, RxJS Observables, Electron integration, and prebuilt binaries for Linux x64/arm64.
16+
**Key features:** Topics, Services, Actions, Parameters, Lifecycle Nodes, TypeScript support, RxJS Observables, Electron integration, browser ↔ ROS 2 WebSocket bridge (rosocket), and prebuilt binaries for Linux x64/arm64.
1717

1818
```javascript
1919
const rclnodejs = require('rclnodejs');
@@ -32,18 +32,15 @@ This example assumes your ROS 2 environment is already sourced.
3232
- Get started:
3333
[Installation](#installation), [Quick Start](#quick-start), [Tutorials](./tutorials/)
3434
- Reference:
35-
[API Documentation](#api-documentation), [Using TypeScript](#using-rclnodejs-with-typescript), [ROS 2 Interface Message Generation](#ros-2-interface-message-generation)
35+
[API Documentation](https://robotwebtools.github.io/rclnodejs/docs/index.html), [Using TypeScript](#using-rclnodejs-with-typescript), [ROS 2 Interface Message Generation](#ros-2-interface-message-generation)
3636
- Features and examples:
37-
[rclnodejs-cli](#rclnodejs-cli), [Electron-based Visualization](#electron-based-visualization), [Observable Subscriptions](#observable-subscriptions), [rosocket](#rosocket--ros-2-in-the-browser-no-library-required), [Performance Benchmarks](#performance-benchmarks)
37+
[rosocket](#rosocket--browser--ros-2-bridge), [Observable Subscriptions](#observable-subscriptions), [Electron-based Visualization](#electron-based-visualization), [Performance Benchmarks](#performance-benchmarks), [rclnodejs-cli](#rclnodejs-cli)
3838
- Project docs:
3939
[Efficient Usage Tips](./docs/EFFICIENCY.md), [FAQ and Known Issues](./docs/FAQ.md), [Building from Scratch](./docs/BUILDING.md), [Contributing](./docs/CONTRIBUTING.md)
4040

4141
## Installation
4242

43-
Choose the path that matches how you plan to use rclnodejs:
44-
45-
- Install from npm: add rclnodejs to your own application.
46-
- Quick Start: run the examples from this repository checkout.
43+
Most users only need [Install from npm](#install-from-npm) below. If you have cloned this repository and want to run the bundled examples, see [Quick Start](#quick-start) instead.
4744

4845
### Prerequisites
4946

@@ -68,23 +65,19 @@ After installation, use the example at the top of this README as a minimal publi
6865

6966
### Install from GitHub
7067

71-
Use this path only if you need a branch or commit that is not yet published to npm.
72-
73-
GitHub installs normally build from source. The published npm package includes prebuilt binaries for supported Linux targets, but this repository does not track those prebuilt artifacts.
68+
Use this path only if you need a branch or commit not yet published to npm. GitHub installs build from source.
7469

7570
```bash
7671
npm install RobotWebTools/rclnodejs#<branch>
7772
```
7873

79-
Or add `"rclnodejs":"RobotWebTools/rclnodejs#<branch>"` to your `package.json` dependency section.
80-
8174
> **Docker:** For containerized development, see the included [Dockerfile](./Dockerfile) for building and testing with different ROS distributions and Node.js versions.
8275
8376
See the [features](./docs/FEATURES.md) and try the [examples](https://github.com/RobotWebTools/rclnodejs/tree/develop/example) to get started.
8477

8578
### Prebuilt Binaries
8679

87-
rclnodejs ships with prebuilt native binaries for common Linux configurations since `v1.5.2`, eliminating the need for compilation during installation. This applies to supported Linux environments when installing the published npm package.
80+
rclnodejs ships with prebuilt native binaries for common Linux configurations, so most installs skip compilation.
8881

8982
**Supported Platforms:**
9083

@@ -94,11 +87,7 @@ rclnodejs ships with prebuilt native binaries for common Linux configurations si
9487
- **Architectures:** x64, arm64
9588
- **Node.js:** >= 20.20.2 (N-API compatible)
9689

97-
Installations outside this prebuilt matrix automatically fall back to building from source.
98-
99-
**Force Building from Source:**
100-
101-
If you need to build from source even when a prebuilt binary is available, set the environment variable:
90+
Installations outside this matrix automatically fall back to building from source. To force a source build even when a prebuilt binary is available:
10291

10392
```bash
10493
export RCLNODEJS_FORCE_BUILD=1
@@ -107,9 +96,7 @@ npm install rclnodejs
10796

10897
## Quick Start
10998

110-
Use these steps if you are working from this repository checkout and want to run one of the included examples.
111-
112-
These steps assume the [installation prerequisites](#prerequisites) are already satisfied and your ROS 2 environment has been sourced.
99+
From a clone of this repository, after sourcing your ROS 2 environment:
113100

114101
1. Install the repository dependencies from the project root.
115102

@@ -123,32 +110,39 @@ npm install
123110
node example/topics/publisher/publisher-example.js
124111
```
125112

126-
You should see messages being published once per second.
113+
More runnable examples in [example/](https://github.com/RobotWebTools/rclnodejs/tree/develop/example) and step-by-step guides in [tutorials/](./tutorials/).
127114

128-
If you want to build an application instead of running the repository examples, install rclnodejs into your own project with [Install from npm](#install-from-npm) and start from the sample code near the top of this README.
115+
## ROS 2 Interface Message Generation
129116

130-
Explore more runnable examples in [example/](https://github.com/RobotWebTools/rclnodejs/tree/develop/example) and step-by-step guides in [tutorials/](./tutorials/).
117+
rclnodejs auto-generates JavaScript bindings and TypeScript declarations for every ROS 2 `.msg`, `.srv`, and `.action` interface available in your sourced ROS 2 environment. This happens during `npm install`, so in most projects you do not need to run anything by hand.
131118

132-
## rclnodejs-cli
119+
Use the generated types directly:
120+
121+
```javascript
122+
import * as rclnodejs from 'rclnodejs';
123+
let stringMsgObject = rclnodejs.createMessageObject('std_msgs/msg/String');
124+
stringMsgObject.data = 'hello world';
125+
```
133126

134-
[rclnodejs-cli](https://github.com/RobotWebTools/rclnodejs-cli/) is a separate companion project that provides command-line tooling for working with rclnodejs-based ROS 2 applications. It is particularly useful for creating ROS 2 Node.js packages and working with launch files for multi-node orchestration.
127+
### Re-running message generation
135128

136-
See the rclnodejs-cli repository for installation instructions and the current command set.
129+
If you install additional ROS packages **after** rclnodejs was installed, re-run the generator from your project so the new interfaces are picked up:
137130

138-
## API Documentation
131+
```bash
132+
npx generate-ros-messages
133+
```
139134

140-
API documentation is available [online](https://robotwebtools.github.io/rclnodejs/docs/index.html). To generate it locally from this repository checkout, run `npm run docs`.
135+
Generated files are written to `<your-project>/node_modules/rclnodejs/generated/`.
141136

142-
## Electron-based Visualization
137+
### IDL Message Generation
143138

144-
Create rich, interactive desktop applications using Electron and web technologies like Three.js. Demos leverage **Electron Forge** for easy packaging on Windows, macOS, and Linux.
139+
In addition to the standard ROS 2 message generation (`.msg`, `.srv`, `.action`), rclnodejs can also generate JavaScript message files directly from IDL (Interface Definition Language) files. This is useful for custom IDL files or when you need finer control over the generation process.
145140

146-
| Demo | Description | Screenshot |
147-
| :-----------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------: |
148-
| **🐢 [turtle_tf2](./demo/electron/turtle_tf2)** | Real-time coordinate frame visualization with turtle control. Features TF2 transforms, keyboard control, and dynamic frame updates. | ![turtle_tf2](./demo/electron/turtle_tf2/turtle-tf2-demo.png) |
149-
| **🦾 [manipulator](./demo/electron/manipulator)** | Interactive two-joint robotic arm simulation. Features 3D joint visualization, manual/automatic control, and visual movement markers. | ![manipulator](./demo/electron/manipulator/manipulator-demo.png) |
141+
To generate messages from IDL files:
150142

151-
Explore more examples in [demo/electron](https://github.com/RobotWebTools/rclnodejs/tree/develop/demo/electron).
143+
```bash
144+
npm run generate-messages-idl
145+
```
152146

153147
## Using rclnodejs with TypeScript
154148

@@ -164,46 +158,11 @@ TypeScript declaration files are included in the package and exposed through the
164158
}
165159
```
166160

167-
TypeScript example:
161+
Then `import * as rclnodejs from 'rclnodejs'` works the same as the JavaScript example at the top of this README. See [TypeScript demos](https://github.com/RobotWebTools/rclnodejs/tree/develop/demo/typescript) for more.
168162

169-
```typescript
170-
import * as rclnodejs from 'rclnodejs';
171-
rclnodejs.init().then(() => {
172-
const node = new rclnodejs.Node('publisher_example_node');
173-
const publisher = node.createPublisher('std_msgs/msg/String', 'topic');
174-
publisher.publish(`Hello ROS 2 from rclnodejs`);
175-
node.spin();
176-
});
177-
```
178-
179-
See [TypeScript demos](https://github.com/RobotWebTools/rclnodejs/tree/develop/demo/typescript) for more examples.
180-
181-
## Observable Subscriptions
163+
## rosocket — Browser ↔ ROS 2 bridge
182164

183-
rclnodejs supports [RxJS](https://rxjs.dev/) Observable subscriptions for reactive programming with ROS 2 messages. Use operators like `throttleTime()`, `debounceTime()`, `map()`, and `combineLatest()` to build declarative message processing pipelines.
184-
185-
```javascript
186-
const { throttleTime, map } = require('rxjs');
187-
188-
const obsSub = node.createObservableSubscription(
189-
'sensor_msgs/msg/LaserScan',
190-
'/scan'
191-
);
192-
obsSub.observable
193-
.pipe(
194-
throttleTime(200),
195-
map((msg) => msg.ranges)
196-
)
197-
.subscribe((ranges) => console.log('Ranges:', ranges.length));
198-
```
199-
200-
See the [Observable Subscriptions Tutorial](./tutorials/observable-subscriptions.md) for more details.
201-
202-
## rosocket — ROS 2 in the browser, no library required
203-
204-
> A tiny WebSocket gateway to ROS 2 — built into `rclnodejs`.
205-
206-
> **Availability:** new in `2.0.0-beta.0`.
165+
> A tiny WebSocket gateway to ROS 2 — built into `rclnodejs`. _New in `2.0.0-beta.0`._
207166
208167
**rosocket** exposes ROS 2 topics/services as plain WebSocket URLs — a
209168
**lightweight** alternative to the rosbridge + roslibjs stack. Zero browser
@@ -222,39 +181,36 @@ ws.onopen = () => ws.send(JSON.stringify({ data: 'hi' }));
222181

223182
See [rosocket/README.md](./rosocket/README.md) for the URL scheme, service calls, and the programmatic `startRosocket()` API.
224183

225-
## ROS 2 Interface Message Generation
226-
227-
ROS client libraries convert IDL message descriptions into target language source code. rclnodejs provides the `generate-ros-messages` script to generate JavaScript message interface files and TypeScript declarations.
184+
## Observable Subscriptions
228185

229-
**Example usage:**
186+
rclnodejs supports [RxJS](https://rxjs.dev/) Observable subscriptions for reactive programming with ROS 2 messages. Use operators like `throttleTime()`, `debounceTime()`, `map()`, and `combineLatest()` to build declarative message processing pipelines.
230187

231188
```javascript
232-
import * as rclnodejs from 'rclnodejs';
233-
let stringMsgObject = rclnodejs.createMessageObject('std_msgs/msg/String');
234-
stringMsgObject.data = 'hello world';
235-
```
236-
237-
### Running Message Generation
238-
239-
Run the message generation script in your project when new ROS packages are installed:
189+
const { throttleTime, map } = require('rxjs');
240190

241-
```bash
242-
npx generate-ros-messages
191+
const obsSub = node.createObservableSubscription(
192+
'sensor_msgs/msg/LaserScan',
193+
'/scan'
194+
);
195+
obsSub.observable
196+
.pipe(
197+
throttleTime(200),
198+
map((msg) => msg.ranges)
199+
)
200+
.subscribe((ranges) => console.log('Ranges:', ranges.length));
243201
```
244202

245-
Generated files are located at `<yourproject>/node_modules/rclnodejs/generated/`.
246-
247-
> **Note:** This step is not needed for `rclnodejs > 1.5.0` because bundled interfaces are generated during installation. Rerun this command only after adding new ROS packages to your environment.
203+
See the [Observable Subscriptions Tutorial](./tutorials/observable-subscriptions.md) for more details.
248204

249-
### IDL Message Generation
205+
## Electron-based Visualization
250206

251-
In addition to the standard ROS2 message generation (`.msg`, `.srv`, and `.action`), rclnodejs provides advanced support for generating JavaScript message files directly from IDL (Interface Definition Language) files. This feature is particularly useful when working with custom IDL files or when you need more control over the message generation process.
207+
Build interactive desktop ROS 2 apps with Electron + Three.js, packaged for Windows/macOS/Linux via **Electron Forge**. Featured demo: 🦾 **[manipulator](./demo/electron/manipulator)** — a two-joint arm with manual/automatic control.
252208

253-
To generate messages from IDL files, use the `generate-messages-idl` npm script:
209+
<p align="left">
210+
<a href="./demo/electron/manipulator"><img src="./demo/electron/manipulator/manipulator-demo.png" alt="manipulator demo" width="320"></a>
211+
</p>
254212

255-
```bash
256-
npm run generate-messages-idl
257-
```
213+
More in [demo/electron](https://github.com/RobotWebTools/rclnodejs/tree/develop/demo/electron).
258214

259215
## Performance Benchmarks
260216

@@ -266,7 +222,11 @@ Benchmark results for 1000 iterations with 1024 KB messages (Ubuntu 24.04 WSL2,
266222
| **rclnodejs** (Node.js) | 744 | 927 |
267223
| **rclpy** (Python) | 1,618 | 15,380 |
268224

269-
These numbers are workload- and environment-specific. See [benchmark/README.md](./benchmark/README.md) for the full setup and methodology.
225+
See [benchmark/README.md](./benchmark/README.md) for the full setup and methodology.
226+
227+
## rclnodejs-cli
228+
229+
[rclnodejs-cli](https://github.com/RobotWebTools/rclnodejs-cli/) is a companion project providing command-line tooling for scaffolding rclnodejs application skeletons and working with launch files for multi-node orchestration.
270230

271231
## Contributing
272232

scripts/npmjs-readme.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,9 @@ To install from GitHub instead of npm, run:
4141
npm install RobotWebTools/rclnodejs#<branch>
4242
```
4343

44-
Or add `"rclnodejs":"RobotWebTools/rclnodejs#<branch>"` to your `package.json` dependencies.
45-
4644
### Prebuilt Binaries
4745

48-
rclnodejs ships with prebuilt native binaries for common Linux configurations since `v1.5.2`, eliminating the need for compilation during installation. This applies to supported Linux environments when installing the published npm package.
46+
rclnodejs ships with prebuilt native binaries for common Linux configurations, so most installs skip compilation.
4947

5048
**Supported Platforms:**
5149

@@ -55,9 +53,7 @@ rclnodejs ships with prebuilt native binaries for common Linux configurations si
5553
- **Architectures:** x64, arm64
5654
- **Node.js:** >= 20.20.2 (N-API compatible)
5755

58-
Installations outside this prebuilt matrix automatically fall back to building from source.
59-
60-
**Force Building from Source:**
56+
Installations outside this matrix automatically fall back to building from source. To force a source build even when a prebuilt binary is available:
6157

6258
```bash
6359
export RCLNODEJS_FORCE_BUILD=1
@@ -70,22 +66,20 @@ npm install rclnodejs
7066
- Tutorials: [tutorials/](https://github.com/RobotWebTools/rclnodejs/tree/develop/tutorials)
7167
- JavaScript examples: [example/](https://github.com/RobotWebTools/rclnodejs/tree/develop/example)
7268
- TypeScript demos: [demo/typescript/](https://github.com/RobotWebTools/rclnodejs/tree/develop/demo/typescript)
69+
- WebSocket bridge demo (rosocket): [demo/rosocket/](https://github.com/RobotWebTools/rclnodejs/tree/develop/demo/rosocket)
7370
- Electron demos: [demo/electron/](https://github.com/RobotWebTools/rclnodejs/tree/develop/demo/electron)
74-
- WebSocket bridge demo: [demo/rosocket/](https://github.com/RobotWebTools/rclnodejs/tree/develop/demo/rosocket)
7571
- Companion CLI: [rclnodejs-cli](https://github.com/RobotWebTools/rclnodejs-cli/)
7672

7773
## Message Generation
7874

79-
rclnodejs generates JavaScript message interfaces and TypeScript declarations during installation for `rclnodejs > 1.5.0`. If you install additional ROS packages later, rerun the generator in your project:
75+
rclnodejs auto-generates JavaScript message interfaces and TypeScript declarations during `npm install`, so in most projects you do not need to run anything by hand. If you install additional ROS packages **after** rclnodejs was installed, re-run the generator from your project so the new interfaces are picked up:
8076

8177
```bash
8278
npx generate-ros-messages
8379
```
8480

8581
Generated files are written to `<your-project>/node_modules/rclnodejs/generated/`.
8682

87-
This step is only needed after adding ROS packages that were not present when rclnodejs was installed.
88-
8983
## Using rclnodejs with TypeScript
9084

9185
TypeScript declaration files are included in the package. In most projects, configuring your `tsconfig.json` is sufficient:
@@ -100,17 +94,24 @@ TypeScript declaration files are included in the package. In most projects, conf
10094
}
10195
```
10296

103-
```typescript
104-
import * as rclnodejs from 'rclnodejs';
97+
Then `import * as rclnodejs from 'rclnodejs'` works the same as the JavaScript example at the top of this README.
10598

106-
rclnodejs.init().then(() => {
107-
const node = new rclnodejs.Node('publisher_example_node');
108-
const publisher = node.createPublisher('std_msgs/msg/String', 'topic');
109-
publisher.publish(`Hello ROS 2 from rclnodejs`);
110-
node.spin();
111-
});
99+
## rosocket — Browser ↔ ROS 2 bridge
100+
101+
A tiny WebSocket gateway to ROS 2, built into `rclnodejs`. Exposes ROS 2 topics and services as plain WebSocket URLs — a lightweight alternative to the rosbridge + roslibjs stack. Browsers use only built-in `WebSocket` + `JSON`; no JavaScript library required.
102+
103+
```bash
104+
npx rosocket --port 9000 --topic /chatter:std_msgs/msg/String
112105
```
113106

107+
```js
108+
const ws = new WebSocket('ws://host:9000/topic/chatter');
109+
ws.onmessage = (e) => console.log(JSON.parse(e.data).data);
110+
ws.onopen = () => ws.send(JSON.stringify({ data: 'hi' }));
111+
```
112+
113+
See the [rosocket guide](https://github.com/RobotWebTools/rclnodejs/tree/develop/rosocket) for the URL scheme, service calls, and the programmatic `startRosocket()` API.
114+
114115
## License
115116

116-
Apache License Version 2.0
117+
Apache License 2.0

0 commit comments

Comments
 (0)