Gazebo | Ignition | Community
Ask Your Question
0

class gazebo::physics::World’ has no member named ‘GetModel’; did you mean ‘Models’?

asked 2019-08-20 09:27:53 -0500

PeterHer gravatar image

updated 2019-08-22 09:26:28 -0500

kumpakri gravatar image

Hi All,

I am very new to Gazebo and ROS. I have the following code snippet in my Ros World Plugin:

    void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf)
    {
        physics::ModelPtr ballmodel;
        ballmodel = _world->GetModel("ball");

Any idea why I always get a error like class gazebo::physics::World’ has no member named ‘GetModel’; did you mean ‘Models’?

I am using Ubuntu 18, Melodic and Gazebo 9.

Any idea? Thanks in advance, Peter


EDIT

No idea what's going on, but the ball is not found :-(

class SimulatorPlugin : public WorldPlugin
{
    void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf)
    {
        sdf::SDF ballSDF;
        ballSDF.SetFromString(
        "<sdf version ='1.6'>\
                <model name='ball'>\
                    <pose>0 0 0 0 0 0</pose>\
                        <include>\
                            <uri>/home/peter/gazebo_plugin/models/my_robocup_spl_ball</uri>\
                        </include>\
                </model>\
            </sdf>");

        sdf::ElementPtr ballmodel = ballSDF.Root()->GetElement("model");
        ballmodel->GetAttribute("name")->SetFromString("ball");
        _world->InsertModelSDF(ballSDF);

        physics::ModelPtr ballmodelPtr = _world->ModelByName("ball");
        if (ballmodelPtr != NULL)
        {
            printf("ball found \n");
        }

        _world->LoadPlugin("librifball.so", "rifball", ballmodel);
    }
}
edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2019-08-21 04:34:16 -0500

kumpakri gravatar image

updated 2020-05-05 02:13:24 -0500

This is the API documentation for Gazebo 9. The method you are looking for is ModelByName(name).


reaction to the EDIT

The use of the API looks right. One thing that comes on my mind is that the retrieval of the ball model is happening right after the call for the model insertion into the world. Is it possible the model is still being loaded when you want to get the pointer to it?

What happens if you wait until the model is fully loaded? Something like

class SimulatorPlugin : public WorldPlugin
{
    void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf)
    {
        sdf::SDF ballSDF;
        ballSDF.SetFromString(
        "<sdf version ='1.6'>\
                <model name='ball'>\
                    <pose>0 0 0 0 0 0</pose>\
                        <include>\
                            <uri>/home/peter/gazebo_plugin/models/my_robocup_spl_ball</uri>\
                        </include>\
                </model>\
            </sdf>");

        sdf::ElementPtr ballmodel = ballSDF.Root()->GetElement("model");
        ballmodel->GetAttribute("name")->SetFromString("ball");
        _world->InsertModelSDF(ballSDF);

        physics::ModelPtr ballmodelPtr = _world->ModelByName("ball");

        while(ballmodelPtr == NULL) 
        {
             ballmodelPtr = _world->ModelByName("ball");
        }
        printf("ball found \n");

        _world->LoadPlugin("librifball.so", "rifball", ballmodel);
    }
}

EDIT 2

The solution to wait for the model to be loaded showed above cannot work. The while loop inside the Load function would block all the other processes so the model or anything else would not be loaded ever.

See this answer for the correct solution: https://answers.gazebosim.org/questio...

edit flag offensive delete link more

Comments

Thanks, I was looking at the wrong API

I have tried your code, but it will fall into an endless loop. Skipping the While() this code result back that there world is loaded and only has one Model, named: ground_plane

    void Init()
    {
            printf("IsLoaded: %d \n", my_worldPtr->IsLoaded());
            printf("ModelCount: %d \n", my_worldPtr->ModelCount());
    }

Maybe this has something to do with it when I run the sim. [Err] [REST.cc:205] Error in REST request

PeterHer gravatar imagePeterHer ( 2019-08-21 05:23:56 -0500 )edit

Or maybe this: libcurl: (51) SSL: no alternative certificate subject name matches target host name 'api.ignitionfuel.org'

PeterHer gravatar imagePeterHer ( 2019-08-26 02:33:36 -0500 )edit

BTW, the ball is visible in Gazebo and listed under Models

PeterHer gravatar imagePeterHer ( 2019-08-26 02:35:16 -0500 )edit

@PeterHer try this https://www.youtube.com/watch?v=ftDz_... for the REST error. Otherwise I'm out of ideas. I think it is a good idea to create a new question for this issue. You will get more attention and people will be more willing to help you, if they don't see any answers to your question.

kumpakri gravatar imagekumpakri ( 2019-08-26 03:12:13 -0500 )edit
0

answered 2019-08-22 07:29:21 -0500

PeterHer gravatar image

No idea what's going on, but the ball is not found and compiler shows LoadPlugin doesn't exist :-(

class SimulatorPlugin : public WorldPlugin
{
    void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf)
    {
        sdf::SDF ballSDF;
        ballSDF.SetFromString(
        "<sdf version ='1.6'>\
                <model name='ball'>\
                    <pose>0 0 0 0 0 0</pose>\
                        <include>\
                            <uri>/home/peter/gazebo_plugin/models/my_robocup_spl_ball</uri>\
                        </include>\
                </model>\
            </sdf>");

        sdf::ElementPtr ballmodel = ballSDF.Root()->GetElement("model");
        ballmodel->GetAttribute("name")->SetFromString("ball");
        _world->InsertModelSDF(ballSDF);

        physics::ModelPtr ballmodelPtr = _world->ModelByName("ball");
        if (ballmodelPtr != NULL)
        {
            printf("ball found \n");
        }

        _world->LoadPlugin("librifball.so", "rifball", ballmodel);
    }
}
edit flag offensive delete link more

Comments

I solved the LoadPlugin error, but the ball is still not found

PeterHer gravatar imagePeterHer ( 2019-08-22 07:32:21 -0500 )edit

Please, edit your question with new progress. The updated question should look like this:

<original question>
___
EDIT

<new details>

That is the standard way of specifying your question after there was some progress on it.

Also accept the answer that helped you solve the issue by clicking the check-button next to the correct answer.

If your new question is not strictly related to the original question, make a new question. Please, adhere to the site policy.

kumpakri gravatar imagekumpakri ( 2019-08-22 08:28:05 -0500 )edit

Sorry I really did make a mess of it now. Don't understand the format. Any examples I can look at on how to use the right format here?

PeterHer gravatar imagePeterHer ( 2019-08-22 08:38:07 -0500 )edit

@PeterHer I eddited your question to comply with the format. The main idea is to visibly separate the original question and the edits with 'EDIT' string. When you have more edits, you would write EDIT 1, EDIT 2 and so on.

kumpakri gravatar imagekumpakri ( 2019-08-22 08:49:24 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2019-08-20 09:27:53 -0500

Seen: 6,575 times

Last updated: May 05 '20