[SOLVED] Gazebo_ros_camera doesn't work in Docker


#1

Dear all,

I installed the NRP by using the Docker Installer. I found the Gazebo_ROS plugin “gazebo_ros_camera” doesn’t work and no corresponding rostopic could be found. But another one “gazebo_ros_p3d” works.

I need to gain images from the camera mounted on my robot. I add a camera in the model.sdf and it works well before using Docker.

  <sensor type="camera" name="camera">
    <update_rate>30.0</update_rate>
    <always_on>1</always_on>
    <visualize>true</visualize>
    <topic>/robot/eye</topic>
    <camera name="robot_eye">
      <horizontal_fov>1.5707963267948966</horizontal_fov>
      <image>
        <width>320</width>
        <height>240</height>
        <format>R8G8B8</format>
      </image>
      <clip>
        <near>0.01</near>
        <far>100</far>
      </clip>
      <noise>
        <type>gaussian</type>
        <mean>0.0</mean>
        <stddev>0.007</stddev>
      </noise>
    </camera>
    <plugin name="camera_controller" filename="libgazebo_ros_camera.so">
      <alwaysOn>true</alwaysOn>
      <updateRate>0.0</updateRate>
      <cameraName>robot/camera</cameraName>
      <imageTopicName>image_raw</imageTopicName>
      <cameraInfoTopicName>camera_info</cameraInfoTopicName>
      <frameName>camera_link</frameName>
      <hackBaseline>0.07</hackBaseline>
      <distortionK1>0.0</distortionK1>
      <distortionK2>0.0</distortionK2>
      <distortionK3>0.0</distortionK3>
      <distortionT1>0.0</distortionT1>
      <distortionT2>0.0</distortionT2>
    </plugin>
  </sensor>

Does anyone know how to solve this problem?

Thanks!
Zhuangyi


#2

Hi Zhuangyi!

Have you tested the camera running one of the template experiments? The Husky Braitenberg experiment, for example.

Ugo


#3

Hi Ugo,

Yes, I have. When I ran the Husky Braitenberg experiment in docker, the rostopic “/husky/husky/camera” echoed nothing. I also tested other template experiments, but all failed.

Best regards,
Zhuangyi


#4

Hi Zhuangyi,

it looks like some problem with your graphics driver setup. Could you enter the docker container and run the next command:

gzserver --verbose

then please share the output here.

thanks.


#5

Hi ercarrion43,

Yes, there really is a display error. But I still don’t know how to fix it.

bbpnrsoa@ebb2dc28cd8d:~/nrp/src$ gzserver --verbose
Gazebo multi-robot simulator, version 7.2.0.hbp.2.2.2
Copyright © 2012-2016 Open Source Robotics Foundation.
Released under the Apache 2 License.
http://gazebosim.org

[Msg] Waiting for master.
[Msg] Connected to gazebo master @ http://127.0.0.1:11345
[Msg] Publicized address: 172.19.0.3
[Err] [RenderEngine.cc:699] Can’t open display:
[Wrn] [RenderEngine.cc:97] Unable to create X window. Rendering will be disabled
[Wrn] [RenderEngine.cc:301] Cannot initialize render engine since render path type is NONE. Ignore this warning ifrendering has been turned off on purpose.

Zhuangyi


#6

@izy91 did you ever solve this problem? I have the same issue.

Running ROS Noetic in my Ubuntu VM and I have no issues with the camera and see these lines in the terminal:

[ INFO] [1610270432.293487831, 0.116000000]: Camera Plugin: Using the 'robotNamespace' param: '/'
[ INFO] [1610270432.299547451, 0.116000000]: Camera Plugin (ns = /)  <tf_prefix_>, set to ""

However, when doing the same thing inside a docker container (osrf/ros:noetic-desktop-full-focal) these lines just never appear and there is nothing in the logs about it - no camera topics are ever published and no errors are shown. I’ve tried apt-update and apt-upgrade to no avail…

I’ve been trying to figure this out for a few hours now and haven’t gotten anywhere, any help would be much appreciated!


#7

ok I fixed it - @ercarrion43 you were absolutely right with your assumption. Here’s the solution:

docker run -it -p 7681:7681 -p 8080:8080 -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix --name gui-test osrf/ros:noetic-desktop-full-focal /bin/bash

-e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -> being what I needed to do differently

Then run this on the host:

xhost local:docker

Reference: https://askubuntu.com/questions/1161646/is-it-possible-to-run-docker-container-and-show-its-graphical-application-window