Skip to content

Commit fd501a4

Browse files
authored
Merge branch 'RobotWebTools:develop' into develop
2 parents 2abf0aa + af41743 commit fd501a4

File tree

8 files changed

+93
-79
lines changed

8 files changed

+93
-79
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ branches:
99
- master
1010

1111
before_install:
12+
- sudo docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
1213
- sudo docker pull ubuntu:bionic
1314
- sudo docker build -t rcldocker .
1415

Dockerfile

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:bionic
1+
FROM ubuntu:focal
22

33
ENV GIT_USER_NAME mrbuild
44
ENV GIT_USER_EMAIL mrbuild@github.com
@@ -9,16 +9,14 @@ ENV LANG en_US.UTF-8
99

1010
RUN apt install -y gnupg2 lsb-release
1111
RUN curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add -
12-
RUN sh -c 'echo "deb [arch=amd64,arm64] http://packages.ros.org/ros2/ubuntu `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-latest.list'
12+
RUN sh -c 'echo "deb [arch=amd64] http://packages.ros.org/ros2/ubuntu `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-latest.list'
1313

1414
# Install prerequisites
1515
RUN export DEBIAN_FRONTEND=noninteractive && apt update && apt install -y \
1616
build-essential \
17-
cmake \
1817
python3-colcon-common-extensions \
19-
python3-pip \
20-
python-rosdep \
21-
libpython3-dev \
18+
python3-rosdep \
19+
libssl-dev \
2220
cppcheck
2321

2422
RUN rosdep init
@@ -32,17 +30,17 @@ RUN git config --global user.name $GIT_USER_NAME \
3230
ENV ROS2_WS=/root
3331
WORKDIR $ROS2_WS
3432

35-
RUN wget https://github.com/ros2/ros2/releases/download/release-eloquent-20200124/ros2-eloquent-20200124-linux-bionic-amd64.tar.bz2 \
36-
&& tar xf ros2-eloquent-20200124-linux-bionic-amd64.tar.bz2
33+
RUN wget https://github.com/ros2/ros2/releases/download/release-foxy-20201211/ros2-foxy-20201211-linux-focal-amd64.tar.bz2 \
34+
&& tar xf ros2-foxy-20201211-linux-focal-amd64.tar.bz2
3735

38-
# [Ubuntu 18.04]
39-
RUN rosdep install --from-paths $ROS2_WS/ros2-linux/share --ignore-src --rosdistro dashing -y --skip-keys "console_bridge fastcdr fastrtps libopensplice67 libopensplice69 osrf_testing_tools_cpp poco_vendor rmw_connext_cpp rosidl_typesupport_connext_c rosidl_typesupport_connext_cpp rti-connext-dds-5.3.1 tinyxml_vendor tinyxml2_vendor urdfdom urdfdom_headers"
36+
# [Ubuntu 20.04]
37+
RUN rosdep install --from-paths $ROS2_WS/ros2-linux/share --ignore-src --rosdistro foxy -y --skip-keys "console_bridge fastcdr fastrtps osrf_testing_tools_cpp poco_vendor rmw_connext_cpp rosidl_typesupport_connext_c rosidl_typesupport_connext_cpp rti-connext-dds-5.3.1 tinyxml_vendor tinyxml2_vendor urdfdom urdfdom_headers"
4038

4139
RUN echo "source $ROS2_WS/ros2-linux/local_setup.bash" >> $HOME/.bashrc
4240

4341
# Install nvm, Node.js and node-gyp
44-
ENV NODE_VERSION v12.16.1
45-
RUN wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash \
42+
ENV NODE_VERSION v12.20.0
43+
RUN wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash \
4644
&& . $HOME/.nvm/nvm.sh \
4745
&& nvm install $NODE_VERSION && nvm alias default $NODE_VERSION
4846

README.md

Lines changed: 47 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
## Server Implementations of the rosbridge v2 Protocol
66

7-
ros2-web-bridge, which leverages the [rclnodejs](https://github.com/RobotWebTools/rclnodejs) client, provides a JSON interface to [ROS 2.0](https://github.com/ros2/ros2/wiki) by adopting the [rosbridge v2 protocol](https://github.com/RobotWebTools/rosbridge_suite/blob/develop/ROSBRIDGE_PROTOCOL.md). The bridge can process commands through JSON tuneled over WebSockets.
7+
ros2-web-bridge, which leverages the [rclnodejs](https://github.com/RobotWebTools/rclnodejs) client, provides a JSON interface to [ROS 2](https://index.ros.org/doc/ros2/) by adopting the [rosbridge v2 protocol](https://github.com/RobotWebTools/rosbridge_suite/blob/develop/ROSBRIDGE_PROTOCOL.md). The bridge can process commands through JSON tuneled over WebSockets.
88

9-
## ROS2 support
9+
## ROS 2 support
1010

1111
The ros2-web-bridge **SUPPORTS** the latest ROS 2 stable release by default (currently [Dashing Patch 2](https://github.com/ros2/ros2/releases/tag/release-dashing-20190806)), please visit the [relase channel](https://github.com/ros2/ros2/releases) to check out the information.
1212

@@ -20,47 +20,40 @@ A client is a program that communicates with ros2-web-bridge using its JSON API.
2020

2121
## Install
2222

23-
1.Prepare for ROS2
24-
25-
Please reference the [wiki](https://index.ros.org/doc/ros2/Installation/) to install ROS2.
26-
27-
2.Install `Node.js`
28-
You can install Node.js:
29-
30-
* Download from Node.js offical [website](https://nodejs.org/en/), and install it.
31-
* Use the Node Version Manager ([nvm](https://github.com/creationix/nvm)) to install it.
32-
33-
3.Install dependencies
34-
35-
```javascript
36-
npm install
37-
```
23+
1. Prepare for ROS 2
24+
Please reference the [documentation](https://index.ros.org/doc/ros2/Installation/) to install ROS 2.
25+
2. Install `Node.js`
26+
You can install Node.js:
27+
* Download from Node.js offical [website](https://nodejs.org/en/), and install it.
28+
* Use the Node Version Manager ([nvm](https://github.com/creationix/nvm)) to install it.
29+
3. Clone and install dependencies
30+
Note that a ROS 2 installation has to be sourced before installing dependencies.
31+
```bash
32+
$ git clone https://github.com/RobotWebTools/ros2-web-bridge.git
33+
$ cd ros2-web-bridge
34+
$ source /opt/ros/$DISTRO/setup.sh # or a source installation
35+
$ npm install
36+
```
3837

3938
## Run Examples
4039

41-
1.Start `ros2-web-bridge` module:
42-
43-
```bash
44-
node bin/rosbridge.js
45-
```
46-
47-
If you want to start in client mode (i.e. connecting the bridge to an existing websocket server), do this instead:
48-
49-
```bash
50-
node bin/rosbridge.js --address ws://<address>:<port>
51-
```
52-
53-
2.Start the [express](https://www.npmjs.com/package/express) server:
54-
55-
```bash
56-
cd examples && node index.js
57-
```
58-
59-
3.Open your browser, and navigate to URL:
60-
61-
``` bash
62-
http://localhost:3000/html/publisher.html
63-
```
40+
1. Make sure to source a ROS 2 installation, e.g.:
41+
```bash
42+
$ source /opt/ros/$DISTRO/setup.sh # or a source installation
43+
```
44+
2. Start `ros2-web-bridge` module:
45+
```bash
46+
$ node bin/rosbridge.js
47+
```
48+
If you want to start in client mode (i.e. connecting the bridge to an existing websocket server), do this instead:
49+
```bash
50+
$ node bin/rosbridge.js --address ws://<address>:<port>
51+
```
52+
3. Start the [express](https://www.npmjs.com/package/express) server:
53+
```bash
54+
$ cd examples && node index.js
55+
```
56+
4. Open your browser, and navigate to URL: http://localhost:3000/html/publisher.html
6457

6558
## Not supported `op`
6659

@@ -85,21 +78,20 @@ subscribe | The type of the topic is [optional](https://github.com/RobotWebTools
8578

8679
If you use [roslibjs](https://static.robotwebtools.org/roslibjs/current/roslib.js) as the client running in the browser, please reference the code snippet below:
8780

88-
* Subscribe a topic.
89-
90-
```JavaScript
91-
// Define a topic with its type.
92-
var example = new ROSLIB.Topic({
93-
ros : ros,
94-
name : '/example_topic',
95-
messageType : 'std_msgs/String'
96-
});
97-
98-
// Subscribe a topic.
99-
example.subscribe(function(message) {
100-
console.log(`Receive message: ${message}`);
101-
});
102-
```
81+
* Subscribe to a topic.
82+
```JavaScript
83+
// Define a topic with its type.
84+
var example = new ROSLIB.Topic({
85+
ros : ros,
86+
name : '/example_topic',
87+
messageType : 'std_msgs/String'
88+
});
89+
90+
// Subscribe to a topic.
91+
example.subscribe(function(message) {
92+
console.log(`Receive message: ${message}`);
93+
});
94+
```
10395

10496
## Contributing
10597

appveyor.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ branches:
55
- master
66
- develop
77

8-
image: Visual Studio 2017
8+
image: Visual Studio 2019
99

1010
environment:
1111
nodejs_version: "12"
@@ -22,16 +22,17 @@ before_build:
2222
- choco install -y vcredist140
2323
- "SET PATH=C:\\Program Files\\CMake\\bin;%PATH%"
2424
- appveyor DownloadFile https://github.com/ros2/choco-packages/releases/download/2019-10-24/asio.1.12.1.nupkg
25+
- appveyor DownloadFile https://github.com/ros2/choco-packages/releases/download/2020-02-24/bullet.2.89.0.nupkg
2526
- appveyor DownloadFile https://github.com/ros2/choco-packages/releases/download/2019-10-24/cunit.2.1.3.nupkg
2627
- appveyor DownloadFile https://github.com/ros2/choco-packages/releases/download/2019-10-24/eigen.3.3.4.nupkg
2728
- appveyor DownloadFile https://github.com/ros2/choco-packages/releases/download/2019-10-24/tinyxml-usestl.2.6.2.nupkg
2829
- appveyor DownloadFile https://github.com/ros2/choco-packages/releases/download/2019-10-24/tinyxml2.6.0.0.nupkg
2930
- appveyor DownloadFile https://github.com/ros2/choco-packages/releases/download/2019-10-24/log4cxx.0.10.0.nupkg
30-
- choco install -y -s c:\download\ asio cunit eigen tinyxml-usestl tinyxml2 log4cxx
31-
- appveyor DownloadFile https://github.com/ros2/ros2/releases/download/release-eloquent-20200124/ros2-eloquent-20200124-windows-release-amd64.zip
32-
- 7z x -y "c:\download\ros2-eloquent-20200124-windows-release-amd64.zip" -o"c:\" > nul
33-
- setx -m OPENSSL_CONF C:\OpenSSL-Win64\bin\openssl.cfg
34-
- set PATH=C:\OpenSSL-Win64\bin;%PATH%
31+
- choco install -y -s c:\download\ asio bullet cunit eigen tinyxml-usestl tinyxml2 log4cxx
32+
- appveyor DownloadFile https://github.com/ros2/ros2/releases/download/release-foxy-20201211/ros2-foxy-20201211-windows-release.amd64.zip
33+
- 7z x -y "c:\download\ros2-foxy-20201211-windows-release.amd64.zip" -o"c:\" > nul
34+
- setx -m OPENSSL_CONF C:\OpenSSL-v111-Win64\bin\openssl.cfg
35+
- set PATH=C:\OpenSSL-v111-Win64\bin;%PATH%
3536
- setx AMENT_PYTHON_EXECUTABLE "c:\Python37"
3637
- refreshenv
3738
- "SET PATH=%PYTHON3%;%PYTHON3%\\bin;%PYTHON3%\\Scripts;%PATH%"
@@ -49,6 +50,6 @@ build_script:
4950
- npm run lint
5051

5152
test_script:
52-
- cmd: call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat"
53-
- "SET PATH=%PYTHON3%;%PYTHON3%\\bin;%PYTHON3%\\Scripts;%PATH%"
53+
- cmd: call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat"
54+
- "SET PATH=%PYTHON3%;%PYTHON3%\\bin;%PYTHON3%\\Scripts;C:\\Program Files\\CMake\\bin;%PATH%"
5455
- npm run ci

index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,26 @@ function createServer(options) {
6060
return rclnodejs.init()
6161
.then(() => {
6262
node = rclnodejs.createNode('ros2_web_bridge');
63-
rclnodejs.spin(node);
6463
debug('ROS2 node started');
64+
let timeout = options.delay_between_messages;
65+
if (timeout == undefined) {
66+
timeout = 0;
67+
}
6568
createConnection(options);
69+
spin(node, timeout);
6670
})
6771
.catch(error => shutDown(error));
6872
}
6973

74+
function spin(node, timeout) {
75+
if (rclnodejs.isShutdown()) {
76+
shutDown();
77+
return;
78+
}
79+
node.spinOnce();
80+
setTimeout(spin, timeout, node, timeout);
81+
}
82+
7083
function createConnection(options) {
7184
if (options.address != null) {
7285
debug('Starting in client mode; connecting to ' + options.address);
@@ -124,6 +137,8 @@ function createConnection(options) {
124137

125138
let wsAddr = options.address || `ws://localhost:${options.port}`;
126139
console.log(`Websocket started on ${wsAddr}`);
140+
// gracefuly shutdown rosbridge node commanding terminal
141+
process.on('SIGINT', () => process.exit(1));
127142
}
128143

129144
module.exports = {

lib/bridge.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ class Bridge extends EventEmitter {
189189
this._registerOpMap('publish', (command) => {
190190
debug(`Publish a topic named ${command.topic} with ${JSON.stringify(command.msg)}`);
191191

192+
if (!this._topicsPublished.has(command.topic)) {
193+
let error = new Error(`The topic ${command.topic} does not exist`);
194+
error.level = 'error';
195+
throw error;
196+
}
192197
let publisher = this._resourceProvider.getPublisherByTopicName(command.topic);
193198
if (publisher) {
194199
publisher.publish(command.msg);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ros2-web-bridge",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"description": "Bridge the web clients to ROS2.0 by a JSON interface",
55
"main": "index.js",
66
"keywords": [

test/nodejs/protocol/test-call-service.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,10 @@ module.exports = function() {
139139

140140
if (response.op === 'status') {
141141
assert.deepStrictEqual(response.level, testData.opStatus);
142-
ws.close();
143-
done();
142+
if (testData.responseCount === 1) {
143+
ws.close();
144+
done();
145+
}
144146
}
145147
if (testData.expectedResponse && response.op === testData.expectedResponse.op) {
146148
assert.deepStrictEqual(response.result, testData.expectedResponse.result);

0 commit comments

Comments
 (0)