|
| 1 | +# Setup Instructions |
| 2 | + |
| 3 | +This workspace can be set up on most operating systems, but it performs the best and requires the least setup on |
| 4 | +Ubuntu and [its derivatives](https://distrowatch.com/search.php?basedon=Ubuntu){target=_blank}. |
| 5 | + |
| 6 | +## Install and configure prerequisites |
| 7 | + |
| 8 | +### Docker |
| 9 | + |
| 10 | +=== ":material-microsoft-windows: Windows" |
| 11 | + |
| 12 | + 1. [Install Docker Desktop](https://docs.docker.com/desktop/install/windows-install/){target=_blank} |
| 13 | + with the WSL 2 backend |
| 14 | + |
| 15 | + 2. Configure [WSL](https://learn.microsoft.com/en-us/windows/wsl/about){target=_blank} |
| 16 | + 1. Run the commands below in an **administrator** PowerShell window |
| 17 | + |
| 18 | + ```powershell |
| 19 | + wsl --install --distribution Ubuntu |
| 20 | + wsl --set-default Ubuntu |
| 21 | + wsl --set-version Ubuntu 2 |
| 22 | + ``` |
| 23 | + |
| 24 | + 2. Run `whoami` in the Ubuntu terminal; if it outputs `root`, create a non-root user with sudo privileges |
| 25 | + and give it full permissions to Docker |
| 26 | + 1. [Create a non-root user with sudo privileges](https://www.digitalocean.com/community/tutorials/how-to-add-and-delete-users-on-ubuntu-20-04){target=_blank} |
| 27 | + 2. Change the default Ubuntu user to the one you just created by entering the following command in Powershell: |
| 28 | + `ubuntu config --default-user <username>`, where `<username>` is the name of the user |
| 29 | + 3. [Add the user to the Docker group](https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user){target=_blank} |
| 30 | + |
| 31 | +=== ":material-apple: MacOS" |
| 32 | + |
| 33 | + 1. [Install Docker Desktop](https://docs.docker.com/engine/install/){target=_blank} |
| 34 | + |
| 35 | +=== ":material-linux: Linux" |
| 36 | + |
| 37 | + 1. [Install Docker Engine](https://docs.docker.com/engine/install/){target=_blank} |
| 38 | + 2. [Manage Docker as a non-root user](https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user){target=_blank} |
| 39 | + 3. [Configure Docker to start on boot](https://docs.docker.com/engine/install/linux-postinstall/#configure-docker-to-start-on-boot){target=_blank} |
| 40 | + |
| 41 | +### VS Code |
| 42 | + |
| 43 | +- [VS Code](https://code.visualstudio.com/){target=_blank} |
| 44 | + 1. [Install VS Code](https://code.visualstudio.com/download){target=_blank} |
| 45 | + - For Arch Linux, make sure install the official Microsoft distribution; |
| 46 | + the one from Pacman doesn't work with Microsoft plugins |
| 47 | + 2. [Install VS Code Remote Development Extension Pack](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack){target=_blank} |
| 48 | + |
| 49 | +## Additional configuration to run GUI applications |
| 50 | + |
| 51 | +=== ":material-microsoft-windows: Windows" |
| 52 | + |
| 53 | + === ":simple-windows11: Windows 11" |
| 54 | + |
| 55 | + GUI applications work without additional configuration, |
| 56 | + **but if you upgraded from Windows 10 make sure to update the WSL kernel:** `wsl --update` |
| 57 | + in an **administrator** PowerShell window |
| 58 | + |
| 59 | + === ":material-microsoft-windows: Windows 10" |
| 60 | + |
| 61 | + 1. Follow [this guide](https://techcommunity.microsoft.com/t5/windows-dev-appconsult/running-wsl-gui-apps-on-windows-10/ba-p/1493242){target=_blank} |
| 62 | + up to, but not including setting the `DISPLAY` variable |
| 63 | + 2. Zsh configuration |
| 64 | + 1. Run the command below in your Ubuntu terminal |
| 65 | + |
| 66 | + ```bash |
| 67 | + echo "export DISPLAY=\"`grep nameserver /etc/resolv.conf | sed 's/nameserver //'`:0\"" >> ~/.bashrc |
| 68 | + echo 'export WIN10_DOCKER_DISPLAY_END="${DISPLAY:1}"' >> ~/.bashrc |
| 69 | + ``` |
| 70 | + |
| 71 | + 3. If VS Code is open, then restart it |
| 72 | + |
| 73 | +=== ":material-apple: MacOS" |
| 74 | + |
| 75 | + 1. XQuartz configuration |
| 76 | + |
| 77 | + 1. Follow [this guide](https://gist.github.com/sorny/969fe55d85c9b0035b0109a31cbcb088){target=_blank} to setup |
| 78 | + XQuartz |
| 79 | + 2. Copy the default xinitrc to your home directory |
| 80 | + |
| 81 | + ```zsh |
| 82 | + cp /opt/X11/etc/X11/xinit/xinitrc ~/.xinitrc |
| 83 | + ``` |
| 84 | + |
| 85 | + 3. Add `xhost +localhost` to `~/.xinitrc` after its first line |
| 86 | + 4. If XQuartz is open, then restart it |
| 87 | + |
| 88 | + 2. Zsh configuration |
| 89 | + |
| 90 | + 1. Run the commands below in your MacOS terminal |
| 91 | + |
| 92 | + ```zsh |
| 93 | + echo 'export MAC_DOCKER_LOCALHOST="docker.for.mac.host.internal"' >> ~/.zshrc |
| 94 | + echo 'export DISPLAY=:0' >> ~/.zshrc |
| 95 | + ``` |
| 96 | + |
| 97 | + 2. If VS Code is open, then restart it |
| 98 | + |
| 99 | +=== ":material-linux: Linux" |
| 100 | + |
| 101 | + === ":material-ubuntu: Ubuntu and its derivatives" |
| 102 | + |
| 103 | + GUI applications should work without additional configuration. |
| 104 | + |
| 105 | + === ":material-linux: Other" |
| 106 | + |
| 107 | + === ":material-arch: Arch Linux" |
| 108 | + |
| 109 | + 1. Set up X11 forwarding |
| 110 | + |
| 111 | + 1. Install xhost |
| 112 | + |
| 113 | + ```bash |
| 114 | + sudo pacman -S xorg-xhost |
| 115 | + ``` |
| 116 | + |
| 117 | + 2. Run the commands below in your Linux terminal |
| 118 | + |
| 119 | + ```bash |
| 120 | + echo 'export DISPLAY=0.0' >> ~/.bashrc |
| 121 | + cp /etc/X11/xinit/xinitrc ~/.xinitrc |
| 122 | + ``` |
| 123 | + |
| 124 | + 3. Add `xhost +local:docker` to `~/.xinitrc` after its first line |
| 125 | + |
| 126 | + ??? bug "ROS 1 not working" |
| 127 | + |
| 128 | + The system has trouble resolving the local hostname; run the commands below in your VS Code terminal |
| 129 | + |
| 130 | + ```bash |
| 131 | + echo 'export ROS_HOSTNAME=localhost' >> ~/.bashrc |
| 132 | + echo 'export ROS_MASTER_URI=http://localhost:11311' >> ~/.bashrc |
| 133 | + ``` |
| 134 | + |
| 135 | +## Clone sailbot_workspace |
| 136 | + |
| 137 | +!!! notes "Note for Windows" |
| 138 | + |
| 139 | + Run the command below in the Ubuntu terminal to clone sailbot_workspace in the WSL filesystem. |
| 140 | + |
| 141 | +```sh |
| 142 | +git clone https://github.com/UBCSailbot/sailbot_workspace.git |
| 143 | +``` |
| 144 | + |
| 145 | +## Open sailbot_workspace in VS Code |
| 146 | + |
| 147 | +```sh |
| 148 | +code sailbot_workspace |
| 149 | +``` |
| 150 | + |
| 151 | +## Open sailbot_workspace in a Dev Container |
| 152 | + |
| 153 | +1. Make sure that Docker is running |
| 154 | +2. Run the "Dev Containers: Reopen in Container" command in the VS Code command pallete |
| 155 | + |
| 156 | +## Open the sailbot_workspace VS Code workspace |
| 157 | + |
| 158 | +1. Open the file `.devcontainer/config/sailbot_workspace.code-workspace` in VS Code |
| 159 | +2. Click "Open Workspace" |
| 160 | + |
| 161 | +## Run the VS Code task named "setup" |
| 162 | + |
| 163 | +This imports the ROS packages and install their dependencies. |
| 164 | + |
| 165 | +## Updating sailbot_workspace |
| 166 | + |
| 167 | +When changes to the Dev container are made (any file in `.devcontainer/`), it needs to be rebuilt. |
| 168 | +This may happen when you pull the latest commits from a branch or switch branches. |
| 169 | + |
| 170 | +1. Run the "Dev Containers: Rebuild Container" command in the VS Code command palette |
0 commit comments