Installing and Using ROS with gazebo

The following post provides instructions on installing and configuring ROS and interfacing it with gazebo, both programs necessary for creating a functional robot. Note that since both ROS and gazebo possess online instructions, this post will mostly consist of a collection of links detailing guides for each step.


Installing ROS on Ubuntu –

To install gazebo, simply follow the instructions listed in Bowen Wang’s previous post on this blog. Install gazebo version 2, instead of 5, since gazebo 5 is not compatible with ROS.

Installing gazebo_ros_pkgs –


Using roslaunch –

We will use roslaunch to set up the environment of the simulation. Be sure to add a folder named ‘sdf’ under the MYROBOT_description package, so that we can include the MYROBOT.sdf file for our robot model. We can then use rosservice to interact with the robot.

Using these guides, we should be able to perform the following operations:

$ roscore

On a new terminal,

$ . ~/catkin_ws/devel/setup.bash
$ roslaunch MYROBOT_gazebo MYROBOT.launch

Now we should see a gazebo simulation open, with our desired robot model showing. To interact with it, in a new terminal we can enter commands such as:

$ rosservice call /gazebo/apply_body_wrench '{body_name: "my_robot::chassis", wrench: { force: { x: 80.0 } }, start_time: 0, duration: 2000000000 }'

To reset the simulation,

$ rosservice call /gazebo/clear_body_wrenches '{body_name: "my_robot::chassis"}'
$ rosservice call /gazebo/reset_simulation

An alternative to using /gazebo/apply_body_wrench would be to call /gazebo/set_model_state, but this command requires the user to supply all information – otherwise it fills in default parameters and sets the robot at the origin.

Because these are ROS commands, they can be communicated across multiple machines. In addition, these commands can be automated through system calls in C++.

Further resources that may be useful include (Particularly 1.1 and 1.2.4), and