From b4a06bcb4cc27b2067657bbd251aba023ee0b439 Mon Sep 17 00:00:00 2001 From: ElSayed ElSheikh Date: Sat, 13 Jan 2024 00:27:12 +0200 Subject: [PATCH] utilize nvidia gpu while running gazebo on linux and windows (#72) * Bump athackst/mkdocs-simple-plugin from 2.2.0 to 2.3.0 (#41) Bumps [athackst/mkdocs-simple-plugin](https://github.com/athackst/mkdocs-simple-plugin) from 2.2.0 to 2.3.0. - [Release notes](https://github.com/athackst/mkdocs-simple-plugin/releases) - [Commits](https://github.com/athackst/mkdocs-simple-plugin/compare/v2.2.0...v2.3.0) --- updated-dependencies: - dependency-name: athackst/mkdocs-simple-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * allow x11 access to host (#44) * Add debugging option for ROS launch files (#45) * Add ROS launch files debugging * Add ROS launch file debugging for isolated install * Sort alphabetically the extensions * Update cpp version (#48) * Add support for intel iGPU (#55) * remove wayland config, devcontainer handles it (#54) * Revert "remove wayland config, devcontainer handles it (#54)" (#58) This reverts commit 24e704d7c38531560e876968c9dd8b6f830fc3c4. * Add script to add submodules to workspace from repos file (#59) * Update workflow to only trigger when pushing to specific branches (#60) * Bump athackst/mkdocs-simple-plugin from 2.3.0 to 3.0.0 (#61) * Bump athackst/mkdocs-simple-plugin from 3.0.0 to 3.1.0 (#62) * Bump actions/checkout from 3 to 4 (#64) * Add rosdistro to setup and update purge command (#68) * Remove eol foxy and add rolling to ros workflow (#69) * utilize nvidia gpu while running gazebo on linux and windows --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sophia Koffler Co-authored-by: DaniGarciaLopez Co-authored-by: Shunsuke KIMURA Co-authored-by: SubaruArai <78188579+SubaruArai@users.noreply.github.com> Co-authored-by: Allison Thackston --- .devcontainer/Dockerfile | 16 ++++++++++++ .devcontainer/devcontainer.json | 17 ++++++++++--- .devcontainer/repos_to_submodules.py | 38 ++++++++++++++++++++++++++++ .github/workflows/docs.yaml | 4 +-- .github/workflows/ros.yaml | 18 +++++++++++-- .vscode/c_cpp_properties.json | 2 +- .vscode/launch.json | 23 ++++++++++++++++- .vscode/tasks.json | 9 ++++++- README.md | 25 +++++++++++++++++- setup.sh | 4 +-- 10 files changed, 143 insertions(+), 13 deletions(-) create mode 100755 .devcontainer/repos_to_submodules.py diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 0634525..efa70f7 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,5 +1,21 @@ FROM althack/ros2:humble-cuda-dev +### For Windows, uncomment the following lines to install WSLg dependencies and utilize vGPU acceleration +# ENV DEBIAN_FRONTEND=noninteractive +# RUN apt-get update \ +# && apt-get -y install \ +# vainfo \ +# mesa-va-drivers \ +# mesa-utils \ +# # Clean up +# && apt-get autoremove -y \ +# && apt-get clean -y \ +# && rm -rf /var/lib/apt/lists/* +# ENV LIBVA_DRIVER_NAME=d3d12 +# ENV LD_LIBRARY_PATH=/usr/lib/wsl/lib +# CMD vainfo --display drm --device /dev/dri/card0 +# ENV DEBIAN_FRONTEND=dialog + # ** [Optional] Uncomment this section to install additional packages. ** # # ENV DEBIAN_FRONTEND=noninteractive diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index e376a1b..072cfa9 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -14,7 +14,17 @@ "--security-opt=apparmor:unconfined", "--volume=/tmp/.X11-unix:/tmp/.X11-unix", "--volume=/mnt/wslg:/mnt/wslg", - "--gpus=all" + "--ipc=host" + // uncomment to use intel iGPU + // "--device=/dev/dri" + // uncomment to use Nvidia GPU with Linux, https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html + // "--runtime=nvidia" + // uncomment to use Nvidia GPU with Windows WSL2 + // "--volume=/usr/lib/wsl:/usr/lib/wsl", + // "--device=/dev/dxg", + // "--device=/dev/dri/card0", + // "--device=/dev/dri/renderD128", + // "--gpus=all" ], "containerEnv": { "DISPLAY": "${localEnv:DISPLAY}", // Needed for GUI try ":0" for windows @@ -29,8 +39,10 @@ "vscode": { "extensions": [ "althack.ament-task-provider", + "betwo.b2-catkin-tools", "DotJoshJohnson.xml", "ms-azuretools.vscode-docker", + "ms-iot.vscode-ros", "ms-python.python", "ms-vscode.cpptools", "redhat.vscode-yaml", @@ -38,8 +50,7 @@ "streetsidesoftware.code-spell-checker", "twxs.cmake", "yzhang.markdown-all-in-one", - "zachflower.uncrustify", - "betwo.b2-catkin-tools" + "zachflower.uncrustify" ] } } diff --git a/.devcontainer/repos_to_submodules.py b/.devcontainer/repos_to_submodules.py new file mode 100755 index 0000000..70713f7 --- /dev/null +++ b/.devcontainer/repos_to_submodules.py @@ -0,0 +1,38 @@ +import glob +import os +import subprocess +import yaml + +prefix="src" + +def add_git_submodule(repo_name, repo_url, repo_version): + subprocess.call(['git', 'submodule', 'add', '-b', repo_version, repo_url, repo_name]) + +def is_submodule(repo_name): + try: + subprocess.check_output(['git', 'submodule', 'status', repo_name], stderr=subprocess.DEVNULL) + return True + except subprocess.CalledProcessError: + return False + +def parse_repos_file(file_path): + with open(file_path, 'r') as file: + repos_data = yaml.safe_load(file) + repositories = repos_data['repositories'] + + for repo_name, repo_info in repositories.items(): + if 'type' in repo_info and repo_info['type'] == 'git': + repo_url = repo_info['url'] + repo_version = repo_info['version'] + submodule_name = os.path.join(prefix, repo_name) + + if not is_submodule(submodule_name): + add_git_submodule(submodule_name, repo_url, repo_version) + print(f"Added {repo_name} as a submodule.") + +# Find .repos files within the src directory +repos_files = glob.glob('src/**/*.repos', recursive=True) + +# Process each .repos file +for repos_file in repos_files: + parse_repos_file(repos_file) diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index d1b9026..4f3f528 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -12,6 +12,6 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Build and push docs - uses: athackst/mkdocs-simple-plugin@v2.2.0 + uses: athackst/mkdocs-simple-plugin@v3.1.0 diff --git a/.github/workflows/ros.yaml b/.github/workflows/ros.yaml index 4f0b650..75e496d 100644 --- a/.github/workflows/ros.yaml +++ b/.github/workflows/ros.yaml @@ -3,6 +3,10 @@ name: ROS on: pull_request: push: + branches: + - humble* + - iron* + - rolling* workflow_dispatch: jobs: @@ -12,7 +16,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Test uses: ./.github/actions/test/ @@ -27,9 +31,19 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Run linter uses: ./.github/actions/lint/ env: LINTER: ${{ matrix.linter }} + + complete: + name: Tests passed + needs: + - lint + - test + runs-on: ubuntu-latest + steps: + - name: Check + run: echo "Completed successfully!" diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 08b9675..40d2c8e 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -10,7 +10,7 @@ "compilerPath": "/usr/bin/gcc", "compileCommands": "${workspaceFolder}/build/compile_commands.json", "cStandard": "c99", - "cppStandard": "c++14", + "cppStandard": "c++17", "intelliSenseMode": "linux-gcc-x64" } ], diff --git a/.vscode/launch.json b/.vscode/launch.json index 61f544e..6dc8dd6 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -50,7 +50,22 @@ "ignoreFailures": true } ] - } + }, + //Example of a ROS Launch file + { + "name": "ROS: Launch File (merge-install)", + "type": "ros", + "request": "launch", + "preLaunchTask": "build", + "target": "${workspaceFolder}/install/share/${input:package}/launch/${input:ros_launch}", + }, + { + "name": "ROS: Launch File (isolated-install)", + "type": "ros", + "request": "launch", + "preLaunchTask": "build", + "target": "${workspaceFolder}/install/${input:package}/share/${input:package}/launch/${input:ros_launch}", + }, ], "inputs": [ { @@ -64,6 +79,12 @@ "type": "promptString", "description": "Program name", "default": "publisher_member_function" + }, + { + "id": "ros_launch", + "type": "promptString", + "description": "ROS launch name", + "default": "file_name_launch.py" } ] } diff --git a/.vscode/tasks.json b/.vscode/tasks.json index c953297..d1ed3ee 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -51,7 +51,7 @@ "label": "purge", "detail": "Purge workspace by deleting all generated files.", "type": "shell", - "command": "rm -fr build install log; py3clean .", + "command": "sudo rm -fr build install log; sudo py3clean .", "problemMatcher": [] }, // Linting and static code analysis tasks @@ -228,6 +228,13 @@ "type": "shell", "command": "./setup.sh", "problemMatcher": [] + }, + { + "label": "add submodules from .repos", + "detail": "Create a git submodule for all repositories in your .repos file", + "type": "shell", + "command": "python3 .devcontainer/repos_to_submodules.py", + "problemMatcher": [] } ], "inputs": [ diff --git a/README.md b/README.md index b95022e..e4549d9 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Take a look at [how I develop using tasks](https://www.allisonthackston.com/arti ### Debugging -This template sets up debugging for python files and gdb for cpp programs. See [`.vscode/launch.json`](.vscode/launch.json) for configuration details. +This template sets up debugging for python files, gdb for cpp programs and ROS launch files. See [`.vscode/launch.json`](.vscode/launch.json) for configuration details. ### Continuous Integration @@ -184,3 +184,26 @@ If you want to access the vGPU through WSL2, you'll need to add additional compo "LIBGL_ALWAYS_SOFTWARE": "1" // Needed for software rendering of opengl }, ``` + +### Repos are not showing up in VS Code source control + +This is likely because vscode doesn't necessarily know about other repositories unless you've added them directly. + +``` +File->Add Folder To Workspace +``` + +![Screenshot-26](https://github.com/athackst/vscode_ros2_workspace/assets/6098197/d8711320-2c16-463b-9d67-5bd9314acc7f) + + +Or you've added them as a git submodule. + +![Screenshot-27](https://github.com/athackst/vscode_ros2_workspace/assets/6098197/8ebc9aac-9d70-4b53-aa52-9b5b108dc935) + +To add all of the repos in your *.repos file, run the script + +```bash +python3 .devcontainer/repos_to_submodules.py +``` + +or run the task titled `add submodules from .repos` diff --git a/setup.sh b/setup.sh index bb31f70..beab00e 100755 --- a/setup.sh +++ b/setup.sh @@ -3,5 +3,5 @@ set -e vcs import < src/ros2.repos src sudo apt-get update -rosdep update -rosdep install --from-paths src --ignore-src -y +rosdep update --rosdistro=$ROS_DISTRO +rosdep install --from-paths src --ignore-src -y --rosdistro=$ROS_DISTRO