Unable to InsertModelSDF into World from model plugin (Bug or Error??)
I'm working on a ModelPlugin that spawns a new model and adjusts the position of the model based on the other model's position. To do this i create an sdf::SDF from string and spawn it with the function world->InsertModelSDF(modelSDF). The function looks like this:
std::string sensor_pose_as = pose3dToString(this->link_pose);
sdf::SDF modelSDF;
modelSDF.SetFromString(
"<sdf version='1.6'>\
<model name='Particle_"+this->parent_save_name_+"'>\
<link name='link_"+this->particle_link_name_+"'>\
<pose frame=''>"+sensor_pose_as+"</pose>\
<gravity>0</gravity>\
<self_collide>0</self_collide>\
<kinematic>0</kinematic>\
<visual name='visual_0'>\
<pose>"+std::to_string(this->p_range)+" 0 0 0 -0 0</pose>\
<geometry>\
<box>\
<size>"+std::to_string(p_size)+" "+std::to_string(p_size)+" 0.001</size>\
</box>\
</geometry>\
<material>\
<lighting>0</lighting>\
<script>\
<uri>file://media/materials/scripts/gazebo.material</uri>\
<name>Gazebo/Grey</name>\
</script>\
</material>\
<transparency>"+std::to_string(this->p_transparency_)+"</transparency>\
<cast_shadows>0</cast_shadows>\
</visual>\
</link>\
<static>0</static>\
</model>\
</sdf>");
sdf::ElementPtr model = modelSDF.Root()->GetElement("model");
for(int i=1; i<=this->num_particles; i++)
{
//do other stuff
}
ROS_INFO("Insert Model into World");
this->model_ = model;
this->world_->InsertModelSDF(modelSDF);
//this->parent_->GetWorld()->InsertModelString(modelSDF.ToString());
common::Time::MSleep(1000);
ROS_INFO("Setting Pose");
math::Pose p = math::Pose(this->link_pose);
this->particle_model_ = this->parent_->GetWorld()->GetModel("Particle_"+this->parent_save_name_);
ROS_INFO("2 %s",this->particle_model_->GetName().c_str());
this->particle_model_->SetLinkWorldPose(p, this->particle_link_name_);
ROS_INFO("Particle Model loaded properly");
I used the exact same function in a SensorPlugin and it worked perfectly. When i debugged the programm this
this->particle_model_ = this->parent_->GetWorld()->GetModel("Particle_"+this->parent_save_name_);
always return NULL. Already checked the modelSDF Variable in a extern file and it's okay. Don't know if its a bug since it worked perfectly in my other Plugin.