1,我们可以在模型的urdf文件或者sdf文件中加入下面这段代码,这是给模型加入一个ros plugin——libgazebo_ros_p3d。
<gazebo>
<plugin name="p3d_base_controller" filename="libgazebo_ros_p3d.so">
<alwaysOn>true</alwaysOn>
<updateRate>50.0</updateRate>
<bodyName>base_link</bodyName>
<topicName>ground_truth/state</topicName>
<gaussianNoise>0.01</gaussianNoise>
<frameName>world</frameName>
<xyzOffsets>0 0 0</xyzOffsets>
<rpyOffsets>0 0 0</rpyOffsets>
</plugin>
</gazebo>
2、加入之后,启动gazebo,加载好了模型之后,在console中敲
rostopic list
3、然后就会出现**/groundtruth/state**这个topic,这个topic发布的数据类型为:nav_msgs/odometry。然后在ros node中订阅这个topic就可以收到这个model的pose了。
4、注意:对于nav_msgs/odometry 中的位置,是通过层层的消息类型定义得到的。
例:const nav_msgs::Odometry::ConstPtr& msg
获得gazebo 中x,y,z的坐标为:
(msg->pose).pose.position.x
(msg->pose).pose.position.y
(msg->pose).pose.position.z