Skip to content

Commit 7cf76c6

Browse files
author
Hugo Boyer
committed
added setup section
1 parent 75ef7a9 commit 7cf76c6

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

gazebojs_camera_topics/tutorial.md

+23-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,27 @@ This method only works with 'gazebo.msgs.ImageStamped' topics, and accepts the f
88

99
Png files are uncompressed (whereas jpeg are smaller). If you want to save the image to disk, use the binary encoding. The base64 encoding is useful if you want to send the image data to another client in a portable way (ex: to make a mjpg stream for web browsers).
1010

11+
## Project setup
12+
13+
Also, because the code tries to connect to the running simulation server, launch Gazebo in a separate terminal (if it is not already running) and verify that the simulation is running (and Sim Time is increasing):
14+
15+
gazebo
16+
17+
Unlike software packages that are installed once per machine, NodeJs packages like Gazebojs are installed inside each node project. Create a NodeJS project for this tutorial, and install a local copy of the gazebojs package with npm:
18+
19+
mkdir gazeboJsCam
20+
cd gazeboJsCam
21+
npm init
22+
23+
Just press enter to get the default values. This operation generates a package.json file. Add gazeboJs to your package file:
24+
25+
npm install gazebojs --save
26+
27+
Now you can create javascript files and execute them by invoking node.
28+
1129
### Code
1230

13-
Create a file
31+
Create a file
1432

1533
gedit save_jpeg.js
1634

@@ -83,17 +101,17 @@ gazebo.subscribeToImageTopic(src_topic, function (err, img){
83101
console.log('bye');
84102
process.exit(0);
85103
}
86-
104+
87105
// make a nice zero padded number (0003 instead of 3)
88106
var nb = pad(savedFrames, 4);
89107
var fname = dest_path + '_' + nb + '.jpeg' ;
90108
fs.writeFile(fname, img, {encoding:'binary'}, function (err) {
91-
if(err)
109+
if(err)
92110
console.log('ERROR: ' + err);
93111
else
94112
console.log(fname + ' saved');
95113
});
96-
114+
97115
}, options);
98116
99117
~~~
@@ -120,7 +138,7 @@ First, you must setup Gazebo. In an empty world, add a few items (the double pen
120138
Invoke the script
121139

122140
node save_jpeg.js camera frame 10
123-
141+
124142
You should see the following output:
125143

126144
~~~

0 commit comments

Comments
 (0)