Spawn a Matrix of Objects over a Heightmap
I'm trying to spawn a matrix of objects to create a field. Ideally this could be done while the model is running so I thought using a plugin was the right strategy. I successfully modified this plugin http://gazebosim.org/tutorials?tut=pl... to place a model at the correct height, but I cannot figure out how to change the name so I can spawn several of the same model. I used the factory portion of the tutorial (option 3) as it will be most convenient to store models in a directory and then call them and place them at the correct location. The main code is copied below. I tried several iterations of using msg.set_clone_mutable_name and some other options with no luck.
// Insert model from file via message passing.
{
// Create a new transport node
transport::NodePtr node(new transport::Node());
// Initialize the node with the world name
node->Init(_parent->Name());
// Create a publisher on the ~/factory topic
transport::PublisherPtr factoryPub = node->Advertise<msgs::Factory>("~/factory");
// Create the messagecatkin
msgs::Factory msg;
msg.set_sdf_filename("model://Cylinder2/");
physics::WorldPtr world = _parent;
physics::ModelPtr model = world->ModelByName("heightmap");
physics::CollisionPtr collision = model->GetLink("link")->GetCollision("collision");
physics::HeightmapShapePtr heightmap =
boost::dynamic_pointer_cast<physics::HeightmapShape>(collision->GetShape());
/* Spawn a matrix of cylinders, doesn't work without changing name.*/
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
// getting the height :
float z_value = heightmap->GetHeight(i, j);
// Pose to initialize the model to
msgs::Set(msg.mutable_pose(),
ignition::math::Pose3d(ignition::math::Vector3d(i, j, z_value+0.5), ignition::math::Quaterniond(0, 0, 0)));
// Send the message
factoryPub->Publish(msg);
}
}
Hi, I am doing the same thing. Have you found any solution to the problem? Thx