Skip to content

Commit d0738c0

Browse files
qiuzhongMinggang Wang
authored andcommitted
Add action example README
* Add a README to guide how to run the action example * Rename the `dodishes_action` directory to `ros1_actions` Fix: #371 #373
1 parent 4f55598 commit d0738c0

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

example/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Introduction
2+
This directory contains some examples based on `rclnodejs`.
3+
4+
## Precondition
5+
To run the examples, you should make sure:
6+
* `rclnodejs` is intalled. To see how to install it, see the repository [README](../README.md)
7+
* In each terminal session, the ROS2 environment is loaded. To check if it's loaded, use command `echo $AMENT_PREFIX_PATH` on POSIX systems and `echo %AMENT_PREFIX_PATH%` on Windows.
8+
9+
## Run the client/service and publisher/subscription examples
10+
For these examples, each of them contains a pair of JavaScript files: `client/service, publisher/subscription`, you should always run the `service` or `subscription` node first:
11+
12+
In terminal 1:
13+
```
14+
$ node subscription-example.js
15+
```
16+
17+
In temrinal 2:
18+
```
19+
$ node publisher-example.js
20+
```
21+
22+
You can press `CTRL + C` to shutdown them.
23+
24+
## Run the action example
25+
**Notice**: the action example requires the `ros1_action` package to be compiled, this package is located in `test` directory. To compile this package:
26+
```
27+
$ rm -fr generated
28+
$ export AMENT_PREFIX_PATH=$AMENT_PREFIX_PATH:$(pwd)/test/ros1_actions
29+
$ node scripts/generate_messages.js
30+
$ cd test/ros1_action
31+
$ colcon build
32+
$ cd ../../
33+
```
34+
35+
After the build, you can run the action example:
36+
In terminal 1:
37+
```
38+
$ source test/ros1_actions/install/local_setup.bash
39+
$ node example/action-server-example.js
40+
```
41+
42+
In terminal 2:
43+
```
44+
$ source test/ros1_actions/install/local_setup.bash
45+
$ node example/action-client-example.js
46+
```

scripts/run_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const Mocha = require('mocha');
1919
const os = require('os');
2020
const path = require('path');
2121

22-
let actionPath = path.join(path.dirname(__dirname), 'test', 'dodishes_action');
22+
let actionPath = path.join(path.dirname(__dirname), 'test', 'ros1_actions');
2323
process.env.AMENT_PREFIX_PATH = process.env.AMENT_PREFIX_PATH + path.delimiter + actionPath;
2424

2525
fs.remove(path.join(path.dirname(__dirname), 'generated'), (err)=> {
File renamed without changes.

test/test-action2msg.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const rclnodejs = require('../index.js');
2121

2222
describe('Testing message files generated from an action file', function() {
2323
let testRootDir = __dirname;
24-
let testActionDir = path.join(testRootDir, 'dodishes_action');
24+
let testActionDir = path.join(testRootDir, 'ros1_actions');
2525
let pkgRootDir = path.dirname(testRootDir);
2626
let msgGenRootDir = path.join(pkgRootDir, 'generated');
2727

@@ -57,7 +57,7 @@ describe('Testing message files generated from an action file', function() {
5757
});
5858

5959
describe('JavaScript message files generated', function() {
60-
let pkgPrefix = 'dodishes_action';
60+
let pkgPrefix = 'ros1_actions';
6161
let exampleName = 'DoDishes';
6262
let testCasesData = [
6363
'ActionFeedback',

0 commit comments

Comments
 (0)