How to publish custom models through plugin
I am currently working on a plugin that spawns objects into the gazebo world. My approach is to use a transport node and messenger to publish the object, just like in the tutorials. I am running into trouble because there doesn't seem to be a way to publish an object without essentially copying out the whole SDF and publishing that. Is there a way to publish object by using only the URI and pose, just like how it's done with the <include>
tag?
// Create a new transport node, initialize with world, and create publisher
transport::NodePtr node(new transport::Node());
node->Init(_world->Name());
transport::PublisherPtr factoryPub = node->Advertise<msgs::Factory>("~/factory");
// create a model and fill it with the correct values
msgs::Model model;
// the line below is where I want to add URI to the model
model.set_sdf_filename(attURI);
model.set_name(attName);
msgs::Set(model.mutable_pose(), ignition::math::Pose3d(10, 10, 10, 1,2,3));
// create a string of the model sdf
std::ostringstream newModelStr;
newModelStr << "<sdf version='" << SDF_VERSION << "'>"
<< msgs::ModelToSDF(model)->ToString("")
<< "</sdf>";
// publish the model
msgs::Factory msg;
msg.set_sdf(newModelStr.str());
factoryPub->Publish(msg);