官方教程:http://gazebosim.org/tutorials?tut=plugins_world&cat=write_plugin
本系列关注的 是如何在仿真的过程中加入已经生成好的模型,就是仿真实际情况下物体出现的随机性。仿真无人机在实际过程中遇到 突然出现的障碍物的反应和路径规划等。
《一》模型的插入方法
模型有三种方法在plugin中插入到仿真环境:
其一:利用gazebo环境下的模型,这一要保证The filename must be in the GAZEBO_MODEL_PATH environment variable(官网:The first method uses a World method to load a model based on a file in the resource path defined by the GAZEBO_MODEL_PATH environment variable.)
_parent->InsertModelFile("model://box");
其二:将模型定义成字符串类型,通过函数的调用(官网:The second method uses a World method to load a model based on string data.
):
sdf::SDF sphereSDF;
sphereSDF.SetFromString(
"<sdf version ='1.4'>\
<model name ='sphere'>\
<pose>1 0 0 0 0 0</pose>\
<link name ='link'>\
<pose>0 0 .5 0 0 0</pose>\
<collision name ='collision'>\
<geometry>\
<sphere><radius>0.5</radius></sphere>\
</geometry>\
</collision>\
<visual name ='visual'>\
<geometry>\
<sphere><radius>0.5</radius></sphere>\
</geometry>\
</visual>\
</link>\
</model>\
</sdf>");
// Demonstrate using a custom model name.
sdf::ElementPtr model = sphereSDF.Root()->GetElement("model");
model->GetAttribute("name")->SetFromString("unique_sphere");
_parent->InsertModelSDF(sphereSDF);
其三:通过消息传送机制(官网:The third method uses the message passing mechanism to insert a model. This method is most useful for stand alone applications that communicate with Gazebo over a network connection.)
{
// Create a new transport node
transport::NodePtr node(new transport::Node());
// Initia