From 9ee670f8009893979c6bb3bcadad8a9c31b4bba0 Mon Sep 17 00:00:00 2001 From: Tim Redick Date: Thu, 29 Aug 2024 10:53:03 +0000 Subject: [PATCH] Add devcontainer --- .clang-format | 66 ++++++++++++++++++++++++++++++++ .clang-tidy | 0 .devcontainer/Dockerfile | 52 +++++++++++++++++++++++++ .devcontainer/devcontainer.json | 63 ++++++++++++++++++++++++++++++ .devcontainer/docker-compose.yml | 43 +++++++++++++++++++++ .devcontainer/postCreate.sh | 25 ++++++++++++ .gitignore | 1 + README.md | 24 +++++++++--- lbrmed_hw_fri/README.md | 3 -- 9 files changed, 269 insertions(+), 8 deletions(-) create mode 100644 .clang-format create mode 100644 .clang-tidy create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml create mode 100644 .devcontainer/postCreate.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..aad8650 --- /dev/null +++ b/.clang-format @@ -0,0 +1,66 @@ +--- +BasedOnStyle: Google +AccessModifierOffset: -2 +ConstructorInitializerIndentWidth: 2 +AlignEscapedNewlinesLeft: false +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AlwaysBreakTemplateDeclarations: true +AlwaysBreakBeforeMultilineStrings: false +BreakBeforeBinaryOperators: false +BreakBeforeTernaryOperators: false +BreakConstructorInitializersBeforeComma: true +BinPackParameters: true +ColumnLimit: 120 +ConstructorInitializerAllOnOneLineOrOnePerLine: true +DerivePointerBinding: false +PointerBindsToType: true +ExperimentalAutoDetectBinPacking: false +IndentCaseLabels: true +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 60 +PenaltyBreakString: 1 +PenaltyBreakFirstLessLess: 1000 +PenaltyExcessCharacter: 1000 +PenaltyReturnTypeOnItsOwnLine: 90 +SpacesBeforeTrailingComments: 2 +Cpp11BracedListStyle: false +Standard: Auto +IndentWidth: 2 +TabWidth: 2 +UseTab: Never +IndentFunctionDeclarationAfterType: false +SpacesInParentheses: false +SpacesInAngles: false +SpaceInEmptyParentheses: false +SpacesInCStyleCastParentheses: false +SpaceAfterControlStatementKeyword: true +SpaceBeforeAssignmentOperators: true +ContinuationIndentWidth: 4 +IncludeBlocksStyle: Preserve +SortIncludes: CaseInsensitive +SpaceAfterCStyleCast: false + +# Configure each individual brace in BraceWrapping +BreakBeforeBraces: Custom + +# Control of individual brace wrapping cases +BraceWrapping: + { + AfterClass: "true", + AfterControlStatement: "true", + AfterEnum: "true", + AfterFunction: "true", + AfterNamespace: "true", + AfterStruct: "true", + AfterUnion: "true", + BeforeCatch: "true", + BeforeElse: "true", + IndentBraces: "false", + } diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..e69de29 diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..514f3dd --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,52 @@ +# @license BSD-3 https://opensource.org/licenses/BSD-3-Clause +# Copyright (c) 2021, Institute of Automatic Control - RWTH Aachen University +# All rights reserved. + +# Choose from melodic or noetic tags +FROM ros:noetic-robot + +# Add your own additional packages +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update \ + && apt-get install -y \ + # Check if GUI and 3D acceleration works + mesa-utils x11-apps \ + # Nice plots for debugging + ros-${ROS_DISTRO}-plotjuggler-ros \ + && apt-get upgrade -y \ + && rm -rf /var/lib/apt/lists/* + +# git-lfs +RUN curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash && \ + apt-get update && \ + apt-get install git-lfs -y --no-install-recommends && \ + rm -rf /var/lib/apt/lists/* && \ + git lfs install +# ROS additional essential packages +RUN apt-get update && apt-get install -y --no-install-recommends\ + python3-catkin-tools python3-catkin-lint python3-rosdep python3-rosinstall python3-rosinstall-generator python3-vcstool python3-wstool build-essential python3-osrf-pycommon \ + ros-${ROS_DISTRO}-ros-control ros-${ROS_DISTRO}-ros-controllers ros-${ROS_DISTRO}-rqt-controller-manager && \ + rm -rf /var/lib/apt/lists/* + +ENV DEBIAN_FRONTEND=dialog + +# Setup non-root user to solve file permission problems with rootfull docker +ARG USERNAME=vscode +ARG USER_UID=1000 +ARG USER_GID=${USER_UID} + +RUN groupadd --gid ${USER_GID} $USERNAME \ + && useradd --uid ${USER_UID} --gid ${USER_GID} -m $USERNAME \ + && apt-get update \ + && apt-get install -y --no-install-recommends sudo \ + && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ + && chmod 0440 /etc/sudoers.d/$USERNAME + +# Autocompletion for root user +RUN echo "if [ -f /etc/bash_completion ] && ! shopt -oq posix; then\n . /etc/bash_completion\nfi" >> /root/.bashrc + +# Create for vscode +RUN sudo mkdir -p /workspace/src && chown -R vscode:vscode /workspace +# Use non-root user to avoid permission problems +USER vscode diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..71051ee --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,63 @@ +// @license BSD-3 https://opensource.org/licenses/BSD-3-Clause +// Copyright (c) 2021, Institute of Automatic Control - RWTH Aachen University +// All rights reserved. +{ + "dockerComposeFile": "docker-compose.yml", + "service": "ros-devcontainer", + "workspaceFolder": "/workspace/src/lbrmed-ros", + // Source the ROS workspace, the ${containerWorkspaceFolder} variable only gets replaced in this .json + // Install dependencies for workspace except Gazebo packages as the OSRF version is installed + "postCreateCommand": "echo 'source /opt/ros/${ROS_DISTRO}/setup.bash' >> ${HOME}/.bashrc && echo 'source ${containerWorkspaceFolder}/devel/setup.bash' >> ${HOME}/.bashrc && /bin/sh .devcontainer/postCreate.sh", + "customizations": { + "vscode": { + "extensions": [ + "dotjoshjohnson.xml", + "epivision.vscode-file-header", + "gruntfuggly.todo-tree", + "mhutchie.git-graph", + "ms-azuretools.vscode-docker", + "ms-iot.vscode-ros", + "ms-python.black-formatter", + "ms-python.flake8", + "ms-python.python", + "ms-vscode.cmake-tools", + "ms-vscode.cpptools", + "ms-vsliveshare.vsliveshare", + "oderwat.indent-rainbow", + "redhat.vscode-yaml", + "streetsidesoftware.code-spell-checker", + "twxs.cmake", + "valentjn.vscode-ltex", + "visualstudioexptteam.vscodeintellicode" + ], + // Set *default* container specific settings.json values on container create. + "settings": { + // Use C/C++ extension for formatting, linting and debugging + "C_Cpp.clang_format_style": "file", + "C_Cpp.codeAnalysis.clangTidy.enabled": true, + "C_Cpp.default.cppStandard": "c++14", + "C_Cpp.default.cStandard": "c11", + "C_Cpp.formatting": "clangFormat", + "[cpp]": { + "editor.defaultFormatter": "ms-vscode.cpptools" + }, + // Other settings + "editor.formatOnSave": true, + "editor.tabSize": 2, + "git.repositoryScanMaxDepth": 3, + "powerHeader.autoInsert.enable": true, + "powerHeader.commentMode": "line", + "powerHeader.template": "file://${containerWorkspaceFolder}/.vscode/copyright_template.txt", + "python.formatting.provider": "autopep8", + "python.autoComplete.extraPaths": [ + "/opt/ros/${env:ROS_DISTRO}/lib/python3/dist-packages" + ], + "python.analysis.extraPaths": [ + "/opt/ros/${env:ROS_DISTRO}/lib/python3/dist-packages" + ], + "terminal.integrated.defaultProfile.linux": "bash", + "terminal.integrated.gpuAcceleration": "on" + } + } + } +} \ No newline at end of file diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..51a2231 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,43 @@ +# Use this, if you run a full Linux installation +services: + ros-devcontainer: + build: + # context: .. + dockerfile: Dockerfile + # Optional: Access external devices, e.g., USB cameras + privileged: true + volumes: + - ..:/workspace/src/lbrmed-ros:cached + # GUI support + - /tmp/.X11-unix:/tmp/.X11-unix + # Avoid Qt glitches + ipc: host + network_mode: host + environment: + # GUI support + DISPLAY: $DISPLAY + WAYLAND_DISPLAY: WAYLAND_DISPLAY + XDG_RUNTIME_DIR: XDG_RUNTIME_DIR + PULSE_SERVER: PULSE_SERVER + # Optional: Use NVIDIA GPU for rendering + # __NV_PRIME_RENDER_OFFLOAD: 1 + # __GLX_VENDOR_LIBRARY_NAME: nvidia + devices: + # Accelerated 3D graphics + - /dev/dri + # Optional: Enable CUDA + # deploy: + # resources: + # reservations: + # devices: + # - driver: nvidia + # capabilities: [gpu] + # count: 1 # limit number of GPUs used by container + # Required for ptrace-based debuggers like C++ + cap_add: + - SYS_PTRACE + security_opt: + - apparmor:unconfined + - seccomp:unconfined + # Avoid shutting down after process ends + command: sleep infinity diff --git a/.devcontainer/postCreate.sh b/.devcontainer/postCreate.sh new file mode 100644 index 0000000..968cffb --- /dev/null +++ b/.devcontainer/postCreate.sh @@ -0,0 +1,25 @@ +# @license BSD-3 https://opensource.org/licenses/BSD-3-Clause +# Copyright (c) 2021, Institute of Automatic Control - RWTH Aachen University +# All rights reserved. + +# /workspace/src/lbrmed-ros +cd /workspace + +# If it exists: extend workspace from source built MoveIt (which extends /opt/ros/...) +if [ -d "/moveit_ws/devel" ]; then + catkin config --init --extend /moveit_ws/devel --cmake-args -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=1 #-DCMAKE_CXX_STANDARD=17 +else + catkin config --init --extend /opt/ros/$ROS_DISTRO --cmake-args -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=1 #-DCMAKE_CXX_STANDARD=17 +fi + +# install workspace dependencies, src is one level above the lbrmed-ros workspace +wstool init src +wstool merge -t src src/lbrmed-ros/.rosinstall +wstool update -t src +rosdep update && sudo apt-get update +rosdep install --from-paths src --ignore-src -r -q -y --skip-keys 'gazebo gazebo_dev gazebo_plugins gazebo_ros gazebo_ros_control' +# install other system dependencies, note that they are not cached for rebuilds of the devcontainer +# frequently used dependencies should be install in my.Dockerfile + +# Check rendering support +glxinfo -B diff --git a/.gitignore b/.gitignore index 722d5e7..a659ccf 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +.catkin_tools .vscode diff --git a/README.md b/README.md index 7eaa13f..ca09f0d 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,26 @@ Please look at the READMEs in the specific hardware packages. **When using the real robot, always keep a safe distance and set up your safety configuration as required**. # Install -## Create a catkin workspace +## Devcontainer +This is the easiest way to get started +When opening this repository in Visual Studio Code, you should be prompted to reopen it in a container. +On launch, the container will setup all required dependencies via rosinstall and rosdep. + +This repository also ships **VS Code tasks** for: +- Building the workspace `catkin build workspace` +- Building the package of the current file only `catkin build package` +- Clean the catkin build files `catkin clean` + +After starting the container, the lbrmed-ros package will be opened as **workspace**. +The folder structure is `/workspace/src/lbrmed-ros`, so you will want to `cd` to a top-level folder when using low-level catkin commands + +## Manual steps +### Create a catkin workspace * Create a catkin workspace folder (e.g. ~/catkin_workspace) * Create a src folder in that workspace (e.g. ~/catkin_workspace/src) * Initialize the catkin workspace (e.g. `cd ~/catkin_workspace && catkin init`) -## Cloning the repository +### Cloning the repository We use [`git-lfs`](https://packagecloud.io/github/git-lfs/install) which should be installed before cloning. Otherwise, you might get errors when the STL files of the robot or the jar files are being loaded. @@ -25,16 +39,16 @@ For the Sunrise Project you have two ways to proceed: * (a) Clone the repository into the src folder of the catkin workspace * (b) (preferable) Clone the repository into a separate folder (e.g. ~/git-repos) and symlink it (e.g. `ln -s ~/git-repos/kuka_MED_Stack ~/catkin_workspace/src`, the target of the symlink must be an absolute path) -## Installing Dependencies +### Installing Dependencies In the catkin workspace, run the following commands to install all workspace and system dependencies. ```bash wstool init src -wstool merge -t src src/lbrmed-stack/.rosinstall +wstool merge -t src src/lbrmed-ros/.rosinstall wstool update -t src rosdep install --from-paths src --ignore-src -r -y ``` -## Building the workspace +### Building the workspace To build the packages in parallel, we use the [catkin_tools](https://catkin-tools.readthedocs.io/en/latest/installing.html). After installing them, run: ```bash cd ~/catkin_workspace diff --git a/lbrmed_hw_fri/README.md b/lbrmed_hw_fri/README.md index 9554c7a..0861687 100644 --- a/lbrmed_hw_fri/README.md +++ b/lbrmed_hw_fri/README.md @@ -40,9 +40,6 @@ Calls the `set_impedance_fri` service of the `lbrmed_hw_fri_node` to set the sti ## Acknowledgment Based on [lbr_fri_ros2_stack](https://github.com/KCL-BMEIS/lbr_fri_ros2_stack/tree/noetic) which has a noetic branch. -# Setup -For the internal irt setup take a look at the [gitlab wiki](https://git-ce.rwth-aachen.de/g-med-irt-robotik/lbrmed-stack/-/wikis/Robot%20Hardware%20Usage) and the [irt wiki](https://wiki.irt.rwth-aachen.de/wiki/KUKA_LBR). - ## Setup the Controller The controller (Sunrise Cabinet) receives commands from the ROS machine via the FRI. Therefore, the server application has to be pushed onto the Sunrise Cabinet. - Connect an ethernet cable to port X66 on the Sunrise Cabinet