Gazebo | Ignition | Community
Ask Your Question

NickDP's profile - activity

2016-11-01 08:06:19 -0500 received badge  Guru (source)
2016-11-01 08:06:19 -0500 received badge  Great Answer (source)
2015-10-31 12:30:42 -0500 marked best answer How to receive a GzString

Hi all

I'm trying to send a string via the Gazebo transport system. I managed to write a plugin that publishes the string I want as a GzString message. I now want to write a receiver that does something with the string. My starting point for this is this listener example.

The problem I have is that I don't know what to do with my received string in the call back function (called cb in the above example). I have changed the call back function to accommodate for the fact that the message is a GzString as follows, but the change was essentially just a guess (replacing ConstWorldStatisticsPtr with ConstWorldStatisticsPtr) and I don't know if this is actually what I need to do. I can't find any documentation regarding this.

void cb(ConstWorldStatisticsPtr &_msg)
  // Dump the message contents to stdout.
  std::cout << _msg->DebugString();

The ->DebugString(); does not necessarily seem appropriate for a string, but I don't know what else to use or where to find documentation about this.

Can somebody help me or point me to where this is described?



P.S: What I'm trying to accomplish is to communicate joint angles back and forth. I would like to be able to have one message type that is able to handle a different number of joints. Right now, I just write the joint names and angle values into the string and parse them out on the receiving side. I realize that this is not very elegant but I couldn't figure out a better way. If you can offer help in doing this differently, I would also be open to suggestions.

2015-10-31 12:30:41 -0500 marked best answer gazebo::common::Exception when running Gazebo as a library

I am trying to run Gazebo as a library using the command

gazebo::setupClient(_argc, _argv);

and loading a world using

gazebo::physics::WorldPtr world = gazebo::loadWorld("worlds/");

I.e. I want to do what the example custom_main does.

However, when I compile and run this example (after running gazebo in a separate terminal), I get the following run-time error:

terminate called after throwing an instance of 'gazebo::common::Exception'
Aborted (core dumped)

gazebo::setupClient(_argc, _argv); returns true, but gazebo::physics::WorldPtr world == NULL. This is the case no matter the content of the string that I give to gazebo::loadWorld(). Looking at the source, I would expect to see some error messages in the console (or is that not where gzerr prints to?), but I don't, even if the string does not name a world file that exists.

What am I doing wrong?


2015-10-31 12:30:20 -0500 marked best answer Model::SetWorldPose() not moving a model permamently

I am running Gazebo (version 4.1.0) as a library in my own main().

I am able load a robot model from a file. Now I want to move the model to some (x,y) position in order to be able to load more than one robot and not have them all sit at the origin. I don't want to have to set the pose in the SDF/URDF file itself because I want to use the same file to spawn several models at different positions.

I am trying to do this using Model::SetWorldPose(). I can see in gzclient that this moves the model. But I have two problems:

  • When I load the robot, all joints are at 0, as is to be expected. After moving the robot, that is no longer the case. They appear to be slightly moved in some arbitrary way. The bigger problem however is:

  • After moving the model, every time I do RunBlocking(1) (the simulation is not free running, I advance it myself after moving the model) on my world pointer, the robot model moves closer to the origin (while the robot's joints change more and more) until it is once again at the origin.

Is this what's supposed to happen? How can I move the robot such that it stays where I put it? I have also tried to move the model using Model::SetLinkWorldPose(), with the same result.

Thanks in advance


The robot model in question is the following (it is converted from a URDF file using gz sdf -p):

<sdf version='1.5'>
  <model name='sixaxis_no_plugin'>
    <link name='link0'>
      <pose>0 0 0 0 -0 0</pose>
        <pose>0 0 0.1 0 -0 0</pose>
      <collision name='link0_collision'>
        <pose>0 0 0.1 0 -0 0</pose>
            <size>0.25 0.25 0.2</size>
      <visual name='link0_visual'>
        <pose>0 0 0.1 0 -0 0</pose>
            <size>0.25 0.25 0.2</size>
    <joint name='joint0' type='revolute'>
        <xyz>0 0 1</xyz>
    <link name='link1'>
      <pose>0 0 0.2 0 -0 0</pose>
        <pose>0 0 0.1 0 -0 0</pose>
      <collision name='link1_collision'>
        <pose>0 0 0.1 0 -0 0</pose>
            <ode ...
2015-10-31 12:30:13 -0500 marked best answer Gazebo Topics disappear

I am trying to control a robot in Gazebo through the messaging system. For this I have a model plugin and four different topics. The model plugin subscribes to two of the topics and advertises on the other two. This works fine for one robot.

Now I want to do this with more than one robot in one world. I.e. I want to have two robot models in Gazebo, each with a model plugin and each with its own set of topics.

The problem I have is that some of the topics I create for the first robot seem to disappear once I create the topics for the second robot.

For each robot I create an instance of a controller class that subscribes and advertises to topics (which are named based on the robots' names). After the constructor for the first robot is done, I can see all four topics by opening the Gazebo Topic selector window (Ctrl + T). If I then let the constructor of the second constructor run, two of the four topics of the first robot are no longer listed in the Gazebo Topic selector window. Specifically, the topics that the model plugin subscribes to (i.e. the ones that are advertised in the controller class) disappear.

One thing that I could see being a problem is that each controller object has its own node, i.e. the constructor does

gazebo::transport::NodePtr node(new gazebo::transport::Node());

Is it a problem that the don't both use the same node? If so, how should I avoid this? Otherwise, what else could be the problem?

2015-10-31 12:27:40 -0500 marked best answer gzsdf: command not found with Gazebo 4.0.2 on Ubuntu 14.04


I'm running Gazebo 4.0.2 on Ubuntu 14.04. I installed Gazebo with the one-line command given here.

I have a URDF file that I want to load in Gazebo. This file is given to me by somebody else and I don't have ROS installed. Following this tutorial, I want to use gzsdf to convert the URDF file to SDF.

However, when I try to run gzsdf, the command is not found. I also can't find the binary in my file system. Where should it be located? What do I need to do to get it?


2015-09-08 13:14:48 -0500 received badge  Taxonomist
2015-07-04 22:47:32 -0500 received badge  Famous Question (source)
2015-06-22 13:16:38 -0500 received badge  Famous Question (source)
2015-06-21 08:10:28 -0500 received badge  Famous Question (source)
2015-06-19 07:27:01 -0500 received badge  Famous Question (source)
2015-06-18 14:29:25 -0500 commented question Insert model programmatically and get its model pointer

Unfortunately I no longer have access to the code. But I believe I followed nkoenigs advice below and paused the simulation, then proceeded as in the first code snippet in the OP and then unpaused.

2015-04-28 11:51:16 -0500 received badge  Good Question (source)
2015-04-20 07:07:35 -0500 received badge  Famous Question (source)
2015-04-20 06:04:47 -0500 received badge  Notable Question (source)
2015-04-20 06:04:47 -0500 received badge  Famous Question (source)
2015-03-15 23:38:04 -0500 received badge  Notable Question (source)
2015-03-15 23:37:56 -0500 received badge  Famous Question (source)
2015-03-02 18:22:02 -0500 answered a question I have to make a SDF from URDF

Have you looked at the URDF in Gazebo tutorial?

In particular, make sure that you add an inertia element to each link.

2015-02-21 21:27:27 -0500 received badge  Famous Question (source)
2015-01-29 10:26:58 -0500 received badge  Good Answer (source)
2015-01-29 10:26:58 -0500 received badge  Enlightened (source)
2015-01-14 05:35:28 -0500 received badge  Notable Question (source)
2015-01-13 11:43:26 -0500 received badge  Notable Question (source)
2015-01-13 04:05:39 -0500 received badge  Popular Question (source)
2015-01-13 04:05:39 -0500 received badge  Notable Question (source)
2015-01-13 04:05:39 -0500 received badge  Famous Question (source)
2015-01-09 14:40:27 -0500 marked best answer Forcing Gazebo to render at fixed intervals or how to record a video of a simulation

I want to be able to get a video of a Gazebo simulation. As far as I can tell, people are doing that by recording their desktop with things like RecordMyDesktop. I don't find this to be very elegant, but more importantly my simulation runs very slow and I want the video to be real-time speed. The reason why the simulation is slow is that I have an external program communicating with a Gazebo plugin. The plugin's OnUpdate() blocks until communication with the external program completes.

To get around this, I wanted to save images from the simulation at every simulation step with the help of a system plugin as described in this tutorial and then convert them into a video with ffmpeg/avconv. However, I found that the video produced is very choppy. It looks like the plugin's call back function event::Events::ConnectPreRender(boost::bind(&ImagePlugin::Update, this))); is not actually called at fixed simulation time intervals. This appears to be true even when limiting the simulation by adding the following to the .world file, which effectively forces the real time factor to be 0.01:

<physics type="ode">

This also not very satisfactory because with this, the simulation is running at a very conservative speed.

The next thing I tried was to run the simulation and record/log it, then filter the log to get a recording at a given update rate (with the -z argument) and playing that back with the system plugin that records the images:

# run the simulation headlessly and record it    
gzserver -r
# filter the log file at 30Hz
gz log -e -f ~/.gazebo/log/*/gzserver/state.log -z 30 --filter *.pose/*.pose > /tmp/filtered_state.log
# run the simulation from the recording and take pictures
gazebo -u -p /tmp/filtered_state.log -g image_plugin/build/

This, however, runs the simulation very quickly and the plugins' Update() function is not executed 30 times per simulation-time second.

So my question is this: What can I do to get an image of the simulation at fixed intervals?

Thanks in advance.

2014-12-16 16:22:17 -0500 received badge  Notable Question (source)
2014-12-16 15:31:33 -0500 commented question InsertModelSDF potential race condition

In your test script you don't declare `model_path`. Can you fix it?

2014-12-16 14:05:57 -0500 answered a question InsertModelSDF potential race condition

Regarding your additional questions, my question and nkoenig's answer here is relevant.

2014-12-16 13:59:45 -0500 received badge  Notable Question (source)
2014-12-16 13:24:50 -0500 commented answer Inserting camera model programmatically

With this addition the example code works. However, in my actual application I still can't get it to work. I wrote a library that runs the Gazebo server and allows me to insert and manipulate models. In my main I have an instance of that class and go through some sample poses etc. So I can't have my main be stuck in this while loop. Am I understanding correctly that there is no way to move the sensor update into my library, for example in a callback to Events::ConnectWorldUpdateBegin?

2014-12-16 08:28:43 -0500 received badge  Popular Question (source)
2014-12-15 13:20:16 -0500 commented question Inserting camera model programmatically

Interesting, do I have to call these myself? I would have expected setupServer() to take care of this kind of thing. If I add these two commands to my main after loading the world, I the model is loaded, i.e. I can see the box in the world. However, I can't see the camera visualization and there are no frames saved to /tmp/gazebo_frames.

2014-12-15 12:34:57 -0500 commented question Inserting camera model programmatically

sorry about that. Hopefully now you can find what you're looking for.

2014-12-15 11:26:27 -0500 commented question Inserting camera model programmatically

I edited the question to include the backtrace. Can you conclude anything from it?

2014-12-13 09:17:33 -0500 received badge  Famous Question (source)
2014-12-12 13:22:44 -0500 asked a question Inserting camera model programmatically

I want to be able to record a simulation in Gazebo. For this I use a camera model, as discussed in this question.

The following camera model works fine if I insert it from the Gazebo GUI or if I include it in a .world file. (The model is taken from the above question, with the only notable difference that I moved <save> element into the <camera> element, which appears to be necessary):

<?xml version="1.0" ?>
<sdf version="1.5">
  <model name="camera">
    <pose>4 -4 4 0 0.5 2.4</pose>
    <link name="link">
      <pose>0.05 0.05 0.05 0 0 0</pose>
      <visual name="visual">
            <size>0.1 0.1 0.1</size>
      <sensor name="camera" type="camera">
          <save enabled="true">

The problem

Now I want to be able to insert the model programmatically, when using Gazebo as a library.

I have created a minimum working example here: Pastebin

When I run this MWE I get a segmentation fault (after inserting the model, in the while loop where I wait for the model to show up). If I remove the <sensor> element, inserting the model is successful.

What am I doing wrong?

Thanks for your help.


Below is the backtrace from running the MWE:

Starting program: /home/nicolas/GazeboAgentCameraExample/build/main 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/".
[New Thread 0x7fffdd4c4700 (LWP 13481)]
[New Thread 0x7fffdccc3700 (LWP 13482)]
[New Thread 0x7fffdc4c2700 (LWP 13483)]
[New Thread 0x7fffdb3d3700 (LWP 13484)]
[New Thread 0x7fffd8dc4700 (LWP 13485)]
[New Thread 0x7fffd0a10700 (LWP 13486)]
[New Thread 0x7fffcbfff700 (LWP 13487)]
[New Thread 0x7fffcb7fe700 (LWP 13488)]
[New Thread 0x7fffcaffd700 (LWP 13489)]
Gazebo server setup successful
[New Thread 0x7fffca3c4700 (LWP 13490)]
[New Thread 0x7fffc9bc2700 (LWP 13492)]
[New Thread 0x7fffc9fc3700 (LWP 13491)]
[New Thread 0x7fffc97c1700 (LWP 13493)]
[New Thread 0x7fffc8fc0700 (LWP 13495)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffc97c1700 (LWP 13493)]
0x00007ffff1f93fa9 in gazebo::sensors::SensorFactory::NewSensor(std::string const&) () from /usr/lib/x86_64-linux-gnu/
(gdb) thread apply all bt

Thread 15 (Thread 0x7fffc8fc0700 (LWP 13495)):
#0  pthread_cond_wait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185
#1  0x00007ffff7b53efb in ?? () from /usr/lib/x86_64-linux-gnu/
#2  0x00007ffff7b4aec7 in gazebo::physics::World::LogWorker() () from /usr/lib/x86_64-linux-gnu/
#3  0x00007ffff4c45a4a in ?? () from /usr/lib/x86_64-linux-gnu/
#4  0x00007ffff7151182 in start_thread (arg=0x7fffc8fc0700) at pthread_create.c:312
#5  0x00007ffff6963efd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111

Thread 14 (Thread 0x7fffc97c1700 (LWP 13493)):
#0  0x00007ffff1f93fa9 in gazebo::sensors::SensorFactory::NewSensor(std::string const&) () from /usr/lib/x86_64-linux-gnu/
#1  0x00007ffff1f96e67 in ...
2014-12-12 12:52:52 -0500 received badge  Notable Question (source)
2014-12-11 16:49:40 -0500 received badge  Popular Question (source)
2014-12-11 14:12:02 -0500 marked best answer Insert model programmatically and get its model pointer

When running Gazebo as a library, I want to insert a robot model. I have the model as an SDF string (which I converted from a URDF file).

I want to be able to insert this model and get the corresponding ModelPtr. I am able to do this if the world is not running when inserting the model, as follows:

// Assume the world is not running at this point.
std::string modelString; // this contains a valid SDF model
gazebo::physics::ModelPtr insertedModel;

int modelCountBefore = world->GetModelCount();
// need to advange the physics engine in order for the model count to increase
if(world->GetModelCount() == modelCountBefore+1)
    // sucess
    insertedModel = world->GetModel(modelCountBefore);
    // failure

This works, but it's not necessarily very pretty.

I would like to be able to insert a model into a running world. If the world is already running, the above won't work. The code below inserts a model when the world is already running.

// Assume the world is running at this point.
std::string modelString; // this contains a valid SDF model
gazebo::physics::ModelPtr insertedModel;

// need to wait several iterations until models are loaded into Gazebo
int timer = 0;
while(world->GetModelCount() == modelCountBefore)
    if(timer > 1000)
if(world->GetModelCount() == modelCountBefore+1)
    // sucess
    insertedModel = world->GetModel(modelCountBefore);
    // failure

This is even more cumbersome. In addition, I have some severe problems when I insert the model with the second method. The model does not behave as it should at all when I use my controller on it. Sometimes the joints just move around arbitrarily, sometimes the joints appear to be fixed to some wrong locations, which causes the robot's links to fly apart when moving the joints. Sometimes it behaves fine. This behavior is not deterministic, something different happens every time I execute the same identical code.

What is the best way to reliably insert a model into a running simulation and get the corresponding ModelPtr?

2014-12-11 14:04:44 -0500 commented answer Insert model programmatically and get its model pointer

Thanks. Right now I stop the simulation with gazebo::physics::World::Stop() before inserting the model. Is there an advantage to using SetPaused()?

2014-12-11 03:32:40 -0500 received badge  Nice Question (source)