Issue executing request to UserCommand plugin

Hello everyone,

I’m facing an issue executing a request to the UserCommand plugin. I’m trying to create a cylinder model using the UserCommand plugin in “shapes.sdf” world but it seems like the request is not executing properly.

The code that I’m using is given below:

xml

gz::msgs::EntityFactory dataMsg;

auto cylinderStr = R"(<?xml version="1.0" ?>
<sdf version='1.7'>
  <model name='cylinder2'>
  <pose>0 -1.5 0.5 0 0 0</pose>
  <link name='cylinder_link'>
    <inertial>
      <inertia>
        <ixx>0.14580000000000001</ixx>
        <ixy>0</ixy>
        <ixz>0</ixz>
        <iyy>0.14580000000000001</iyy>
        <iyz>0</iyz>
        <izz>0.125</izz>
      </inertia>
      <mass>1</mass>
      <pose>0 0 0 0 0 0</pose>
    </inertial>
    <collision name='cylinder_collision'>
      <geometry>
        <cylinder>
          <radius>0.5</radius>
          <length>1</length>
        </cylinder>
      </geometry>
      <surface>
        <friction>
          <ode/>
        </friction>
        <bounce/>
        <contact/>
      </surface>
    </collision>
    <visual name='cylinder_visual'>
      <geometry>
        <cylinder>
          <radius>0.5</radius>
          <length>1</length>
        </cylinder>
      </geometry>
      <material>
        <ambient>0 1 0 1</ambient>
        <diffuse>0 1 0 1</diffuse>
        <specular>0 1 0 1</specular>
      </material>
    </visual>
    <pose>0 0 0 0 0 0</pose>
    <enable_wind>false</enable_wind>
  </link>
  <static>false</static>
  <self_collide>false</self_collide>
</model>
</sdf>)";
dataMsg.set_sdf(cylinderStr);

bool executed = node.Request("/world/shapes/create", dataMsg);
if (executed)
    cout << "Service executed successfully" << endl;
else
    cerr << "Service call timed out" << endl;

The code above tries to create a cylinder model using the UserCommand plugin, a request is made to the /world/shapes/create service to create it. However, it seems like the request is not executing properly as the cylinder it’s not created but the “Service executed successfully” message is displayed.

Can anyone help me with this issue? Any suggestions would be appreciated.

Thank you.

I finally fixed it by changing the request call from:

bool executed = node.Request("/world/shapes/create", dataMsg);

to:

gz::msgs::Boolean reply;
bool result;
const unsigned int timeout = 300;
bool executed = node.Request("/world/basic/create", dataMsg, timeout, reply, result);    

The request to create the object it’s working now.