diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..552642c --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.sh text eol=lf diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index af37d2d..c8e90d8 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -10,4 +10,4 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - run: docker build . \ No newline at end of file + - run: docker compose build diff --git a/Dockerfile b/Dockerfile index 053f1a7..9ab4394 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,13 @@ # pull container from https://hub.docker.com/_/ros, choosing the melodic-robot-bionic version -FROM ros:melodic-robot-bionic - +FROM ros:noetic # install dependencies for the F1Tenth simulator and wget (and now pip) -RUN sudo apt-get update - -RUN sudo apt-get -y install ros-melodic-ackermann-msgs ros-melodic-tf2-geometry-msgs ros-melodic-interactive-markers ros-melodic-cv-bridge ros-melodic-image-transport ros-melodic-rviz ros-melodic-joy ros-melodic-map-server wget vim python3-pip -# switch to bash for running commands - -# mightn't be necessary -RUN pip3 install -U pip - -RUN rm /bin/sh && ln -s /bin/bash /bin/sh -# initialise ROS, pull useful scripts from our repo and clone the F1Tenth simulator into a new catkin workspace -RUN source /ros_entrypoint.sh && \ - source /opt/ros/melodic/setup.bash && \ - git clone https://github.com/FT-Autonomous/f1tenth-ros-setup.git && \ - mv f1tenth-ros-setup/utils /utils && \ - rm -rf f1tenth-ros-setup && \ - mkdir -p f1tenth_workspace/src && \ - cd f1tenth_workspace/src && \ - git clone https://github.com/f1tenth/f1tenth_simulator.git && \ - cd f1tenth_simulator/maps && \ - git init && \ - git remote add racetracks https://github.com/f1tenth/f1tenth_racetracks && \ - git pull racetracks main +RUN apt update && apt install -y ros-noetic-xacro ros-noetic-ackermann-msgs ros-noetic-tf2-geometry-msgs ros-noetic-interactive-markers ros-noetic-cv-bridge ros-noetic-image-transport ros-noetic-rviz ros-noetic-joy ros-noetic-map-server wget neovim python3-pip x11vnc xvfb xorg-dev git python3-numpy +# Initialise code for geting graphical output from the docker container +RUN git clone https://git.suckless.org/st/ && cd st && make clean install ; \ + git clone https://github.com/FT-Autonomous/dwm && cd dwm && make clean install ; \ + git clone https://github.com/novnc/noVNC.git /noVNC ; \ + git clone https://github.com/novnc/websockify /noVNC/utils/websockify +# Pull in utility scripts +COPY ./utils /utils +RUN cp -f /bin/bash /bin/sh +RUN /utils/setup-workspace.sh /f1tenth_workspace diff --git a/README.md b/README.md index 3c3a12a..46578bf 100644 --- a/README.md +++ b/README.md @@ -5,39 +5,47 @@ A simplified setup and workspace for using F1Tenth with ROS and Docker. ## Prerequisites ### Windows/Mac + * [git](https://www.atlassian.com/git/tutorials/install-git) * [Docker Desktop](https://www.docker.com/products/docker-desktop) +* [Docker Compose](https://docs.docker.com/compose/install/) ### Editor + * [Visual Studio Code](https://www.toolsqa.com/blogs/install-visual-studio-code/) (unless you have some other preference) ### Linux -* Make sure to sync packages before installing new packages -* [git](https://www.atlassian.com/git/tutorials/install-git) - * Debian based - * `sudo apt update` (syncing packages) - * `sudo apt install git` - * Arch based - * `sudo pacman -Sy` (syncing packages) - * `sudo pacman -S git` - * Gentoo based - * `sudo emerge --sync` (syncing packages) - * `sudo emerge git` + +Make sure to sync packages before installing new packages + +#### Git - + +* Debian based + * `sudo apt update` (syncing packages) + * `sudo apt install git` +* Arch based + * `sudo pacman -Sy` (syncing packages) + * `sudo pacman -S git` +* Gentoo based + * `sudo emerge --sync` (syncing packages) + * `sudo emerge git` -* [Docker](https://www.docker.com/products/docker-desktop) - * [Debian based](https://docs.docker.com/engine/install/ubuntu/) - * [Arch based](https://wiki.archlinux.org/title/Docker) - * `sudo pacman -S yay base-devel` - * `yay -S docker-git` - * [Gentoo based](https://wiki.gentoo.org/wiki/Docker) - * `sudo emerge app-containers/docker app-containers/docker-cli` - -#### Systemd based - Debian/Arch etc +#### Docker - + +* [Debian based](https://docs.docker.com/engine/install/ubuntu/) + * See [here](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-compose-on-ubuntu-20-04) for instructions on how to install docker compose on ubuntu. +* [Arch based](https://wiki.archlinux.org/title/Docker) + * `sudo pacman -S yay base-devel` + * `yay -S docker-git docker-compose` +* [Gentoo based](https://wiki.gentoo.org/wiki/Docker) + * `sudo emerge app-containers/docker app-containers/docker-cli app-containers/docker-compose` + +#### Starting the Docker daemon + +##### Systemd based - Debian/Ubuntu/Arch etc * `sudo systemctl enable docker` * `sudo systemctl start docker` -#### Init Systems - ##### OpenRC - Gentoo * `sudo rc-update add docker` * `sudo rc-service docker start` @@ -62,7 +70,7 @@ The build might take a while to load the first time you run it. ``` cd f1tenth-ros-setup -docker build -t f1tenth-ros . +docker compose build ``` #### 4. Run a Container @@ -70,10 +78,10 @@ docker build -t f1tenth-ros . This step will ensure the build has worked by running a container. Later we will run the simulator in this container. ``` -docker run -it f1tenth-ros +docker compose run f1tenth-ros ``` -You should see your terminal display something like +You should see your terminal display something like: ``` root@...:/# @@ -193,48 +201,60 @@ chmod +x * Having multiple terminals open can get confusing, luckily in VSCode you can rename each terminal to something more convenient: Right-click terminal name -> rename. -## Enabling the container to display GUIs on the host machine (Windows) - -Prerequisite: Chocolatey must be installed on your computer. +## Using the GUI within the Docker Container via VNC -Warning: Some firewalls may block access so it might be necessary to disable your firewall when running the simulator. - -Open Windows Powershell as Administrator and install the `xming` package +First, run the container with the VNC ports exposed. ``` -choco install xming +docker compose run --rm --service-ports f1tenth-ros-vnc ``` -Open the XLaunch Application +### Connecting to the Docker Container Using a VNC Client - +There is a universal method, though you will have a better experience using a dedicated VNC client. -Follow the default settings for each step except the following +#### MacOS - +MacOS comes with a built in VNC client. +Once the docker container is running, you can open it using `open vnc://root:f1tenth@localhost:5900`. -Once the XLaunch setup is finished, find your local IP Address by entering an ipconfig command in your local terminal +#### Linux -``` -ipconfig -``` +A VNC client can be installed called remmina: -Your local IP should be found similarly to where its shown below (ignore the white marks) + * [Debian based](https://remmina.org/how-to-install-remmina/) + * It is not found in the apt repository but you can use snap/flatpaks or adding it to the apt repository + * Arch based + * `sudo pacman -S remmina libvncserver` + * [Gentoo based](https://wiki.gentoo.org/wiki/USE_flag) (see more on how to use use flags) + * Make sure to update USE flag for package to include the `vnc` USE Flag + * `sudo emerge net-misc/remmina net-libs/libvncserver` - +Create a new connection to `localhost:5900` with the password `f1tenth` using the VNC plugin. -Execute the setup-display script in the container passing your local IP Address as a parameter. +On Remmina if some keystrokes are not captured such as modifier keys like shift/ctrl/alt. +Make sure to turn on `Grab all keyboard events` on the left hand side. +You can also activate it by pressing `Control_R` -``` -source /utils/set-display.sh -``` +#### Universal + +Open `localhost:6080/vnc_lite.html` in your browser. +Enter the password `f1tenth` when prompted. + +*Key combinations may work properly if you use the in browser VNC client* + +### Running the Simulator + +[DWM Keybindings](https://github.com/FT-Autonomous/dwm) (keybindings for general use in the docker container) + +Open a terminal and then type in `source /utils/run-simulator.sh Silverstone`. -Now when you run the simulator you should see the display open in a new window. +## Enabling the Container to display GUIs on the host machine using rocker (Linux) -### Enabling the Container to display GUIs on the host machine (Ubuntu, and other) +Rocker integrates much better with the host machine than a VNC client. First, install [Rocker](https://github.com/osrf/rocker), then after you have built your image (step 3), run the following command in your Terminal to run the Docker image: ``` -rocker [optional: --nvidia or --devices /dev/dri/card0] --x11 docker-ros +rocker [optional: --nvidia or --devices /dev/dri/card0] --x11 ``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1ff910d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +version: '3' + +services: + f1tenth-ros: &f1tenth-ros + user: root + build: + context: . + dockerfile: Dockerfile + stdin_open: true + volumes: + - ./utils:/utils + - ./utils/setup-vnc.sh:/setup.sh + ports: + - 5900:5900 + - 6080:6080 + + f1tenth-ros-vnc: + <<: *f1tenth-ros + entrypoint: /setup.sh diff --git a/utils/setup-vnc.sh b/utils/setup-vnc.sh new file mode 100755 index 0000000..4c4b834 --- /dev/null +++ b/utils/setup-vnc.sh @@ -0,0 +1,7 @@ +#!/bin/sh +export SCREEN=0 DISPLAY=:0 WINDOW_MANAGER=dwm +source /ros_entrypoint.sh +pgrep Xvfb || (rm -fr /tmp/.X* && Xvfb "$DISPLAY" -screen $SCREEN 1280x720x16 -ac -pn -noreset) & sleep 1 +pgrep $WINDOW_MANAGER || nohup $WINDOW_MANAGER > /tmp/${WINDOW_MANAGER}.log & +pgrep x11vnc || x11vnc -forever -noxdamage -noxrecord -display $DISPLAY -passwd f1tenth & +pgrep novnc_proxy || ./noVNC/utils/novnc_proxy --vnc localhost:5900 --listen 6080 diff --git a/utils/setup-workspace.sh b/utils/setup-workspace.sh new file mode 100755 index 0000000..22aa660 --- /dev/null +++ b/utils/setup-workspace.sh @@ -0,0 +1,6 @@ +workspace_dir="${1-f1tenth_shared_workspace}/src" +mkdir -p "$workspace_dir" +cd "$workspace_dir" +git clone https://github.com/f1tenth/f1tenth_simulator.git +cd f1tenth_simulator/maps +git init && git pull https://github.com/f1tenth/f1tenth_racetracks