Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to spawn multiple clone of model using msg::Factory?

I am using world plugin as model spawner with this code snippet

 for(auto object:objects){
        ROS_INFO("Spawn %s", object.name.c_str());
        msg.set_sdf_filename("model://"+object.name);
        msgs::Set(
        msg.mutable_pose(),
            ignition::math::Pose3d(
                ignition::math::Vector3d(object.point.x, object.point.y, 0),
                ignition::math::Quaterniond(0, 0, object.yaw)
            )
        );
        factoryPub->Publish(msg);
    }

The trouble is when I try to spawn multiple models by cloning same sdf file, Gazebo only spawn one object per one SDF model even there are multiple object element with same SDF model but different coordinate inside objects vector such as

for(int i = 0; i < 4; ++i){
        objects.push_back(
            object_t(
                "furniture", i, i, 0.0
            )
        );
    }

Is there any way to spawn multiple clone with c++? Msg factory method is preferrable

How to spawn multiple clone of model using msg::Factory?

I am using world plugin as model spawner with this code snippet

  for(auto object:objects){
        ROS_INFO("Spawn %s", object.name.c_str());
        msg.set_sdf_filename("model://"+object.name);
        msgs::Set(
        msg.mutable_pose(),
            ignition::math::Pose3d(
                ignition::math::Vector3d(object.point.x, object.point.y, 0),
                ignition::math::Quaterniond(0, 0, object.yaw)
            )
        );
        factoryPub->Publish(msg);
    }

The trouble is when I try to spawn multiple models by cloning same sdf file, Gazebo only spawn one object per one SDF model even there are multiple object element with same SDF model but different coordinate inside objects vector such as

 for(int i = 0; i < 4; ++i){
        objects.push_back(
            object_t(
                "furniture", i, i, 0.0
            )
        );
    }

Is there any way to spawn multiple clone with c++? Msg factory method is preferrable

How to spawn multiple clone of model using msg::Factory?

I am using model spawner according this world plugin as model spawner tutorial with this code snippetoption number three using msg::factory

 transport::NodePtr node(new transport::Node());
 for(auto object:objects){
node->Init(_parent->Name());
 transport::PublisherPtr factoryPub =
 node->Advertise<msgs::Factory>("~/factory");
 msgs::Factory msg;

 ROS_INFO("Spawn %s", object.name.c_str());
msg.set_sdf_filename("model://cylinder");

       msg.set_sdf_filename("model://"+object.name);
        msgs::Set(
        msg.mutable_pose(),
      msgs::Set(msg.mutable_pose(),
      ignition::math::Pose3d(
                ignition::math::Vector3d(object.point.x, object.point.y, ignition::math::Vector3d(1, -2, 0),
         ignition::math::Quaterniond(0, 0, object.yaw)
0)));

           )
        );
        factoryPub->Publish(msg);
    }
factoryPub->Publish(msg)

The trouble I use this option because it let me set the spawn position. My problem is when I try do not know how to spawn multiple models by cloning same sdf file, Gazebo only spawn one object per one SDF model even there are multiple object element another clone with same SDF model but different coordinate inside file using this method, I tried call objectsfactoryPub->Publish(msg) vector such as

    for(int i = 0; i < 4; ++i){
        objects.push_back(
            object_t(
                "furniture", i, i, 0.0
            )
        );
    }

Is there any way to again but it seem gazebo only spawn multiple clone with c++? Msg factory method is preferrablea model per SDF model file.