GazeboJs is a C++ addon to NodeJs that is loaded inside node process at runtime (using the
This is the same mechanism that the Gazebo simulation client (the gzclient process) uses to communicate with the simulation server.
The source code for this project can be found here: https://bitbucket.org/osrf/gazebojs
This page explains how to install the GazeboJs Node bindings to Gazebo.
This tutorial shows how to download, install and compile Gazebojs on a computer where Gazebo and its development libraries are installed.
Install the osrf repository and install the development libraries, dependending on the version of Gazebo you are using (for example, libgazebo4-dev for Gazebo 4. see http://gazebosim.org/tutorials?cat=install). The dev Debian package contains the Gazebo header files that are necessary for the gazebojs installation. This is because the NodeJs Gazebo modules are automatically compiled on your machine when the 'npm install gazebojs' is invoked (see below).
Like Gazebo, gazebojs module uses semantic versioning, so the major version of gazebojs should be the same as the major version of Gazebo you are using. You can specify rules about the version of gazebojs you want to use in the
package.json file (see https://www.npmjs.org/doc/files/package.json.html).
Make sure you have curl
sudo apt-get install curl
Install nodejs and npm
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
You may have to install nodejs-legacy if the node command does not exist:
sudo apt-get install nodejs-legacy
If you already have nodejs, make sure that its version >=0.12.x:
If you have a problem with installation or are using a different OS, take a look at the NodeJs documentation.
Tip: In case you want to install more than one version of nodejs on your machine you can use nvm
curl https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh | bash source ~/.profile nvm install [version number e.g: v5] nvm use [version number e.g: v5]
Install jansson (JSON library)
sudo apt-get install libjansson-dev
Make sure that these packages can be found in your pkg-config path. You can check this by executing this command without any error:
pkg-config --cflags gazebo jansson protobuf
Now that everything is installed, here are the steps to test it:
Create a NodeJs project directory
npm install gazebojs || echo "Installation failed!"
This operation should download and compile the latest gazebojs. There is a C++
compilation phase where a NodeJs module is created. There should now be a
gz_node_inst/node_modules directory and you should not see the installation
Test your installation:
Launch Gazebo in a separate terminal and verify that the simulation is running (Sim Time increases):
Use the 'node' command (from the same directory where you invoked the npm command) to invoke the NodeJs REPL console
Type in the following commands to load the gazeboJs module, create a simulation client and pause the running simulation
Note: 'undefined' messages are NodeJS console valid responses to your command
> var gazebojs = require('gazebojs')
> var sim = new gazebojs.Gazebo()
You should see the simulation stop in Gazebo.