Skip to content

Commit 26d697e

Browse files
wayneparrottMinggang Wang
authored andcommitted
Optmized documentation for new application developers
Fix #664 README.md * Added **install** section with npm install directions * Tweaked rclnodejs-ros2 version compatibility table * Moved "Build from Scratch" section lower in document * Removed and reduced wordiness of typescript section npmjs-readme.md * Replaced link to clnodejs-ros2 version compatibility table with the table content * Added link to github project ./example folder * Removed some wordy typescript content
1 parent fc0705b commit 26d697e

File tree

2 files changed

+131
-84
lines changed

2 files changed

+131
-84
lines changed

README.md

Lines changed: 98 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,116 @@
55
| develop | [![Build Status](https://travis-ci.org/RobotWebTools/rclnodejs.svg?branch=develop)](https://travis-ci.org/RobotWebTools/rclnodejs) | [![macOS Build Status](https://circleci.com/gh/RobotWebTools/rclnodejs/tree/develop.svg?style=shield)](https://circleci.com/gh/RobotWebTools/rclnodejs) | [![Build status](https://ci.appveyor.com/api/projects/status/upbc7tavdag1aa5e/branch/develop?svg=true)](https://ci.appveyor.com/project/minggangw/rclnodejs/branch/develop) |
66
| master | [![Build Status](https://travis-ci.org/RobotWebTools/rclnodejs.svg?branch=master)](https://travis-ci.org/RobotWebTools/rclnodejs) | [![macOS Build Status](https://circleci.com/gh/RobotWebTools/rclnodejs/tree/master.svg?style=shield)](https://circleci.com/gh/RobotWebTools/rclnodejs) | [![Build status](https://ci.appveyor.com/api/projects/status/upbc7tavdag1aa5e/branch/master?svg=true)](https://ci.appveyor.com/project/minggangw/rclnodejs/branch/master) |
77

8-
## Match with ROS 2.0 Stable Releases
8+
`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.
99

10-
If you want to select a stable release of ROS 2.0 as your platform, please check the table below.
10+
Here's an example for how to create a ROS 2 node that publishes a string message in a few lines of JavaScript.
1111

12-
| ROS 2.0 release | NPM version |
13-
| :-----------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------: |
14-
| Eloquent Elusor Patch Release [1](https://github.com/ros2/ros2/releases/tag/release-eloquent-20200124) | [0.14.0](https://www.npmjs.com/package/rclnodejs/v/0.14.0) ([doc](http://robotwebtools.org/rclnodejs/docs/0.14.0/index.html)) |
15-
| [Eloquent Elusor](https://github.com/ros2/ros2/releases/tag/release-eloquent-20191122) | [0.11.1](https://github.com/RobotWebTools/rclnodejs/releases/tag/0.11.1) |
16-
| Dashing Diademata Patch Release [4](https://github.com/ros2/ros2/releases/tag/release-dashing-20191018) | [0.10.3](https://github.com/RobotWebTools/rclnodejs/releases/tag/0.10.3) |
17-
| Dashing Diademata Patch Release [3](https://github.com/ros2/ros2/releases/tag/release-dashing-20190910) | [0.10.2](https://github.com/RobotWebTools/rclnodejs/releases/tag/0.10.2) |
18-
| Dashing Diademata Patch Release [2](https://github.com/ros2/ros2/releases/tag/release-dashing-20190806) | [0.10.1](https://github.com/RobotWebTools/rclnodejs/releases/tag/0.10.1) |
19-
| Dashing Diademata Patch Release [1](https://github.com/ros2/ros2/releases/tag/release-dashing-20190614) | [0.10.0](https://www.npmjs.com/package/rclnodejs/v/0.10.0) |
12+
``` JavaScript
13+
const rclnodejs = require('rclnodejs');
14+
rclnodejs.init().then(() => {
15+
const node = rclnodejs.createNode('publisher_example_node');
16+
const publisher = node.createPublisher('std_msgs/msg/String', 'topic');
17+
publisher.publish(`Hello ROS 2 from rclnodejs`);
18+
rclnodejs.spin(node);
19+
});
20+
```
21+
22+
## Prerequisites
23+
24+
**Node.js**
25+
* [Node.js](https://nodejs.org/en/) version between 8.12 - 12.x.
26+
27+
**ROS 2 SDK**
28+
* See the ROS 2 SDK [Installation Guide](https://index.ros.org/doc/ros2/Installation/) for details.
29+
* *** DON'T FORGET TO [SOURCE THE ROS 2 STARTUP FILES](https://index.ros.org/doc/ros2/Tutorials/Configuring-ROS2-Environment/#source-the-setup-files) ***
30+
31+
## Install rclnodejs
32+
33+
Install the rclnodejs version that is compatible with your version of ROS 2 (see table below).
34+
35+
Run the following command for the most current version of rclnodejs
36+
37+
``` bash
38+
npm i rclnodejs
39+
```
40+
or to install a specific version of rclnodejs use
41+
``` bash
42+
43+
```
44+
#### RCLNODEJS - ROS 2 Version Compatibility
45+
46+
| RCLNODEJS Version | Compatible ROS 2 Release |
47+
| :---------------: | :-----------: |
48+
| [0.14.1 (current)](https://www.npmjs.com/package/rclnodejs/v/0.14.1) ([API](http://robotwebtools.org/rclnodejs/docs/0.14.1/index.html)) | [Foxy Fitzroy](https://github.com/ros2/ros2/releases/tag/release-foxy-20200605) |
49+
| [0.14.0](https://www.npmjs.com/package/rclnodejs/v/0.14.0) [(API)](http://robotwebtools.org/rclnodejs/docs/0.14.0/index.html) | [Eloquent Elusor - Patch 1](https://github.com/ros2/ros2/releases/tag/release-eloquent-20200124) |
50+
| [0.11.1](https://github.com/RobotWebTools/rclnodejs/releases/tag/0.11.1) | [Eloquent Elusor](https://github.com/ros2/ros2/releases/tag/release-eloquent-20191122)
51+
| [0.10.3](https://github.com/RobotWebTools/rclnodejs/releases/tag/0.10.3) | [Dashing Diademata - Patch 4](https://github.com/ros2/ros2/releases/tag/release-dashing-20191018) |
52+
| [0.10.2](https://github.com/RobotWebTools/rclnodejs/releases/tag/0.10.2) | [Dashing Diademata - Patch 3](https://github.com/ros2/ros2/releases/tag/release-dashing-20190910) |
53+
| [0.10.1](https://github.com/RobotWebTools/rclnodejs/releases/tag/0.10.1) | [Dashing Diademata - Patch 2](https://github.com/ros2/ros2/releases/tag/release-dashing-20190806) |
54+
| [0.10.0](https://www.npmjs.com/package/rclnodejs/v/0.10.0) | [Dashing Diademata - Patch 1](https://github.com/ros2/ros2/releases/tag/release-dashing-20190614) |
55+
56+
57+
- **Note:** to install rclnodejs from GitHub: add `"rclnodejs":"RobotWebTools/rclnodejs#<branch>"` to your `package.json` depdendency section.
58+
59+
## API Documentation
60+
61+
The API documentation is generated by `jsdoc`. To create a local copy run `npm run docs`. Alternatively you can use the prebuilt api documentation found in the `docs/` folder or view the [on-line version](http://robotwebtools.org/rclnodejs/docs/index.html) in your browser.
62+
63+
## Using TypeScript
64+
65+
TypeScript declaration files (\*.d.ts) are included to support developers that wish to use rclnodejs in TypeScript projects.
66+
67+
In your node project, in addition to installing the rclnodejs package, you will need to install the TypeScript compiler and node typings.
68+
69+
```
70+
npm install typescript @types/node -D
71+
```
72+
73+
Your tsconfig.json file should include the following compiler options:
74+
75+
```json
76+
{
77+
"compilerOptions": {
78+
"module": "commonjs",
79+
"moduleResolution": "node",
80+
"target": "es6"
81+
// your additional options here
82+
}
83+
}
84+
```
85+
86+
Here's a simple example implemented in TypeScript.
87+
88+
```
89+
import * as rclnodejs from 'rclnodejs';
90+
rclnodejs.init().then(() => {
91+
const node = rclnodejs.createNode('publisher_example_node');
92+
const publisher = node.createPublisher('std_msgs/msg/String', 'topic');
93+
publisher.publish(`Hello ROS 2 from rclnodejs`);
94+
rclnodejs.spin(node);
95+
});
96+
```
2097

21-
- Verify that you are using a compatible version of node between 8.12 - 12.99: run `node -v` for your node version info.
98+
The benefits of using TypeScript become evident when working with more complex use-cases. The ROS 2 messages are defined in the `types/interfaces.d.ts` module. This module is updated as part of the `generate_messages` process. Here's a trivial example of working with a String msg.
2299

23-
- Install from npmjs: run `npm i rclnodejs@<version>` to install a specific version.
100+
```
101+
const msg: rclnodejs.std_msgs.msg.String = {
102+
data: 'hello ROS2 from rclnodejs'
103+
}
104+
```
24105

25-
- Install from GitHub: add `"rclnodejs":"RobotWebTools/rclnodejs#<branch>"` to your `package.json`.
26106

27107
## Build from Scratch
28108

29109
### Get ready for ROS 2
30110

31-
1.Install ROS 2.0 from binary package.
111+
1.Install ROS 2 from binary package.
32112

33-
ROS 2.0 is a cross-platform system, which covers Linux, macOS and Windows, and the `rclnodejs` module is developed against the [`master`](https://github.com/ros2/ros2/blob/master/ros2.repos) branch of ROS 2.0. You can download the latest binary packages from [ROS 2.0 build farm](http://ci.ros2.org/view/packaging/) and follow the instructions of [Linux](https://index.ros.org/doc/ros2/Installation/Linux-Install-Binary/)/[macOS](https://index.ros.org/doc/ros2/Installation/OSX-Install-Binary/)/[Windows](https://index.ros.org/doc/ros2/Installation/Windows-Install-Binary/) to setup the environment (If you want to run your apps on a stable release of ROS 2.0, e.g. crystal-clemmys, please see the section `Running on Stable Release of ROS 2.0`).
113+
ROS 2 is a cross-platform system, which covers Linux, macOS and Windows, and the `rclnodejs` module is developed against the [`master`](https://github.com/ros2/ros2/blob/master/ros2.repos) branch of ROS 2. You can download the latest binary packages from [ROS 2 build farm](http://ci.ros2.org/view/packaging/) and follow the instructions of [Linux](https://index.ros.org/doc/ros2/Installation/Linux-Install-Binary/)/[macOS](https://index.ros.org/doc/ros2/Installation/OSX-Install-Binary/)/[Windows](https://index.ros.org/doc/ros2/Installation/Windows-Install-Binary/) to setup the environment (If you want to run your apps on a stable release of ROS 2, e.g. crystal-clemmys, please see the section `Running on Stable Release of ROS 2).
34114

35-
2.Build ROS 2.0 from scratch.
115+
2.Build ROS 2 from scratch.
36116

37-
Alternatively, you can build ROS 2.0 from scratch. Please select the platform you want to work on, then reference the instructions of [Linux](https://index.ros.org/doc/ros2/Installation/Linux-Development-Setup/)/[macOS](https://index.ros.org/doc/ros2/Installation/OSX-Development-Setup/)/[Windows](https://index.ros.org/doc/ros2/Installation/Windows-Development-Setup/) to build ROS 2.0 (please build wiht flag `--merge-install`).
117+
Alternatively, you can build ROS 2 from scratch. Please select the platform you want to work on, then reference the instructions of [Linux](https://index.ros.org/doc/ros2/Installation/Linux-Development-Setup/)/[macOS](https://index.ros.org/doc/ros2/Installation/OSX-Development-Setup/)/[Windows](https://index.ros.org/doc/ros2/Installation/Windows-Development-Setup/) to build ROS 2 (please build wiht flag `--merge-install`).
38118

39119
### Install `Node.js`
40120

@@ -116,7 +196,7 @@ rclnodejs.init().then(() => {
116196
let msg = new String();
117197

118198
setInterval(function() {
119-
const str = 'Hello ROS2.0';
199+
const str = 'Hello ROS 2;
120200
msg.data = str;
121201
publisher.publish(msg);
122202
}, 1000);
@@ -127,55 +207,6 @@ rclnodejs.init().then(() => {
127207
128208
Browse the JavaScript programs in the `example` folder to learn how to create and work with `timers, subscriptions, publishers, clients, services, timers,` and `nodes`.
129209
130-
## API Specification
131-
132-
The API spec is generated by `jsdoc`. To create a local copy run `npm run docs`. Alternatively you can use the prebuilt api documentation found in the `docs` folder or view the [on-line version](http://robotwebtools.org/rclnodejs/docs/index.html) in your browser.
133-
134-
## TypeScript Support
135-
136-
Type declaration files (\*.d.ts) are included to support developers that wish to use rclnodejs in TypeScript projects.
137-
138-
In your node project, in addition to installing the rclnodejs package, you will need to install the TypeScript compiler and node typings.
139-
140-
```
141-
npm install typescript @types/node -D
142-
```
143-
144-
Your tsconfig.json file should include the following compiler options:
145-
146-
```json
147-
{
148-
"compilerOptions": {
149-
"module": "commonjs",
150-
"moduleResolution": "node",
151-
"target": "es6"
152-
// your additional options here
153-
}
154-
}
155-
```
156-
157-
Here's a simple example implemented in TypeScript.
158-
159-
```
160-
import * as rclnodejs from 'rclnodejs';
161-
rclnodejs.init().then(() => {
162-
const node = rclnodejs.createNode('publisher_example_node');
163-
const publisher = node.createPublisher('std_msgs/msg/String', 'topic');
164-
publisher.publish(`Hello ROS 2.0 from rclnodejs`);
165-
rclnodejs.spin(node);
166-
});
167-
```
168-
169-
The benefits of using TypeScript become evident when working with more complex messages. The ROS2 messages are defined in the interfaces.d.ts module. This module is updated as part of the generate_messages process. Here's a trivial example of working with a String msg.
170-
171-
```
172-
const msg: rclnodejs.std_msgs.msg.String = {
173-
data: 'hello ROS2 from rclnodejs'
174-
}
175-
```
176-
177-
Smart TypeScript tools such as Visual Studio Code and the CodeMix plugin for Eclipse will help you learn the rclnodejs api and identify issues while coding rather than at runtime.
178-
179210
## Troubleshooting
180211
181212
### Maximum call stack size exceeded error when running in Jest

scripts/npmjs-readme.md

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,60 @@
11
# rclnodejs [![Build Status](https://travis-ci.org/RobotWebTools/rclnodejs.svg?branch=develop)](https://travis-ci.org/RobotWebTools/rclnodejs)
22

3-
`rclnodejs` is a Node.js client for the Robot Operating System (ROS) v2.0. It provides a simple and easy JavaScript API for ROS 2.0 programming. TypeScript declarations are included to support use of rclnodejs in TypeScript projects.
3+
`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-
The following JavaScript example demonstrates how to create a ROS 2.0 node and then publish a string message in only 6 lines of code.
5+
Here's an example for how to create a ROS 2 node that publishes a string message in a few lines of JavaScript.
66

77
``` JavaScript
88
const rclnodejs = require('rclnodejs');
99
rclnodejs.init().then(() => {
1010
const node = rclnodejs.createNode('publisher_example_node');
1111
const publisher = node.createPublisher('std_msgs/msg/String', 'topic');
12-
publisher.publish(`Hello ROS 2.0 from rclnodejs`);
12+
publisher.publish(`Hello ROS 2 from rclnodejs`);
1313
rclnodejs.spin(node);
1414
});
1515
```
1616

17-
## Install ROS 2.0
17+
## Prerequisites
1818

19-
Before install rclnodejs, make sure ROS 2.0 is installed first. Read and follow the [Installation Guide](https://index.ros.org/doc/ros2/Installation/) to install ROS 2.0
19+
**Node.js**
20+
* [Node.js](https://nodejs.org/en/) version between 8.12 - 12.x.
21+
22+
**ROS 2 SDK**
23+
* See the ROS 2 SDK [Installation Guide](https://index.ros.org/doc/ros2/Installation/) for details.
24+
* *** DON'T FORGET TO [SOURCE THE ROS 2 STARTUP FILES](https://index.ros.org/doc/ros2/Tutorials/Configuring-ROS2-Environment/#source-the-setup-files) ***
2025

2126
## Install rclnodejs
2227

23-
After ROS 2.0 is installed, run the following command
28+
Install the rclnodejs version that is compatible with your installed version of ROS 2 (see table below).
29+
30+
Run the following command for the most current version of rclnodejs
2431

2532
``` bash
26-
npm i --save rclnodejs
33+
npm i rclnodejs
34+
```
35+
or to install a specific version of rclnodejs use
36+
``` bash
37+
2738
```
39+
#### RCLNODEJS - ROS 2 Version Compatibility
2840

29-
## Match with ROS 2.0 Stable Releases
41+
| RCLNODEJS Version | Compatible ROS 2 Release |
42+
| :---------------: | :-----------: |
43+
| [0.14.1 (current)](https://www.npmjs.com/package/rclnodejs/v/0.14.1) ([API](http://robotwebtools.org/rclnodejs/docs/0.14.1/index.html)) | [Foxy Fitzroy](https://github.com/ros2/ros2/releases/tag/release-foxy-20200605) |
44+
| [0.14.0](https://www.npmjs.com/package/rclnodejs/v/0.14.0) [(API)](http://robotwebtools.org/rclnodejs/docs/0.14.0/index.html) | [Eloquent Elusor - Patch 1](https://github.com/ros2/ros2/releases/tag/release-eloquent-20200124) |
45+
| [0.11.1](https://github.com/RobotWebTools/rclnodejs/releases/tag/0.11.1) | [Eloquent Elusor](https://github.com/ros2/ros2/releases/tag/release-eloquent-20191122)
46+
| [0.10.3](https://github.com/RobotWebTools/rclnodejs/releases/tag/0.10.3) | [Dashing Diademata - Patch 4](https://github.com/ros2/ros2/releases/tag/release-dashing-20191018) |
47+
| [0.10.2](https://github.com/RobotWebTools/rclnodejs/releases/tag/0.10.2) | [Dashing Diademata - Patch 3](https://github.com/ros2/ros2/releases/tag/release-dashing-20190910) |
48+
| [0.10.1](https://github.com/RobotWebTools/rclnodejs/releases/tag/0.10.1) | [Dashing Diademata - Patch 2](https://github.com/ros2/ros2/releases/tag/release-dashing-20190806) |
49+
| [0.10.0](https://www.npmjs.com/package/rclnodejs/v/0.10.0) | [Dashing Diademata - Patch 1](https://github.com/ros2/ros2/releases/tag/release-dashing-20190614) |
3050

31-
Please check the [table](https://github.com/RobotWebTools/rclnodejs#match-with-ros-20-stable-releases) to select a specific version you want.
3251

33-
## Document
52+
## Documentation
3453

3554
API [documentation](http://robotwebtools.org/rclnodejs/docs/index.html) is available online.
3655

3756
## JavaScript Examples
57+
The source for the following examples and many others can be found [here](https://github.com/RobotWebTools/rclnodejs/tree/develop/example).
3858

3959
Use complex message
4060

@@ -108,7 +128,7 @@ In your node project install the rclnodejs package as described above. You will
108128
npm install typescript @types/node -D
109129
```
110130

111-
In your tsconfig.json file include the following compiler options:
131+
In your project's tsconfig.json file include the following compiler options:
112132
```json
113133
{
114134
"compilerOptions": {
@@ -126,23 +146,19 @@ import * as rclnodejs from 'rclnodejs';
126146
rclnodejs.init().then(() => {
127147
const node = rclnodejs.createNode('publisher_example_node');
128148
const publisher = node.createPublisher('std_msgs/msg/String', 'topic');
129-
publisher.publish(`Hello ROS 2.0 from rclnodejs`);
149+
publisher.publish(`Hello ROS 2 from rclnodejs`);
130150
rclnodejs.spin(node);
131151
});
132152
```
133153

134-
In this example you may notice that other than the `import` statement the code is virtually identical to the JavaScript version. Where the benefits of using TypeScript kick in is when using smart coding tools such as Visual Studio Code or the CodeMix plugin for Eclipse. These productivity tools use the rclnodejs type declaration files to help you learn the api and code with it more accurately and quickly.
135-
136-
Type aliases are provided for the ROS2 messages 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.
154+
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.
137155
```
138156
const msg: rclnodejs.std_msgs.msg.String = {
139157
data: 'hello ROS2 from rclnodejs'
140158
}
141159
```
142160
**Note** that the interface.d.ts file is updated each time the generate_messages.js script is run.
143161

144-
While the code snippet above is a trivial message example, when working with more complex message types such as sensor data, developers can benefit from typing information to help detect issues earlier in the develpment cycle.
145-
146162
## License
147163

148164
Apache License Version 2.0

0 commit comments

Comments
 (0)