Home | Tutorials | Wiki | Issues
Ask Your Question
0

including models in world file, cannot access joint in model

asked 2019-09-03 05:24:19 -0600

PeterHer gravatar image

updated 2019-09-03 07:39:19 -0600

kumpakri gravatar image

If I create a model like this and import this model in my world file, I cannot access the two joints.

MODEL: (from Gazebo tutorial)

<?xml version='1.0'?>
<sdf version='1.6'>
    <model name="mymodel">
        <static>false</static>

        <link name='chassis'>
          <pose>0 0 .1 0 0 0</pose>
          <collision name='collision'>
            <geometry>
              <box>
                <size>.4 .2 .1</size>
              </box>
            </geometry>
          </collision>

          <visual name='visual'>
            <geometry>
              <box>
                <size>.4 .2 .1</size>
              </box>
            </geometry>
          </visual>

          <collision name='caster_collision'>
            <pose>-0.15 0 -0.05 0 0 0</pose>
            <geometry>
              <sphere>
              <radius>.05</radius>
            </sphere>
          </geometry>

          <surface>
            <friction>
              <ode>
                <mu>0</mu>
                <mu2>0</mu2>
                <slip1>1.0</slip1>
                <slip2>1.0</slip2>
              </ode>
            </friction>
          </surface>
        </collision>

        <visual name='caster_visual'>
          <pose>-0.15 0 -0.05 0 0 0</pose>
          <geometry>
            <sphere>
              <radius>.05</radius>
            </sphere>
          </geometry>
        </visual>
      </link>

      <link name="left_wheel">
        <pose>0.1 0.13 0.1 0 1.5707 1.5707</pose>
        <collision name="collision">
          <geometry>
            <cylinder>
              <radius>.1</radius>
              <length>.05</length>
            </cylinder>
          </geometry>
        </collision>
        <visual name="visual">
          <geometry>
            <cylinder>
              <radius>.1</radius>
              <length>.05</length>
            </cylinder>
          </geometry>
        </visual>
      </link>

      <link name="right_wheel">
        <pose>0.1 -0.13 0.1 0 1.5707 1.5707</pose>
        <collision name="collision">
          <geometry>
            <cylinder>
              <radius>.1</radius>
              <length>.05</length>
            </cylinder>
          </geometry>
        </collision>
        <visual name="visual">
          <geometry>
            <cylinder>
              <radius>.1</radius>
              <length>.05</length>
            </cylinder>
          </geometry>
        </visual>
      </link>

      <joint type="revolute" name="left_wheel_hinge">
        <pose>0 0 -0.03 0 0 0</pose>
        <child>left_wheel</child>
        <parent>chassis</parent>
        <axis>
          <xyz>0 1 0</xyz>
        </axis>
      </joint>

      <joint type="revolute" name="right_wheel_hinge">
        <pose>0 0 0.03 0 0 0</pose>
        <child>right_wheel</child>
        <parent>chassis</parent>
        <axis>
          <xyz>0 1 0</xyz>
        </axis>
      </joint>

    </model>
</sdf>

WORLD:

<?xml version="1.0" ?>
<sdf version="1.6">
  <world name="default">

    <include>
        <uri>model://ground_plane</uri>
    </include>

    <include>
        <uri>model://sun</uri>
    </include>

    <model name='mymodel'>
        <pose>0 0 0 0 0 0</pose>
            <include>
                <uri>/home/test/src/simulator_world/models/my_model</uri>
            </include>
        <plugin name="mymodel" filename="libmymodel.so"/>
    </model>
  </world>
</sdf>

GAZEBO MODEL PLUGIN:

    void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
    {
        this->myModelPtr = _model;
        this->leftWheelJoint = myModelPtr->GetJoint("left_wheel_hinge");
    }

Only if I put the whole model makeup in the world file I can access the Joint. Any idea why?

I have a lot of models which I want to control in the plugin. If all makeup text has to be done in the world file, I get a very large file.

All suggestions are welcome.

Thanks, Peter

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-09-03 07:47:13 -0600

kumpakri gravatar image

The joint is not identified by the model plugin just by its name, but you need to specify also the model it belongs to. I always do it the way shown below.

std::string leftWheelJointName = this->myModelPtr->GetName() + "::left_wheel_hinge";
this->leftWheelJoint = myModelPtr->GetJoint(leftWheelJointName);
edit flag offensive delete link more

Comments

Thanks, problem solved :-)

PeterHer gravatar imagePeterHer ( 2019-09-03 11:24:05 -0600 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-09-03 05:24:19 -0600

Seen: 90 times

Last updated: Sep 03