Home | Tutorials | Wiki | Issues
Ask Your Question
1

Access to the gzclient_camera in a world plugin

asked 2018-06-13 10:28:31 -0500

TTDM gravatar image

updated 2018-06-13 10:32:15 -0500

Hi,

I'm trying to take a picture from a world that I create using a worldPlugin. For practical reasons, I'd like to take the picture at the end of the world plugin.

I noticed that when a gzclient is open, a camera "gzclient_camera" is created. I was hoping to select this camera from the world plugin and then take my picture by doing :

    parent->GetByName("gzclient_camera")->SetPose(anIgnitionPose);
    parent->GetByName("gzclient_camera")->SaveFrame(imgName);

With parent the WorldPtr to my world.

But it seems that it doesn't work. I was wondering if there is a way to select the gzclient_camera from the worldPtr. The API seems to say that "The world provides access to all other object within a simulated environment" but at the same time PrintEntityTree shows only models and the sun.

Thanks for anyone that can help.

PS : I guess it's possible to solve it by creating a sensor plugin and to calling it from the worldPlugin but it seems a little bit over complicated for probably 2 lines of code.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-06-13 10:58:09 -0500

updated 2018-06-13 12:35:31 -0500

World plugins run on gzserver, which is a different process from gzclient. So you won't be able to get a pointer to the user camera, which runs in the client.

You could add a camera sensor to the world and take the screenshot with that instead. And since that would live in sensor land, rather than physics land, I'd use something like this to get it:

auto camera = std::dynamic_pointer_cast<sensors::CameraSensor>(
    sensors::SensorManager::Instance()->GetSensor(cameraName));

That's still 2 lines ;)

edit flag offensive delete link more

Comments

My bad for not seeing your first point. Thanks a lot for the line to retrieve a sensor in a world plugin. Just for the exactitude, there is a little typo, it's 'std::dynamic_pointer_cast<sensors::camerasensor>' and then to use the rendering, the functions should be called as : 'camera->Camera()->SaveFrame(name)' Thanks again

TTDM gravatar imageTTDM ( 2018-06-13 12:31:11 -0500 )edit

Thanks for pointing out the typo, it's fixed

chapulina gravatar imagechapulina ( 2018-06-13 12:35:50 -0500 )edit

And if some readers wonder how to add a camera in a world plugin, I did it in adding a model that includes a camera using the World function: InsertModelString. See an exemple of the sdf here :http://gazebosim.org/tutorials?tut=camera_save&cat=sensors

TTDM gravatar imageTTDM ( 2018-06-13 12:38:07 -0500 )edit

I also want to add that a simple SaveFrame Call is not enough to save a frame. It creates the exact same issue as here: http://answers.gazebosim.org/question/18277/rendering-error-of-camera-sensor-partially-gray-image/ . I'm looking at the other rendering functions and I will post an answer there if I find how to do it properly.

TTDM gravatar imageTTDM ( 2018-06-18 09:28:34 -0500 )edit
Login/Signup to Answer

Question Tools

2 followers

Stats

Asked: 2018-06-13 10:28:31 -0500

Seen: 40 times

Last updated: Jun 13