How does getChild() and getChildCount() work?
I am making a plugin for this model:
<?xml version="1.0"?>
<sdf version="1.4">
<model name="my_model">
<link name="link">
<gravity>true</gravity>
<inertial>...</inertial>
<sensor name="camera" type="camera">
<pose>0 0 0 0 0 0</pose>
<camera>
<horizontal_fov>2.0</horizontal_fov>
<image>
<width>640</width>
<height>480</height>
</image>
<clip>
<near>1.0</near>
<far>15000</far>
</clip>
</camera>
<always_on>1</always_on>
<update_rate>10</update_rate>
<visualize>1</visualize>
</sensor>
<collision name="collision">...</collision>
<visual name="visual">...</visual>
</link>
<plugin name="myplugin" filename="libmyplugin.so"/>
</model>
</sdf>
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"));
if(base){
boost::dynamic_pointer_cast<gazebo::sensors::CameraSensor>(base)->SetPose(pose);
}
Interestingly base
always ends up being a nullptr
.
When I call
_model->GetLink()->GetChildCount()
I get the children count of 1
.
If I call
_model->GetLink()->GetChild(0)->GetName()
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?