Gazebo Answers logo

I am making a plugin for this model:

<?xml version="1.0"?> 
<sdf version="1.4">
  <model name="my_model">

    <link name="link">

      <sensor name="camera" type="camera">
        <pose>0 0 0 0 0 0</pose>

      <collision name="collision">...</collision>
      <visual name="visual">...</visual>

    <plugin name="myplugin" filename="libmyplugin.so"/>

In the plugin I want to manipulate the pose of the camera. The code I use to do this is:

gazebo::physics::BasePtr base = _model->GetLink()->GetChild(std::string("camera"));

Interestingly base always ends up being a nullptr.

When I call


I get the children count of 1.

If I call


I get "collision". So it seems like the only children to the <link> is the <collision>. This seems quite unlogical for me and I am stuck. I also tried adding another collision tag to the model SDF, GetChildCount then increases to 2, and both collisions can be listed. Is there something about the semantics of GetChild() that I do not understand? I thought I could manipulate the camera using it?

Originally posted by lysgaard on Gazebo Answers with karma: 3 on 2017-02-13

Post score: 0


1 Answer 1


Gazebo Answers logo

The gazebo::physics library deals with physics entities, such as models, links and collisions. Therefore, when you get a child entity, you get one of these physics objects.

Sensors are handled by a separate library, gazebo::sensors. I can see how that can be confusing, but even though the camera sensor is a child of the link in SDF, it isn't a child for the physics library. The maximum the physics library can give you is the name and number of sensors, but no pointers. Take a look at these functions:

To get a pointer to the camera sensor, you'll have to use the sensor library like this for example:

auto camera = sensors::SensorManager::Instance()->GetSensor("my_model::link::camera");

Originally posted by chapulina with karma: 7504 on 2017-02-13

This answer was ACCEPTED on the original site

Post score: 1

Original comments

Comment by lysgaard on 2017-02-14:
Thanks for the good answer. Might I suggest that the GetChild() and GetChildCount() documentation is updated to include a note about it's limitations, and maybe even a link to other possibly wanted functions like GetSensor()?

Comment by chapulina on 2017-02-14:
Sure, I created an issue for that: https://bitbucket.org/osrf/gazebo/issues/2194/improve-api-documentation-for-getchild


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.