Gazebo | Ignition | Community
Ask Your Question
0

programmatically turning off a camera

asked 2020-05-02 13:37:39 -0600

altineller gravatar image

Hello,

To make a video recording of my gazebo stage I have followed tutorial at http://gazebosim.org/tutorials?tut=ca... and successfully recorded jpg files for the screen.

How can I turn off this camera programmatically?

Best regards, C.A.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2020-05-02 15:56:43 -0600

nlamprian gravatar image

You can get the sensor and deactivate it:

#include <gazebo/sensors/SensorManager.hh>
sensors::SensorPtr sensor = sensors::SensorManager::Instance()->GetSensor(
    "world_name::model_name::link_name::sensor_name");
sensor->SetActive(false);

If you are not sure about the name, you can get the names of all sensors and identify yours:

for (sensors::SensorPtr sensor : sensors::SensorManager::Instance()->GetSensors())
    gzmsg << sensor->ScopedName() << "\n";

At the same time, you can skip the whole saving images thing, and directly record a video with the camera:

sensors::CameraSensorPtr camera_sensor =
  std::static_pointer_cast<sensors::CameraSensor>(sensor);
camera_sensor->Camera()->StartVideo("mp4");
camera_sensor->Camera()->StopVideo();
camera_sensor->Camera()->SaveVideo("~/recording");
edit flag offensive delete link more

Comments

thank you for the answer. is there any example code that I can work on? I have a setup where I run a simulation for 100seconds, then stop recording at that time. unfortunately, killing gazebo with a timer node, does work, but it takes a varying amount of time to stop, which records more images.

altineller gravatar imagealtineller ( 2020-05-02 16:31:15 -0600 )edit

You can create a world plugin and configure things as you like in there. If you don't wanna get into that, I recently released a plugin that records videos, which you can control through ROS services. See gazebo_video_monitor_plugins

nlamprian gravatar imagenlamprian ( 2020-05-02 17:51:01 -0600 )edit

When I use sensor->SetActive(false); I have to call it several times before the change takes effect, should it be like this?

rezenders gravatar imagerezenders ( 2020-06-16 13:37:00 -0600 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-05-02 13:37:39 -0600

Seen: 185 times

Last updated: May 02 '20