You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: gazebojs_camera_topics/tutorial.md
+23-5
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,27 @@ This method only works with 'gazebo.msgs.ImageStamped' topics, and accepts the f
8
8
9
9
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).
10
10
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
+
11
29
### Code
12
30
13
-
Create a file
31
+
Create a file
14
32
15
33
gedit save_jpeg.js
16
34
@@ -83,17 +101,17 @@ gazebo.subscribeToImageTopic(src_topic, function (err, img){
83
101
console.log('bye');
84
102
process.exit(0);
85
103
}
86
-
104
+
87
105
// make a nice zero padded number (0003 instead of 3)
88
106
var nb = pad(savedFrames, 4);
89
107
var fname = dest_path + '_' + nb + '.jpeg' ;
90
108
fs.writeFile(fname, img, {encoding:'binary'}, function (err) {
91
-
if(err)
109
+
if(err)
92
110
console.log('ERROR: ' + err);
93
111
else
94
112
console.log(fname + ' saved');
95
113
});
96
-
114
+
97
115
}, options);
98
116
99
117
~~~
@@ -120,7 +138,7 @@ First, you must setup Gazebo. In an empty world, add a few items (the double pen
0 commit comments