joseandres94
joseandres94

Reputation: 33

Using rviz in a remote connection "Could not connect to any X display."

I am trying to work with rviz by means a remote connection with ssh. When I execute the command rosrun rviz rviz, this error appears:

QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root' qt.qpa.screen: QXcbConnection: Could not connect to display Could not connect to any X display.

I already added the -X flag during the ssh connection, by ssh myusername@host -X but nothing changes.

I don't know what else to do, so any help would be welcomed.

I am working from a Mac computer (macOS Catalina), remotely I am working on a workstation with Docker, and my image has Ubuntu 18.04 and ROS Melodic.

Thank you in advance.

EDIT:

I just tried to execute rviz locally on the workstation and appears the same error, so I suppose the ssh connection is not the problem. Could the problem be due to the Docker or the workstation (Nvidia DGX Station)? Could it be due to permission issue?

Thank you.

Upvotes: 2

Views: 4208

Answers (2)

li9i
li9i

Reputation: 31

I don't currently know about docker, but does the following work for you:

user@local $ export ROS_MASTER_URI=http://your_remote's_hostname:11311

user@local $ rosrun rviz rviz

And see https://wiki.ros.org/ROS/NetworkSetup for the details + ip configuration on both machines.

Upvotes: 1

ichramm
ichramm

Reputation: 6642

Update: Here are some instruction about running GUI apps in docker and MAC, may be useful (in case you haven' seen it already).

I have a docker container with ROS that I use to run rviz and other UI apps (ROS's QT-based apps do not work in KDE Neon).

The docker-compose.yml contains the following:

##############
version: "3.8"

services:
  ros:
    container_name: ros1
    network_mode: host
    # I created my own image, with my own user, etc
    image: YOUR_IMAGE
    volumes:
      # you can ignore this line if you want (I'll explain below)
      # - /home/ichramm/devel/robots:/home/ichramm/devel/robots
      - /etc/localtime:/etc/localtime:ro
      - /tmp/.X11-unix:/tmp/.X11-unix:ro
      - /home/ichramm/.Xauthority:/home/ichramm/.Xauthority:ro
      - /run/user/1000:/run/user/1000:ro
      - /run/user/1000/bus:/run/user/1000/bus:ro
    command: /entrypoint.sh
    environment:
      USER: ichramm
      DISPLAY: ${DISPLAY}
      XDG_RUNTIME_DIR=/tmp/runtime-${USER}
      DBUS_SESSION_BUS_ADDRESS: unix:path=/run/user/1000/bus
    devices:
      #- "/dev/ttyUSB0:/dev/ttyUSB0"
      #- "/dev/dri/card0:/dev/dri/card0"
      #- "/dev/dri/card1:/dev/dri/card1"

You should try to map the mounted volumes to your system. I understand that you have MAC, which means this may not work for you.

This works for me, but I don't use ssh, I just use two scripts:

1.

❯ cat docker-run.sh
#!/bin/bash

docker exec -ti -w $(pwd) ros1 ./wrapper.sh $@
❯ cat wrapper.sh 
#!/bin/bash

export XDG_RUNTIME_DIR=/tmp/runtime-$USER

source env.sh

$@

In order for this to work you need the following:

  1. Mount the working directory in the container (see commented line above)
  2. Have a file env.sh which sources ROS's setup.bash and the workspace devel/setup.bash.

Of course the experience with those scripts its limited, that's why I also enter the docker directly using the following:

❯ cat enter-env.sh 
#!/bin/bash

docker exec -ti -w /home/ichramm/devel/robots ros1 /bin/bash

This works only because the container's directory structure matches the host's. (Note that I only mount the development directory anyway). I also added a user with the same name UID and GID as in the host to prevent issues with file permissions.

If you can't make it work, I suggest you turn to a VM. Just install Ubuntu 20.04 without UI (you can disable it later with sudo systemctl set-default multi-user) and use SSH with X forwarding. I worked with that setup switching to docker and still have the VM in case something happens.

Update: Have in mind that I am doing some potentially unsecure things, like mounting .Xauthority. It works for me because no one else has access to my computer.

Upvotes: 0

Related Questions