diff --git a/For_Ubuntu20_04.adoc b/For_Ubuntu20_04.adoc new file mode 100644 index 0000000000000000000000000000000000000000..36ea49129c8c182ac3ba63f4d4b12a62a1015ada --- /dev/null +++ b/For_Ubuntu20_04.adoc @@ -0,0 +1,108 @@ +Using docker to setup a development environment +=============================================== +//:Author: Andres Montaño +//:Email: <andres.montano@tecnalia.com> +:Date: 08.07.2021 +:Revision: 0.1 + +From an Ubuntu 20.04 system +--------------------------- + +=== 1.- Follow the instructions to get access to the Tecnalia repositories and artifacts: +https://git.code.tecnalia.com/tecnalia_robotics/documentation/-/blob/master/good_practices/development_environment_setup.adoc + +.Summary + +- Obtain API key for internal repositories +- Configure the Debian repository +[source,bash] +sudo apt-get install apt-transport-https +sudo sh -c "echo 'deb https://USER.NAME@tecnalia.com:API_TOKEN@artifact.tecnalia.com/artifactory/tecnalia-robotics-debian xenial main' >> /etc/apt/sources.list.d/tecnalia.list" + +- Install Docker CE +[source,bash] +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg +echo \ +"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ +$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null +sudo apt update +sudo apt-get install docker-ce docker-ce-cli containerd.io +sudo usermod -aG docker USER_NAME + +- Configure the docker registry +[source,bash] +docker login tecnalia-robotics-docker.artifact.tecnalia.com + +- Configure Git LFS +[source,bash] +curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash +sudo apt-get install git-lfs +git lfs install +git config --global credential.helper 'cache --timeout=3600' + +=== 2.- Build the docker image using the Dockerfile +[source,bash] +docker build -t devenv:melodic <Path_to_Dockerfile> . + +for example: +[source,bash] +docker build -t devenv:melodic \ + --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa_TecnaliaUB20)" \ + --build-arg USER_API_KEY_ARTIFACTS_TECNALIA="$(cat ~/.ssh/user_api_key_artifacts_tecnalia)" \ + -f Dockerfile-devenv . + +// docker build -t devenv:melodic --build-arg USER_API_KEY_ARTIFACTS_TECNALIA="$(cat ~/.ssh/user_api_key_artifacts_tecnalia)" -f Devenv.Dockerfile . +// docker build -t devenv:melodic --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa_TecnaliaUB20)" --build-arg USER_API_KEY_ARTIFACTS_TECNALIA="$(cat ~/.ssh/user_api_key_artifacts_tecnalia)" -f ssh.Dockerfile . + +=== 3.- Install rocker + +https://github.com/osrf/rocker +For Debian systems +[source,bash] +sudo apt-get install python3-rocker + +=== 4.- Launch the docker image +[source,bash] +rocker --home --x11 --nvidia --user --git --ssh IMAGE_NAME:IMAGE_TAG <COMAND> + +for example: +[source,bash] +rocker --home --x11 --nvidia --user --git --ssh devenv:melodic bash + +== Notes and Tricks + +=== Windows hosts + +NOTE: ON WINDOWS NOT WORKING YET!!! Because Ubuntu installations are not recognized as WSL2 distributions on the Tecnalia laptops. + +If you are using Ubuntu 20.04 over a Windows PC with WSL2 you need to install Docker Desktop to have integration between Ubuntu 20.04 and docker +Following this guide: +https://adamtheautomator.com/how-to-set-up-docker-in-wsl-step-by-step/ + +.Summary + +- Download and install Docker Desktop +https://desktop.docker.com/win/stable/amd64/Docker%20Desktop%20Installer.exe +- Add your user to docker-users group +From a PowerShell with admin permissions: net localgroup docker-users DOMAIN\username /add +Where DOMAIN\username = TRI.LAN\Your_CODE +- Configure Docker desktop integration with WSL 2 +By default, it should be configured, otherwise, follow the tutorial. + +WARNING: Linux version installed from MS-Store must be the one without number, i.e. Numbered version e.g. Ubuntu 20.04 or Ubuntu 18.04 are not supported by WSL2 + +=== ssh and git + +- Check ssh and git permissions to access and download packages from git.code.tecnalia.com + +=== useful aliases + +- rundoc: Launch a container from the dev image +[source,bash] +function rundoc() { + rocker --home --user --x11 --nvidia --ssh --git --name melodic devenv:melodic bash +} + +- dat: Launch a terminal inside the runing container from the dev image +[source,bash] +alias dat="docker exec -it melodic bash" diff --git a/VS_Code_ROS/.gitignore b/VS_Code_ROS/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..9406a0c40cc68bd722056351c4674e372e6adfa5 --- /dev/null +++ b/VS_Code_ROS/.gitignore @@ -0,0 +1,6 @@ +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/extensions.json +!.vscode/launch.json +!.vscode/c_cpp_properties.json diff --git a/VS_Code_ROS/.vscode/c_cpp_properties.json b/VS_Code_ROS/.vscode/c_cpp_properties.json new file mode 100644 index 0000000000000000000000000000000000000000..c1c7a6e3cd322e3e9a4aa08c346e96c6f3af88b9 --- /dev/null +++ b/VS_Code_ROS/.vscode/c_cpp_properties.json @@ -0,0 +1,22 @@ +{ + "configurations": [ + { + "browse": { + "databaseFilename": "", + "limitSymbolsToIncludedHeaders": true + }, + "includePath": [ + "/opt/ros/kinetic/include", + "/usr/include/**", + "${workspaceFolder}/../../devel/include", + "${workspaceFolder}/**" + ], + "name": "Linux", + "intelliSenseMode": "gcc-x64", + "compilerPath": "/usr/bin/gcc", + "cStandard": "c11", + "cppStandard": "c++17" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/VS_Code_ROS/.vscode/launch.json b/VS_Code_ROS/.vscode/launch.json new file mode 100644 index 0000000000000000000000000000000000000000..2b5881909a92562dfe0ab745ad2305b486a258c3 --- /dev/null +++ b/VS_Code_ROS/.vscode/launch.json @@ -0,0 +1,67 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "configurations": [ + { + "name": "VS_Talker_Node", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/../../devel/lib/hello_vs_code/vs_talker", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}/../../", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + }, + { + "name": "VS_Listener_Node", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/../../devel/lib/hello_vs_code/vs_listener", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}/../../", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + }, + { + "name": "VS_Listener2_Node", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/../../devel/lib/hello_vs_code/vs_listener2", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}/../../", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/VS_Code_ROS/.vscode/tasks.json b/VS_Code_ROS/.vscode/tasks.json new file mode 100644 index 0000000000000000000000000000000000000000..7827612b5609ef7c83c818f1a9753807def750a4 --- /dev/null +++ b/VS_Code_ROS/.vscode/tasks.json @@ -0,0 +1,29 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "ROS: Build Hello_VS_CODE", + "type": "shell", + "command": "catkin_make", + "args": [ + "--pkg", + "hello_vs_code", + "-j4", + "-DCMAKE_BUILD_TYPE=Debug" + ], + "problemMatcher": "$gcc", + "options": { + "cwd": "${workspaceFolder}/../../" + }, + "group": { + "kind": "build", + "isDefault": true + }, + "presentation": { + "reveal": "always", + "revealProblems": "onProblem", + "panel": "new" + } + } + ] +} \ No newline at end of file diff --git a/VS_Code_ROS/LICENSE b/VS_Code_ROS/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..a3623725c672f03b0f88404d63f6071630049b98 --- /dev/null +++ b/VS_Code_ROS/LICENSE @@ -0,0 +1,22 @@ + +The MIT License (MIT) + +Copyright (c) 2019 MrGnomes + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/VS_Code_ROS/README.md b/VS_Code_ROS/README.md new file mode 100644 index 0000000000000000000000000000000000000000..c0efdbc06c6cb40df83c59cfb2f84154c99732f2 --- /dev/null +++ b/VS_Code_ROS/README.md @@ -0,0 +1,700 @@ +# Step By Step Integration of ROS in VS Code + +This repository provides an example set up that can be used to automate your ROS workflow in the VS Code IDE. + + +## Contents: +* [1. VS Code Extensions](#1-vs-code-extensions) +* [2. Set Up your VS Code Workspace](#2-set-up-your-vs-code-workspace) +* [3. Intellisense](#3-intellisense) +* [4. Building Your Nodes](#4-building-your-nodes) +* [5. Debugging Your Nodes](#5-debugging-your-nodes) +* [6. Multi-Root ROS Workspace](#6-multi-root-ros-workspace) + +## 1) VS Code Extensions + +I use the following extensions: + +- C/C++ (c++ intellisense and configuration help) +- CMake (Intellisense support in CMakeLists.txt files) +- CMake Tools (Extended CMake support in Visual Studio Code) +- GitLens (Git support and additional git tab) +- Python (If you're using rospy) +- vscode-icons (Optional, but helps with all the different file types used by ROS) +- ROS (Adds helper actions for starting the roscore, for creating ROS packages and provides syntax highlighting for .msg, .urdf and other ROS files) + + +### GitLens has a problem with git versions <= 2.7. Update git on Ubuntu 16.04 + +``` +sudo apt-get install python-software-properties software-properties-common +sudo add-apt-repository ppa:git-core/ppa -y +sudo apt-get update +sudo apt-get upgrade +sudo apt-get install git -y +``` + +Check with `git --version` that the newly installed version is > 2.7. + +## 2) Set Up your VS Code Workspace + +Assuming your catkin workspace is all set up and running smoothly, we need to tell VS Code where our ROS workspace is. +This can be accomplished in two ways: +1) Open the catkin root folder in VS Code and use the complete catkin folder as your workspace. + This is a centralized ROS package management approach, where you get to see every ROS package and where you have to manage your configurations + globally for every package. Meaning one launch.json and one task.json for everything. + This is the most common approach seen on the web. +2) Use the multi-root option VS Code provides to manage each ROS package as a single project and provide individual + build, debug and other run tasks that are common on a package level. + You can then add each ROS package folder to your workspace (each with it's individual configurations) and VS Code + will find all your launch.json and task.json files. + When you search for a launch or a build configuration, VS Code will also add the name of the ROS package folder to your label + as a suffix, so you can find the configuration based on the package name. + I personally like this approach more, because of the nice clean separation of build and debugging tasks between my packages and because this essentially make every ROS package self contained. + +But first let's try the first approach and build/debug a package from a centralized configuration, since it is easier to start with. + +Start a VS Code instance, open the catkin_ws workspace folder and go to "File>Save Workspace As" and save the workspace file in your catkin root. +This should add the {workspaceName}.code-workspace file and a .vscode folder to your catkin_ws root folder. +You should now have the following (or a similar) folder structure: +``` +~/catkin_ws + .vscode/ + build/ + devel/ + src/ + ROS_WS.code-workspace +``` + +## 3) Intellisense + +To add intellisense support for ROS nodes we need to provide a c_cpp_properties.json in our .vscode folder. +This is used by the C/C++ Extension to search for all the include folders that are referenced by the node. + +c_cpp_properties.json +``` +{ + "configurations": [ + { + "name": "Linux", + "browse": { + "databaseFilename": "", + "limitSymbolsToIncludedHeaders": true + }, + "includePath": [ + "${workspaceFolder}/devel/include", + "/opt/ros/kinetic/include", + "/usr/include/**", + "${workspaceFolder}/**" + ], + "intelliSenseMode": "gcc-x64", + "compilerPath": "/usr/bin/g++", + "cStandard": "c11", + "cppStandard": "c++17" + } + ], + "version": 4 +} +``` + +The most import option is the `includePath`. +It points the intellisense tools to the right folders. +The first line is the path to the catkin devel includes, that include generated headers for your .srv and .msg files. +You can access them with `#include "<pacakgeName>/<msg_srv_name>.h` in your nodes. +The second include is the path to the ros headers (ros.h etc.). +The last line is a recursive pattern that VS Code unterstands. +It starts at your workspace root folder and then works down to every folder in your workspace folder. + In the global management environment it's the ~/catkin_ws folder. + In the multi-root environment it's the ROS package root folder you added as a folder to your workspace. + +In a typical package folder structure like in the image below you can include your package headers from `<pacakgeName>/include/<packagename>/<name>.h` with a `#include <packageName>/<name>.h` to your node. + +Keep in mind that this is only for intellisense. +If you set up your build configuration correctly, your packages would still build fine when using catkin_make, regardless of what is configured in this file. + + + + +If you're on a Mac you might want to use clang: +``` +{ + "configurations": [ + { + "name": "Mac", + "includePath": [ + "${workspaceFolder}//devel/include", + "/opt/ros/kinetic/include", + "/usr/include/**", + "${workspaceFolder}/**" + ], + "intelliSenseMode": "clang-x64", + "compilerPath": "/usr/bin/clang++", + "cStandard": "c11", + "cppStandard": "c++17", + "compileCommands": "${workspaceFolder}/build/compile_commands.json" + } + ], + "version": 4 +} +``` + + +You can also combine both in the same file, and select your environment. +Check out the documentation for more info on that. + +## 4) Building Your Nodes + +You should now have a VS Code workspace set up in your catkin workspace root. +To build the ROS nodes we need to add a build task configuration. +Add the following task.json to the folder ~/catkin_ws/.vscode: +``` +{ + "version": "2.0.0", + "tasks": [ + { + "label": "ROS: catkin_make", + "type": "shell", + "command": "catkin_make", + "args": [ + "-j4", + "-DCMAKE_BUILD_TYPE=Debug" + ], + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} +``` + +You can now run `CTRL+SHIFT+P`, search for "Tasks: Run Task" and select the "ROS: catkin_make" task we configured. Since we set it to be the default build task with the `group` option you can also run that task with the shortcut `CTRL+SHIFT+B`. +The build type is set to "Debug", so that the ROS nodes can be debugged later on. +If you need a "compile_commands.json" for clang, you can add "-DCMAKE_EXPORT_COMPILE_COMMANDS=1" as an additional argument to the `args` option. +This will generate a compile_commands in the ~/catkin_ws/build folder that you can reference in the c_cpp_properties.json file. + +You can add your own additional configurations and run them with the "Run Task" action, or provide your own keybindings for your own build configurations. +Check out the VS Code documentation for more information on that. + +If your ROS workspace contains a lot of packages you may not want to build them all. +You can add these additional parameters to the catkin_make task for that: +``` +{ + "version": "2.0.0", + "tasks": [ + { + "label": "ROS: catkin_make", + "type": "shell", + "command": "catkin_make", + "args": [ + "--pkg", + "<your package name, e.g. hello_vs_code>", + "-j4", + "-DCMAKE_BUILD_TYPE=Debug" + ], + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} +``` +Note that catkin will still be configuring every package in the catkin-ws, but it will only build the specified one. +You can check this by inspecting the ~/catkin_ws/devel/lib/**packagename** folder. + +## 5) Debugging Your Nodes + +Setting up a working debugging session is pretty straight forward with VS Code. +I'll show you how to debug a single node first and build upon that to configure a multi-node debugging set up. + +The following sections assume you have a hello_vs_code package in your ~/catkin_ws/src folder, with three nodes: talker.cpp, listener.cpp, listener2.cpp, and that you built the packages. +You can also clone this repo and build the package I am providing here. + +### Debug a Single ROS Node with VS Code (C++) + +Add a launch configuration (launch.json) to the .vscode folder in the catkin_ws and paste this to debug the talker node. + +launch.json +``` +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(gdb) Launch", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/devel/lib/hello_vs_code/vs_talker", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} +``` +If you're using your own package, you have to change the path in the `program` option to point to your executable. +Unfortunatly I haven't found a way to generate this automatically based on the catkin build system outputs. +Maybe it's possible by using roslaunch and then attach to the active node. +The ${worksspaceFolder} is the top level folder of your workspace (in this case it's catkin_ws). +If your ${workspaceFolder} isn't the catkin root, then you also need to change the `cwd` option to point to your catkin root folder. +More on that when we're setting up the multi-root workspace. + +Set a breakpoint in your node file you want to debug (e.g. talker.cpp). +Start the roscore by using the ROS extension. +For that type `CTRL+SHIFT+P` and search for "ROS: Start Core" and check at the status bar that the ROS master is running. +You can also open up a terminal and type in `roscore`. + +Press F5 to launch the debugging session and make sure that you build +with the `-DCMAKE_BUILD_TYPE=Debug` option. +If you used the task.json example given in this guide, then you should be fine. + +After that you can step through your node like in the example below: + + + +The "`poll failed with ...`" error message is due to a bug in +the current ros_comm module. See issue [#1370][i1370] for updates. + +### Debug Multiple ROS Nodes with VS Code (C++) + +Since ROS uses the publisher/subscriber and request/response models, it's usually more interresting to debug multiple nodes that are interconnected through the ROS master. +The `configurations` option in the launch.json shown above is actually an array. +You add multiple debug configurations by adding them to it. +But how do you use these configurations to actually start multiple debugging sessions? + +There are currently three ways (known to me): + +1) Open up a new VS Code window and select a configuration to be used by the new window and start the debugger. +2) Switch to the debug tab and select a configuration from the combo box, and start +every configuration by hand. +3) Use an additional `compounds` option and start multiple configuration simultaniously. + +So lets get those up and running and see whats possible. + +#### The Separate Window Approach (recommended) + +The obvious thing to try, would be to just open up a new window and open the workspace we already set up (using the vscode workspace file). +Unfortunatly this isn't (currently) possible. +The next thing to try would be to have the **worspace** open in one VS Code instance and than open up another instance and tell VS Code to open the catkin root folder directly and not using the workspace file. +Both are pointing to same folder, but internally VS Code treats them differently. +This works, but you can't open the catkin root folder more than once (at least I couldn't). +So you're left with debugging a maximum of two nodes. + +The approach that worked for me, was presented in [#19793](i19793): + +- Launch a new VS Code window +- Use the "Add Workspace Folder" action + +  + +- Select the catkin root folder (in my case catkin_ws), or in a multi-root setup select the ROS package folder you wan't to debug +- Switch to the debug tab. VS Code automatically detects all launch configurations inside your new workspace +- Set your breakpoints, select a configuration and start debugging +- Repeat for every node you want to debug + +Below is an example where I am debugging three different nodes. A talker node that publishes to two subscribed listener nodes. +You can see that I was stepping through the talker node in the left window and as soon +as I moved past the `talker_pub.publish(...)` line, the breakpoint hit on +both of VS Code instances on the right, that had active debugging sessions for the listener nodes. +  + +Combine this with the great intellisense provided and you have an incredibly powerfull tool at your hand for programming ROS nodes, which makes VS Code my go to IDE when I am working on any robotics stuff. + +Here are a couple of points I like about the multi-window approach: + +- Every window handles just one debugging session, getting a full responsive workflow +- I can choose which nodes to debug, and the visual separation helps me to keep track of where every node currently is and what it is doing +- I get a seperate local variable watch window for every node +- I can leave every window open as long as I want, while all my breakpoints are preserved. I can edit every file from any window and VS Code keeps track of everything + +The downside is that this approach is consuming more window space, which can +get cluttered on a single monitor set up. + +Here is the complete launch.json and the tasks.json used for the global set up: +``` +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "configurations": [ + { + "name": "Talker_Node", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/devel/lib/hello_vs_code/vs_talker", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + }, + { + "name": "Listener_Node", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/devel/lib/hello_vs_code/vs_listener", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + }, + { + "name": "Listener2_Node", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/devel/lib/hello_vs_code/vs_listener2", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ], + "compounds": [ + { + "name": "Talker/Listener", + "configurations": ["Talker_Node", "Listener_Node"] + } + ] +} +``` +task.json +``` +{ + "version": "2.0.0", + "tasks": [ + { + "label": "ROS: catkin_make", + "type": "shell", + "command": "catkin_make", + "args": [ + "--pkg", + "hello_vs_code", + "-j4", + "-DCMAKE_BUILD_TYPE=Debug", + ], + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} +``` + +#### The Compound Approach + +VS Code can launch multiple debug configuration from the same window, you just need to define them (we'll be using the ones defined above). +Switch to the debug tab, set your breakpoints, select a configuration and start it. +To start another one, just select another configuration from the combo box and start it. It's pretty much that easy. + +By starting more than one debugging session, the debug toolbar changes and it adds a combo box that allows you to select the active session you currently want to view. +This basically means that you can only view the breakpoints and step through the code of the session that is currently selected in the combo box. + +You can also add the `compounds` option to your launch configuration and start as many debug sessions simultaneously as you want, but you can still only view the breakpoints of the one that is selected. +You also need to close every debugging session individually when you want to stop debugging and you need to do it for every debug configuration you included in the compounds option. + +In the example below I started the talker and the listener configuration and stepped through the talker code until I +passed the `talker_pub.publish(...)` code. +Notice that I switched the active session to the "Talker_Node" in the debugger tool bar and that I don't see +the breakpoint beeing hit in the listener window on the right side. + + + +Now VS Code does a pretty good job switching automatically the session where a breakpoint was hit +(see the image below). +This also aplies to the multi-window approach. +VS-Code automatically switches the window to the one where a breakpoint was hit. + + +The one thing I personally don't like, is that as soon as I step through the listener callback, the program returns to the ROS spin thread and then VS Code stays in the "Listener_Node" debug session, leaving me to manually select the talker node, to be able to step through the original node I debugged. + +This is obviously just a matter of personal preference, but I like having the yellow bar as a visual feedback to know where every node is (see the image in the windowed section). +And I don't like stepping through every configuration to get back to the previous one. +This gets even worse as the number of nodes in your workspace increases, altough VS Code provides you with means to search for a debug configuration by name. +But it's still more annoying (to me) than to just have the debug session for a particular node always active in it's own window. + +## 6) Multi-Root ROS Workspace + +Ok so now we have a global task.json, launch.json and c_cpp_properties.json sitting in our catkin root folder. +Since it is local, we don't disturbe any settings of other users when publishing the package. +But it also means we have to write every configuration in this single file. +This tends to get annoying, as the number of packages and nodes increases. + +The first thing one might try, is to add local files in the package itself and hope that VS Code finds it. +Currently VS Code does not search recursively for *.json files in sub folders. +But it does find them multi-root workspaces. +So we could add a local .vscode folder to every package and create a workspace where we add every ROS package as a folder to the workspace. +As said, VS Code supports that and it is the (currently) recommended way to create a multi-root workspace in VS Code. + +It's actually possible to have the catkin_ws folder as a separate folder to your workspace, +combined with the child folders of your ROS packages. +So it seems that there would be no drawback to this method, since you get the best of both worlds (self contained ROS packages and the overall view of your build environment). +But as always in life, there is a catch. + +There seems to be bug currently in VS Code. +When adding a parent folder and it's child folder to a workspace the intellisense engine seems to break. + +But there is a solution to that too. +It only breaks when you first add the parent folder and then it's child. +Or to be more exact, when the parent folder sits above the child folder in the directoy listing of your workspace folder. +It seems that the intellisense indexer traverses the folder in the order we add them to the workspace. +If for example you start a fresh VS Code instance and you add a ROS package (e.g. VS_Code_ROS) as a folder to your workspace and then add the catkin_ws folder as **the last** folder to your workspace, everything works as expected. +If you do it the other way around, then intellisense breaks in the child folder. +Actually you can just move the catkin_ws folder to the last position in the explorer tab and most of the time it works again. +But the most reliable (and fastest way) is to remove the catkin_ws folder and readd it, after you added all your child folders to the workspace. + +So here is my working set up: + +- First remove the catkin_ws folder, leaving you with an empty workspace +- Add all the ROS packages you want as additional folders to the workspace, using the context menu when right clicking the explorer tab (see image below). Since the VS Code workspace is only a logical construct, it doesn't create a copy of your files or does something else with them. +It's more like a direct link to your specific ROS package, without any noise from any parent directory. +Here is an example workspace with only the VS_Code_ROS package added: + +- Add a .vscode folder at the package root folder. This enables VS Code to find the launch configuration for every folder you add to your workspace +- Add a taks.json, c_cpp_properties.json and launch.json configuration file to the .vscode folder and add your package specific configurations (see the .vscode folder in the VS_CODE_ROS package in the image above) +- Add your catkin_ws folder last. + When adding new packages to your workspace, you need the remove and readd your catkin_ws folder +- Since we now have multiple workspace folders in VS Code we need to tell it where to find our include folders, executables and where the catkin_ws root folder is. + We can do this using relative paths. + Remember the ${workspaceFolder} is now different for every folder you add to your workspace, because of the multi-root environment. + If you need to debug the path for a package, you can add a + task to your tasks.json where you just set "dir" or "ls" as the command, change the "cwd" option and run the task until you get the right path you need. + Here are the configrations for the shown package: + +c_cpp_properties.json +``` +{ + "configurations": [ + { + "name": "Linux", + "browse": { + "databaseFilename": "", + "limitSymbolsToIncludedHeaders": true + }, + "includePath": [ + "${workspaceFolder}/../../devel/include", + "/opt/ros/kinetic/include", + "/usr/include/**", + "${workspaceFolder}/**" + ], + "intelliSenseMode": "gcc-x64", + "compilerPath": "/usr/bin/g++", + "cStandard": "c11", + "cppStandard": "c++17" + } + ], + "version": 4 +} +``` + +tasks.json +``` +{ + "version": "2.0.0", + "tasks": [ + { + "label": "ROS: Build Hello_VS_CODE", + "type": "shell", + "command": "catkin_make", + "args": [ + "--pkg", + "hello_vs_code", + "-j4", + "-DCMAKE_BUILD_TYPE=Debug" + ], + "problemMatcher": [], + "options": { + "cwd": "${workspaceFolder}/../../" + }, + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} +``` + +launch.json +``` +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "configurations": [ + { + "name": "VS_Talker_Node", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/../../devel/lib/hello_vs_code/vs_talker", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}/../../", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + }, + { + "name": "VS_Listener_Node", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/../../devel/lib/hello_vs_code/vs_listener", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}/../../", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + }, + { + "name": "VS_Listener2_Node", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/../../devel/lib/hello_vs_code/vs_listener2", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}/../../", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ], + "compounds": [ + { + "name": "Talker/Listener", + "configurations": ["VS_Talker_Node", "VS_Listener_Node"] + } + ] +} +``` +Since the packages are subfolders of the catkin_ws/src folder, VS Code keeps highlighting the files in the explorer tab that are also open in the editor. Most of the time it will unfold the complete catkin_ws folder in the explorer tab, to show you the file beeing edited. You can set the "explorer.autoReveal" option to false to tell VS Code to stop messing with the folders. + +You now have a multi-root environment where every ROS package is completly self contained and you see the catkin_ws root folder. +This gives you full intellisense, full build flexbility and the complete debug experience previously explained. +To debug multiple nodes/packages in a multi window set up, you just need to open a new window and add +the self-contained ROS packages you want to debug to your new (temporary) workspace (as described in the [Seperate Window Approach](#the-separate-window-approach-(recommended))). + +I also use this "trick", when I want to focus on one single package. +This gives me a clean look on this single folder, while still providing the full build and debugging experience. +You can always add and remove any package folder from your workspace without losing anything. +The only difference is the catkin_ws folder with the previuosly mentioned intellisene problem. + + +With this set up you also get a nice little suffix with the name of the package folder to your debugging launch configurations when you are in the debug tab. +I just copied the launch.json from the VS_CODE_ROS package to catkin_ws/.vscode to get this doubled output: + + + +You can also add a package specific task.json and enable single package building and overriding the default build task. +Setting multiple default build tasks in a multi-root environment will force VS Code to show a searchable prompt when using the build shortcut `CTRL+SHIFT+B` and asking for a selection of the +task that should be run. +Here is the example shown above of a package specific default build task that only builds the hello_vs_code package: +``` +{ + "version": "2.0.0", + "tasks": [ + { + "label": "ROS: Build Hello_VS_CODE", + "type": "shell", + "command": "catkin_make", + "args": [ + "--pkg", + "hello_vs_code", + "-j4", + "-DCMAKE_BUILD_TYPE=Debug" + ], + "problemMatcher": [], + "options": { + "cwd": "${workspaceFolder}/../../" + }, + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} +``` + +You can add any other tasks specific to that package, like launching rviz or other plugins. +And then you can add those tasks as a preLaunchTask in your launch.json to start automatically with your debugging session when you hit F5. +Or you can add package specific keybindings to your package specific tasks, to enable a really fast workflow. + + +So have fun coding and debugging ROS nodes with VS Code. + + + <!-- Links --> + +[i1370]: https://github.com/ros/ros_comm/issues/1370 +[i19793]: https://github.com/Microsoft/vscode/issues/19793 +[idebug]: https://vscode.readthedocs.io/en/latest/editor/debugging/ diff --git a/VS_Code_ROS/docs/FolderStructure.png b/VS_Code_ROS/docs/FolderStructure.png new file mode 100644 index 0000000000000000000000000000000000000000..26173e59c11a4b18b02fe8e25766951801828113 Binary files /dev/null and b/VS_Code_ROS/docs/FolderStructure.png differ diff --git a/VS_Code_ROS/docs/addFolder.png b/VS_Code_ROS/docs/addFolder.png new file mode 100644 index 0000000000000000000000000000000000000000..e2c1902405acd28c0d32d737f390b83ef1d146bb Binary files /dev/null and b/VS_Code_ROS/docs/addFolder.png differ diff --git a/VS_Code_ROS/docs/addWS.png b/VS_Code_ROS/docs/addWS.png new file mode 100644 index 0000000000000000000000000000000000000000..5395060bab5a0220be791bbb1f61c5a2127c417f Binary files /dev/null and b/VS_Code_ROS/docs/addWS.png differ diff --git a/VS_Code_ROS/docs/debugConfigs.png b/VS_Code_ROS/docs/debugConfigs.png new file mode 100644 index 0000000000000000000000000000000000000000..a1ba6bfbf7a16d5e68c2fe7303c0e247ffbe5e40 Binary files /dev/null and b/VS_Code_ROS/docs/debugConfigs.png differ diff --git a/VS_Code_ROS/docs/listenerComp.png b/VS_Code_ROS/docs/listenerComp.png new file mode 100644 index 0000000000000000000000000000000000000000..53dce10133d472b8b2a3334c56bf1232ebff2a47 Binary files /dev/null and b/VS_Code_ROS/docs/listenerComp.png differ diff --git a/VS_Code_ROS/docs/multiDebug.png b/VS_Code_ROS/docs/multiDebug.png new file mode 100644 index 0000000000000000000000000000000000000000..78bf99cb20dcdb05852a8ceca9d7f0448b9db172 Binary files /dev/null and b/VS_Code_ROS/docs/multiDebug.png differ diff --git a/VS_Code_ROS/docs/talkerComp.png b/VS_Code_ROS/docs/talkerComp.png new file mode 100644 index 0000000000000000000000000000000000000000..ea3ffcdfdf642ff276cb3b7ca45cd0fbef065480 Binary files /dev/null and b/VS_Code_ROS/docs/talkerComp.png differ diff --git a/VS_Code_ROS/docs/talkerDebug.png b/VS_Code_ROS/docs/talkerDebug.png new file mode 100644 index 0000000000000000000000000000000000000000..0115239aa789d31c95645772833a18f35cae6f44 Binary files /dev/null and b/VS_Code_ROS/docs/talkerDebug.png differ diff --git a/VS_Code_ROS/hello_vs_code/CMakeLists.txt b/VS_Code_ROS/hello_vs_code/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..2f173422014a05a16f749bd98fc3875876aa4080 --- /dev/null +++ b/VS_Code_ROS/hello_vs_code/CMakeLists.txt @@ -0,0 +1,208 @@ +cmake_minimum_required(VERSION 2.8.3) +project(hello_vs_code) + +## Compile as C++11, supported in ROS Kinetic and newer +# add_compile_options(-std=c++11) + +## Find catkin macros and libraries +## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) +## is used, also find other catkin packages +find_package(catkin REQUIRED COMPONENTS + roscpp + rospy + std_msgs +) + +## System dependencies are found with CMake's conventions +# find_package(Boost REQUIRED COMPONENTS system) + + +## Uncomment this if the package has a setup.py. This macro ensures +## modules and global scripts declared therein get installed +## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html +# catkin_python_setup() + +################################################ +## Declare ROS messages, services and actions ## +################################################ + +## To declare and build messages, services or actions from within this +## package, follow these steps: +## * Let MSG_DEP_SET be the set of packages whose message types you use in +## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...). +## * In the file package.xml: +## * add a build_depend tag for "message_generation" +## * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET +## * If MSG_DEP_SET isn't empty the following dependency has been pulled in +## but can be declared for certainty nonetheless: +## * add a exec_depend tag for "message_runtime" +## * In this file (CMakeLists.txt): +## * add "message_generation" and every package in MSG_DEP_SET to +## find_package(catkin REQUIRED COMPONENTS ...) +## * add "message_runtime" and every package in MSG_DEP_SET to +## catkin_package(CATKIN_DEPENDS ...) +## * uncomment the add_*_files sections below as needed +## and list every .msg/.srv/.action file to be processed +## * uncomment the generate_messages entry below +## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...) + +## Generate messages in the 'msg' folder +# add_message_files( +# FILES +# Message1.msg +# Message2.msg +# ) + +## Generate services in the 'srv' folder +# add_service_files( +# FILES +# Service1.srv +# Service2.srv +# ) + +## Generate actions in the 'action' folder +# add_action_files( +# FILES +# Action1.action +# Action2.action +# ) + +## Generate added messages and services with any dependencies listed here +# generate_messages( +# DEPENDENCIES +# std_msgs +# ) + +################################################ +## Declare ROS dynamic reconfigure parameters ## +################################################ + +## To declare and build dynamic reconfigure parameters within this +## package, follow these steps: +## * In the file package.xml: +## * add a build_depend and a exec_depend tag for "dynamic_reconfigure" +## * In this file (CMakeLists.txt): +## * add "dynamic_reconfigure" to +## find_package(catkin REQUIRED COMPONENTS ...) +## * uncomment the "generate_dynamic_reconfigure_options" section below +## and list every .cfg file to be processed + +## Generate dynamic reconfigure parameters in the 'cfg' folder +# generate_dynamic_reconfigure_options( +# cfg/DynReconf1.cfg +# cfg/DynReconf2.cfg +# ) + +################################### +## catkin specific configuration ## +################################### +## The catkin_package macro generates cmake config files for your package +## Declare things to be passed to dependent projects +## INCLUDE_DIRS: uncomment this if your package contains header files +## LIBRARIES: libraries you create in this project that dependent projects also need +## CATKIN_DEPENDS: catkin_packages dependent projects also need +## DEPENDS: system dependencies of this project that dependent projects also need +catkin_package( +# INCLUDE_DIRS include +# LIBRARIES hello_vs_code +# CATKIN_DEPENDS roscpp rospy std_msgs +# DEPENDS system_lib +) + +########### +## Build ## +########### + +## Specify additional locations of header files +## Your package locations should be listed before other locations +include_directories( +# include + ${catkin_INCLUDE_DIRS} +) + +## Declare a C++ library +# add_library(${PROJECT_NAME} +# src/${PROJECT_NAME}/hello_vs_code.cpp +# ) + +## Add cmake target dependencies of the library +## as an example, code may need to be generated before libraries +## either from message generation or dynamic reconfigure +# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) + +## Declare a C++ executable +## With catkin_make all packages are built within a single CMake context +## The recommended prefix ensures that target names across packages don't collide +# add_executable(${PROJECT_NAME}_node src/hello_vs_code_node.cpp) +add_executable(vs_talker src/talker.cpp) +add_executable(vs_listener src/listener.cpp) +add_executable(vs_listener2 src/listener2.cpp) + +## Rename C++ executable without prefix +## The above recommended prefix causes long target names, the following renames the +## target back to the shorter version for ease of user use +## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node" +# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "") + +## Add cmake target dependencies of the executable +## same as for the library above +# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) + +## Specify libraries to link a library or executable target against +# target_link_libraries(${PROJECT_NAME}_node +# ${catkin_LIBRARIES} +# ) +target_link_libraries(vs_talker + ${catkin_LIBRARIES}) +target_link_libraries(vs_listener + ${catkin_LIBRARIES}) +target_link_libraries(vs_listener2 + ${catkin_LIBRARIES}) + +############# +## Install ## +############# + +# all install targets should use catkin DESTINATION variables +# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html + +## Mark executable scripts (Python etc.) for installation +## in contrast to setup.py, you can choose the destination +# install(PROGRAMS +# scripts/my_python_script +# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +# ) + +## Mark executables and/or libraries for installation +# install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_node +# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +# ) + +## Mark cpp header files for installation +# install(DIRECTORY include/${PROJECT_NAME}/ +# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} +# FILES_MATCHING PATTERN "*.h" +# PATTERN ".svn" EXCLUDE +# ) + +## Mark other files for installation (e.g. launch and bag files, etc.) +# install(FILES +# # myfile1 +# # myfile2 +# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} +# ) + +############# +## Testing ## +############# + +## Add gtest based cpp test target and link libraries +# catkin_add_gtest(${PROJECT_NAME}-test test/test_hello_vs_code.cpp) +# if(TARGET ${PROJECT_NAME}-test) +# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) +# endif() + +## Add folders to be run by python nosetests +# catkin_add_nosetests(test) diff --git a/VS_Code_ROS/hello_vs_code/package.xml b/VS_Code_ROS/hello_vs_code/package.xml new file mode 100644 index 0000000000000000000000000000000000000000..478f4f01f27f42795b37fa274ea1ef733475cc1e --- /dev/null +++ b/VS_Code_ROS/hello_vs_code/package.xml @@ -0,0 +1,28 @@ +<?xml version="1.0"?> +<package format="2"> + <name>hello_vs_code</name> + <version>0.0.0</version> + <description>Simple hello_vs_code package</description> + + <!-- One maintainer tag required, multiple allowed, one person per tag --> + <!-- Example: --> + <!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> --> + <maintainer email="MrGonmes@todo.todo">MrGnomes</maintainer> + + + <!-- One license tag required, multiple allowed, one license per tag --> + <!-- Commonly used license strings: --> + <!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 --> + <license>TODO</license> + + <buildtool_depend>catkin</buildtool_depend> + <depend>roscpp</depend> + <depend>rospy</depend> + <depend>std_msgs</depend> + + <!-- The export tag contains other, unspecified, tags --> + <export> + <!-- Other tools can request additional information be placed here --> + + </export> +</package> diff --git a/VS_Code_ROS/hello_vs_code/src/listener.cpp b/VS_Code_ROS/hello_vs_code/src/listener.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0f19d9dc25b35dd572670683754c0d1582f42860 --- /dev/null +++ b/VS_Code_ROS/hello_vs_code/src/listener.cpp @@ -0,0 +1,18 @@ +#include "ros/ros.h" +#include "std_msgs/String.h" + +void talkerCallback(const std_msgs::String::ConstPtr& rosMsg) +{ + ROS_INFO("I heard: [%s]", rosMsg->data.c_str()); +} + +int main(int argc, char** argv) +{ + ros::init(argc, argv, "listener"); + ros::NodeHandle hanlde; + + ros::Subscriber talker_sub = hanlde.subscribe("/talker", 1000, talkerCallback); + ros::spin(); + + return 0; +} \ No newline at end of file diff --git a/VS_Code_ROS/hello_vs_code/src/listener2.cpp b/VS_Code_ROS/hello_vs_code/src/listener2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..03897661e275d7004c6607e01d0cfeec45c6b237 --- /dev/null +++ b/VS_Code_ROS/hello_vs_code/src/listener2.cpp @@ -0,0 +1,18 @@ +#include "ros/ros.h" +#include "std_msgs/String.h" + +void talkerCallback(const std_msgs::String::ConstPtr& rosMsg) +{ + ROS_INFO("I heard: [%s]", rosMsg->data.c_str()); +} + +int main(int argc, char** argv) +{ + ros::init(argc, argv, "listener2"); + ros::NodeHandle hanlde; + + ros::Subscriber talker_sub = hanlde.subscribe("/talker", 1000, talkerCallback); + ros::spin(); + + return 0; +} \ No newline at end of file diff --git a/VS_Code_ROS/hello_vs_code/src/talker.cpp b/VS_Code_ROS/hello_vs_code/src/talker.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6b436ddffc769f6749b957db060965b23fba63f2 --- /dev/null +++ b/VS_Code_ROS/hello_vs_code/src/talker.cpp @@ -0,0 +1,33 @@ +#include "ros/ros.h" +#include "std_msgs/String.h" +#include <iostream> + +int main(int argc, char **argv) +{ + + ros::init(argc, argv, "talker"); + ros::NodeHandle hanlde; + + ros::Publisher talker_pub = hanlde.advertise<std_msgs::String>("/talker", 1000); + ros::Rate loop_rate(10); + int count = 0; + + while(ros::ok()) + { + std_msgs::String rosMsg; + std::stringstream ss; + + ss << "Hello Ros World [" << count << "]"; + rosMsg.data = ss.str(); + + ROS_INFO("%s", rosMsg.data.c_str()); + talker_pub.publish(rosMsg); + + ros::spinOnce(); + loop_rate.sleep(); + + ++count; + } + + return 0; +} \ No newline at end of file diff --git a/docker-tracebot/Dockerfile b/docker-tracebot/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..38a497bb875d0a42ddf5154ea41227c14b270b8a --- /dev/null +++ b/docker-tracebot/Dockerfile @@ -0,0 +1,117 @@ +################################################### +### FIRST LAYER TO DOWNLOAD GIT REPOS +FROM osrf/ros:melodic-desktop-full as intermediate + +RUN apt-get update && apt-get install -y \ + ssh \ + git \ + wget + +ARG SSH_PRIVATE_KEY +RUN mkdir ~/.ssh/ +RUN echo "${SSH_PRIVATE_KEY}" > /root/.ssh/id_rsa +RUN chmod 600 ~/.ssh/id_rsa +RUN ssh-keyscan git.code.tecnalia.com >> /root/.ssh/known_hosts && chmod 644 /root/.ssh/known_hosts + +# Create workspace +RUN mkdir -p /root/dev_ws/src +WORKDIR /root/dev_ws/src + +# Install python-wstools +RUN wget http://packages.ros.org/ros.key -O - | sudo apt-key add - +RUN apt-get update && apt-get install -y python-catkin-tools +# Clone main package +RUN git clone git@git.code.tecnalia.com:tecnalia_robotics/flexbotics/flexbotics_test/dummy_application.git +# checkout working branch +WORKDIR /root/dev_ws/src/dummy_application +RUN git checkout testing_tracebot +# Populate dependencies with rosinstall +RUN mkdir /root/dev_ws/src/dependencies +WORKDIR /root/dev_ws/src/dependencies +RUN wstool init && wstool merge ../dummy_application/.rosinstall && wstool update + +################################################### +### Setting up dev environment, so that ssh key does not stay in image +FROM osrf/ros:melodic-desktop-full + +# Avoid warnings by switching to noninteractive +ENV DEBIAN_FRONTEND=noninteractive + +# Setup environment locales +RUN apt-get update && apt-get install -y \ + locales \ + && sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen +ENV LANG=en_US.UTF-8 \ + LANGUAGE=en_US:en \ + LC_ALL=en_US.UTF-8 + +# Configure apt and install packages +RUN apt-get update \ + && apt-get -y install --no-install-recommends \ + apt-transport-https \ + ca-certificates \ + curl \ + gnupg-agent \ + software-properties-common \ + apt-utils dialog 2>&1 \ + # + # Verify if git, process tools, lsb-release (common in install instructions for CLIs) are installed + # Install the https transport support package for The Artifactory debian repository + && apt-get -y install git \ + git-lfs \ + nano \ + iproute2 \ + procps \ + lsb-release \ + curl \ + cmake \ + openssh-client \ + python-catkin-tools \ + python-osrf-pycommon \ + ros-${ROS_DISTRO}-rosmon \ + xterm \ + wget \ + && rm -rf /var/lib/apt/lists/* + +# Install docker-ce-cli +RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - &&\ + add-apt-repository \ + "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" &&\ + apt-get update && apt-get install -y docker-ce-cli &&\ + rm -rf /var/lib/apt/lists/* + +# Import the key in order to be able to use the packages from the repository +RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 7E72C5B4111A50084C63C9489E7A9B1D990CF897 + +# Configure rosdep +RUN sh -c "echo 'yaml https://git.code.tecnalia.com/tecnalia_robotics-public/gitlab_templates/raw/master/rosdistro/rosdep_tecnalia.yaml' \ + >> /etc/ros/rosdep/sources.list.d/20-default.list" + +# Source ros setup.sh +RUN /bin/sh . "/opt/ros/$ROS_DISTRO/setup.bash" + +# Install python-wstools +RUN wget http://packages.ros.org/ros.key -O - | sudo apt-key add - &&\ + apt-get update && apt-get install -y python-catkin-tools &&\ + rm -rf /var/lib/apt/lists/* + +# Copy workspace with dependencies created in the previous layer +COPY --from=intermediate /root/dev_ws /root/dev_ws +WORKDIR /root/dev_ws + +# Run rosdep +RUN apt-get update &&\ + rosdep install -iy --from-paths src/ &&\ + rm -rf /var/lib/apt/lists/* + +# Build packages +RUN catkin init && catkin config --extend /opt/ros/melodic && catkin build + +# Add source ros to .bashrc +RUN echo "#ROS\nsource /opt/ros/melodic/setup.bash\nsource /root/dev_ws/devel/setup.bash" >> /root/.bashrc + +# Switch back to dialog for any ad-hoc use of apt-get +ENV DEBIAN_FRONTEND= + +# Add source of the workspace's setup to the default entrypoint +RUN sed -i 's/exec/source "\/root\/dev_ws\/devel\/setup.bash" \nexec/' /ros_entrypoint.sh diff --git a/docker-tracebot/docker-compose.yml b/docker-tracebot/docker-compose.yml new file mode 100644 index 0000000000000000000000000000000000000000..fe7c60b2a9cc9742d349d04642b03fb8de965bea --- /dev/null +++ b/docker-tracebot/docker-compose.yml @@ -0,0 +1,16 @@ +version: "2" + +services: + tracebot: + image: tracebot + build: + context: . + dockerfile: Dockerfile + args: + SSH_PRIVATE_KEY: ${SSH_PRIVATE_KEY} + environment: + - DISPLAY + - QT_X11_NO_MITSHM=1 + volumes: + - /tmp/.X11-unix:/tmp/.X11-unix + command: stdbuf -o L roslaunch dummy_application tracebot_application.launch diff --git a/docker-tracebot/docker.md b/docker-tracebot/docker.md new file mode 100644 index 0000000000000000000000000000000000000000..e15a33af9265b74f08dd3f660ee089f51839d07c --- /dev/null +++ b/docker-tracebot/docker.md @@ -0,0 +1,64 @@ +# Using Docker + +## Setup the display + +To provide access to an application to the graphical server. + +```bash +xhost +local:docker +``` + +## Run everything with docker-compose + +To run the example using docker-compose simply run: + +```bash +SSH_PRIVATE_KEY=$(cat ~/.ssh/id_rsa) docker-compose up +``` + +## Manually compile, generate an Docker image and run a container + +### Manually compile and generate a Docker image + +Use the Dockerfile of the repository (Tracebot.Dockerfile) to compile and make a new Docker image. + +**Note**: To properly compile and make the Docker image it is necessary to pass a SSH private key (id_rsa) using the --build-arg (SSH_PRIVATE_KEY="$(cat path_to_if_rsa)") option. + +```bash +docker build --build-arg SSH_PRIVATE_KEY="$(cat path/to/id_rsa)" -t image_name:tag -f path_to_Dockerfile . +``` + +For example: + +```bash +docker build --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)" -t tracebot . +``` + +### Manually create and Run a container + +Create a container from the Docker image. + +**Note**: It is necessary to enable the docker graphics options + +```bash +docker run -it --name container_name \ + --env=DISPLAY \ + --env=QT_X11_NO_MITSHM=1 \ + --volume /tmp/.X11-unix:/tmp/.X11-unix \ + image_name:tag \ + bash +``` + +For example: + +```bash +docker run -it --rm -e DISPLAY=$DISPLAY -e QT_X11_NO_MITSHM=1 -v /tmp/.X11-unix:/tmp/.X11-unix tracebot bash +``` + +### Launch the execution manager + +To launch the application. + +```bash +roslaunch dummy_application dummy_application.launch +``` diff --git a/dockerfiles/.devcontainer/Dockerfile b/dockerfiles/.devcontainer/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d0c554e527bad17e261a3b45531ec1b43a35747d --- /dev/null +++ b/dockerfiles/.devcontainer/Dockerfile @@ -0,0 +1,49 @@ +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- + +FROM tecnalia-robotics-docker.artifact.tecnalia.com/flexbotics-fat-devel:melodic + +# Avoid warnings by switching to noninteractive +ENV DEBIAN_FRONTEND=noninteractive + +# This Dockerfile adds a non-root 'vscode' user with sudo access. However, for Linux, +# this user's GID/UID must match your local user UID/GID to avoid permission issues +# with bind mounts. Update USER_UID / USER_GID if yours is not 1000. See +# https://aka.ms/vscode-remote/containers/non-root-user for details. +ARG USERNAME=vscode +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + +# Configure apt and install packages +RUN apt-get update \ + && apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \ + # + # Verify git, process tools, lsb-release (common in install instructions for CLIs) installed + && apt-get -y install git iproute2 procps lsb-release curl \ + && apt install -y git openssh-client python-catkin-tools \ + # + # Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user. + && groupadd --gid $USER_GID $USERNAME \ + && useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \ + # [Optional] Add sudo support for the non-root user + && apt-get install -y sudo \ + && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\ + && chmod 0440 /etc/sudoers.d/$USERNAME \ + # + && rosdep init || true + +USER $USERNAME +RUN rosdep update \ + && mkdir -p /home/${USERNAME}/robot_ws/src/ + +COPY .devcontainer/catkin_ws_init.sh /tmp/ + + # Clean up + # && apt-get autoremove -y \ + # && apt-get clean -y \ + # && rm -rf /var/lib/apt/lists/* + +# Switch back to dialog for any ad-hoc use of apt-get +ENV DEBIAN_FRONTEND= diff --git a/dockerfiles/.devcontainer/catkin_ws_init.sh b/dockerfiles/.devcontainer/catkin_ws_init.sh new file mode 100644 index 0000000000000000000000000000000000000000..98e230be0efc525a673c426c38d04888094720c2 --- /dev/null +++ b/dockerfiles/.devcontainer/catkin_ws_init.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +if [[ -z "${ROS_PACKAGE_PATH}" ]]; then + . $(find /opt/ros/ -name "setup.bash") +fi + +if [[ -z "${ROS_DISTRO}" ]]; then + export ROS_DISTRO=$(basename $(find /opt/ros/* -maxdepth 0 -type d | head -1)) +fi + +pkg_name=$(basename $(find /workspaces/ -maxdepth 1 -mindepth 1 -type d)) +mkdir -p ~/robot_ws/src +cd ~/robot_ws/src +ln -s /workspaces/${pkg_name} +cd .. +wstool init src +if [ -f "src/${pkg_name}/.rosinstall" ]; then + wstool merge "src/${pkg_name}/.rosinstall" -t src +fi + +mkdir -p ~/.ssh/ +cat << EOF >> ~/.ssh/config +Host * + StrictHostKeyChecking no +EOF +wstool update -t src +find -L src -name ci_entry_script.bash -exec bash -c 'echo Running entry script from $(basename $(dirname $1)) ; $1 ' _ {} \; +rosdep update +rosdep install --from-paths src --ignore-src --rosdistro $ROS_DISTRO -r -y +catkin init +catkin config --cmake-args -DCMAKE_CXX_FLAGS=-w -- + +echo "source $(find /opt/ros/ -name 'setup.bash')" >> ~/.bashrc diff --git a/dockerfiles/.devcontainer/devcontainer.json b/dockerfiles/.devcontainer/devcontainer.json new file mode 100644 index 0000000000000000000000000000000000000000..3c9f9b620b4783693db6792dfc6c989aab6c2bbb --- /dev/null +++ b/dockerfiles/.devcontainer/devcontainer.json @@ -0,0 +1,36 @@ +// For format details, see https://aka.ms/vscode-remote/devcontainer.json +{ + "name": "flexbotics base melodic", + "context": "..", + "dockerFile": "Dockerfile", + + // Use 'settings' to set *default* container specific settings.json values on container create. + // You can edit these settings after create using File > Preferences > Settings > Remote. + "settings": { + "terminal.integrated.shell.linux": "/bin/bash" + }, + + // Uncomment the next line if you want to publish any ports. + // "appPort": [], + + // Uncomment the next line to run commands after the container is created. + "postCreateCommand": "bash /tmp/catkin_ws_init.sh", + + "workspaceFolder": "/home/vscode/robot_ws/src/", + + // Uncomment the next line to use a non-root user. On Linux, this will prevent + // new files getting created as root, but you may need to update the USER_UID + // and USER_GID in .devcontainer/Dockerfile to match your user if not 1000. + "runArgs": [ "-u", "vscode", + "-v", "${env:SSH_AUTH_SOCK}:/ssh-agent", + "-e", "SSH_AUTH_SOCK=/ssh-agent", + "-e", "DISPLAY=${env:DISPLAY}", + "-v", "/tmp/.X11-unix:/tmp/.X11-unix" + ], + + // Add the IDs of extensions you want installed when the container is created in the array below. + "extensions": [ + "ms-python.python", + "ms-iot.vscode-ros" + ] +} diff --git a/dockerfiles/DevenvMelodic.Dockerfile b/dockerfiles/DevenvMelodic.Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..8436a1d3f8742215035498ecd37aaf03facefeae --- /dev/null +++ b/dockerfiles/DevenvMelodic.Dockerfile @@ -0,0 +1,141 @@ +FROM osrf/ros:melodic-desktop-full +ENV ROS_DISTRO melodic + +# Avoid warnings by switching to noninteractive +ENV DEBIAN_FRONTEND=noninteractive + +# Setup environment +RUN apt-get update && apt-get install -y \ + locales \ + && sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen en_US.UTF-8 +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US:en +ENV LC_ALL en_US.UTF-8 + +# Configure apt and install packages +RUN apt-get -y install --no-install-recommends \ + apt-transport-https \ + ca-certificates \ + software-properties-common \ + curl \ + gnupg-agent \ + apt-utils dialog 2>&1 \ + git \ + git-lfs \ + nano \ + less \ + iproute2 \ + procps \ + lsb-release \ + curl \ + cmake \ + openssh-client \ + python-catkin-tools \ + python-osrf-pycommon \ + ros-${ROS_DISTRO}-rosmon \ + xterm \ + && rm -rf /var/lib/apt/lists/* + +# Install docker-ce +RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - +RUN add-apt-repository \ + "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" +RUN apt-get update && apt-get -y install --no-install-recommends \ + docker-ce-cli \ + && rm -rf /var/lib/apt/lists/* + +# Configure system to look for debian packages in the Artifactory repository +ARG USER_API_KEY_ARTIFACTS_TECNALIA +RUN sh -c "echo \ + 'deb https://${USER_API_KEY_ARTIFACTS_TECNALIA}@artifact.tecnalia.com/artifactory/tecnalia-robotics-debian xenial main' \ + >> /etc/apt/sources.list.d/tecnalia.list" + +# Import the key in order to be able to use the packages from the repository +RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 7E72C5B4111A50084C63C9489E7A9B1D990CF897 + +# Configure rosdep +RUN sh -c "echo 'yaml https://git.code.tecnalia.com/tecnalia_robotics-public/gitlab_templates/raw/master/rosdistro/rosdep_tecnalia.yaml' \ + >> /etc/ros/rosdep/sources.list.d/20-default.list" + +# Packages installed as dependecies of kawada_lab_aplication +RUN apt-get update && apt-get install -y \ + ros-melodic-ros-control-boilerplate \ + ros-melodic-ur-msgs \ + ros-melodic-eigen-stl-containers \ + ros-melodic-industrial-robot-simulator \ + ros-melodic-srdfdom \ + ros-melodic-joint-state-publisher-gui \ + python-pyside \ + python-lxml \ + python-qt4 \ + python-qt4-dev \ + libshiboken-dev \ + shiboken \ + libpyside-dev \ + libcomedi-dev \ + libmodbus-dev \ + libcanberra-gtk-module \ + libcanberra-gtk0 \ + cmake + +# Packages installed as dependecies of sherlock-ui +RUN apt-get install -y \ + ros-melodic-rosbridge-server \ + ros-melodic-moveit \ + ros-melodic-hector-mapping \ + ros-melodic-hector-gazebo-plugins \ + ros-melodic-amcl \ + ros-melodic-gmapping \ + ros-melodic-twist-mux \ + ros-melodic-map-server \ + ros-melodic-joy \ + ros-melodic-teb-local-planner \ + ros-melodic-move-base \ + ros-melodic-velocity-controllers \ + ros-melodic-ackermann-msgs \ + ros-melodic-robot-localization \ + ros-melodic-imu-complementary-filter \ + ros-melodic-mavros-msgs \ + ros-melodic-joint-trajectory-controller \ + python-sqlalchemy + + # Packages installed as dependecies of botarobota +RUN apt-get install -y \ + ros-melodic-ar-track-alvar-msgs \ + ros-melodic-navigation + +RUN apt-get install -y \ + ros-melodic-ar-track-alvar \ + libceres-dev \ + libglfw3-dev \ + && rm -rf /var/lib/apt/lists/* + +# Update final image +RUN apt-get update && apt-get -y upgrade + +# Install code +# SHELL ["/bin/bash", "-o", "pipefail", "-c"] +# RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg \ +# && mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg \ +# && sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list' +# RUN apt-get update && apt-get install -y --no-install-recommends \ +# code \ +# && rm -rf /var/lib/apt/lists/* + +# RUN code --user-data-dir /root \ +# --install-extension ms-iot.vscode-ros \ +# --install-extension joaompinto.asciidoctor-vscode \ +# --install-extension ms-python.python \ +# --install-extension ms-vscode.cpptools \ +# --install-extension ms-azuretools.vscode-docker \ +# --install-extension twxs.cmake + +# Set entrypoint +COPY ./ros_entrypoint.sh / +RUN chmod a+x /ros_entrypoint.sh + +ENTRYPOINT ["/ros_entrypoint.sh"] +CMD ["bash"] + +# Switch back to dialog for any ad-hoc use of apt-get +ENV DEBIAN_FRONTEND= diff --git a/dockerfiles/DevenvNoetic.Dockerfile b/dockerfiles/DevenvNoetic.Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..0fc7330e872a3331ed1a1e473233d54bfa8eed79 --- /dev/null +++ b/dockerfiles/DevenvNoetic.Dockerfile @@ -0,0 +1,91 @@ +FROM osrf/ros:noetic-desktop-full +ENV ROS_DISTRO noetic + +# Avoid warnings by switching to noninteractive +ENV DEBIAN_FRONTEND=noninteractive + +# Setup environment +RUN apt-get update && apt-get install -y \ + locales \ + && sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen en_US.UTF-8 +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US:en +ENV LC_ALL en_US.UTF-8 + +# Configure apt and install packages +RUN apt-get -y install --no-install-recommends \ + apt-transport-https \ + ca-certificates \ + curl \ + gnupg-agent \ + software-properties-common \ + apt-utils dialog 2>&1 \ + # + # Verify if git, process tools, lsb-release (common in install instructions for CLIs) are installed + # Install the https transport support package for The Artifactory debian repository + git \ + git-lfs \ + nano \ + iproute2 \ + procps \ + lsb-release \ + curl \ + cmake \ + openssh-client \ + python3-catkin-tools \ + python3-osrf-pycommon \ + ros-${ROS_DISTRO}-rosmon \ + xterm \ + terminator \ + # && rosdep init || true \ + && rm -rf /var/lib/apt/lists/* + +# Install docker-ce +RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - +RUN add-apt-repository \ + "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" +RUN apt-get update && apt-get -y install --no-install-recommends \ + docker-ce-cli \ + && rm -rf /var/lib/apt/lists/* + +# Configure system to look for debian packages in the Artifactory repository +ARG USER_API_KEY_ARTIFACTS_TECNALIA +RUN sh -c "echo \ + 'deb https://${USER_API_KEY_ARTIFACTS_TECNALIA}@artifact.tecnalia.com/artifactory/tecnalia-robotics-debian xenial main' \ + >> /etc/apt/sources.list.d/tecnalia.list" + +# Import the key in order to be able to use the packages from the repository +RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 7E72C5B4111A50084C63C9489E7A9B1D990CF897 +RUN curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add - + +# Configure rosdep +RUN sh -c "echo 'yaml https://git.code.tecnalia.com/tecnalia_robotics-public/gitlab_templates/raw/master/rosdistro/rosdep_tecnalia.yaml' \ + >> /etc/ros/rosdep/sources.list.d/20-default.list" + +# Packages installed as dependecies of kawada_lab_aplication +RUN apt-get update && apt-get install -y \ + cmake\ + && rm -rf /var/lib/apt/lists/* + +# Update final image +RUN apt-get update && apt-get -y upgrade + +# Install code +SHELL ["/bin/bash", "-o", "pipefail", "-c"] +RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg \ + && mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg \ + && sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list' + +RUN apt-get update && apt-get install -y --no-install-recommends \ + code \ + && rm -rf /var/lib/apt/lists/* + +# Set entrypoint +COPY ./ros_entrypoint.sh / +RUN chmod a+x /ros_entrypoint.sh + +ENTRYPOINT ["/ros_entrypoint.sh"] +CMD ["bash"] + +# Switch back to dialog for any ad-hoc use of apt-get +ENV DEBIAN_FRONTEND= diff --git a/dockerfiles/Robouton.Dockerfile b/dockerfiles/Robouton.Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..2cddaeb24071106b1d6b86f0c80d4f903319622f --- /dev/null +++ b/dockerfiles/Robouton.Dockerfile @@ -0,0 +1,144 @@ +FROM ubuntu:18.04 +SHELL ["/bin/bash", "-c"] + +# Update system +RUN apt-get update && apt-get install -y apt-transport-https +RUN apt-get install -y apt-utils +RUN apt-get -y upgrade +RUN apt-get update +RUN apt-get -y --purge autoremove + +# Installing necessary packages +# RUN apt-get install -y gnupg2 +RUN apt-get install -y curl +RUN apt-get install -y lsb-release +ARG DEBIAN_FRONTEND=noninteractive +RUN apt-get install -y nano +RUN apt-get install -y wget +RUN apt-get install -y python-pip +# RUN apt-get install -y libpng16-16 +# RUN apt-get install -y libjpeg-turbo8 +# RUN apt-get install -y libtiff5 +RUN apt-get install -y byobu + +# Installing ROS-melodic +RUN sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' +RUN curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add - + +RUN apt-get update +RUN apt-get install -y ros-melodic-desktop-full +# ----- Parche para subsanar los errores que devuelve el codigo de Robotnik con estos paquetes +RUN apt-get install -y ros-melodic-navigation +RUN apt-get install -y ros-melodic-ar-track-alvar +# ----- +RUN apt-get install -y python-rosdep +RUN rosdep init +RUN rosdep update +RUN echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc +RUN apt-get install -y python-rosinstall python-rosinstall-generator python-wstool build-essential + +# Installing pyton-catkin +RUN sh -c 'echo "deb http://packages.ros.org/ros/ubuntu `lsb_release -sc` main" > /etc/apt/sources.list.d/ros-latest.list' +RUN wget http://packages.ros.org/ros.key -O - | sudo apt-key add - +RUN apt-get update +RUN apt-get install -y python-catkin-tools +RUN apt-get install -y software-properties-common + +RUN echo "source /opt/ros/melodic/setup.bash" >> ~/.bash_profile + +# Create a ROS Workspace +RUN source /opt/ros/melodic/setup.bash +RUN mkdir -p /root/ros/catkin_ws/src +ENV DIRPATH=/root/ros/catkin_ws +WORKDIR $DIRPATH +RUN catkin init +RUN catkin config --extend /opt/ros/melodic +RUN catkin build + +# Install software +RUN apt-get install -y git +# Make ssh dir +RUN mkdir /root/.ssh/ +# Copy over private key, and set permissions +# Warning! Anyone who gets their hands on this image will be able +# to retrieve this private key file from the corresponding image layer +ADD id_rsa_TecnaliaUB20 /root/.ssh/id_rsa +# Create known_hosts +RUN touch /root/.ssh/known_hosts +# Add github key +RUN ssh-keyscan github.com >> /root/.ssh/known_hosts +# Clone the conf files into the docker container + + + +# PROVISIONAL HASTA QUE ROBOTNIK ACEPTE EL CAMBIO DEL FICHERO .gitmodules +# ------------------------ BORRAR ------------------------------------- +WORKDIR $DIRPATH/src +RUN git clone git@github.com:Robotnik-Tecnalia/rbrobout.git + +WORKDIR $DIRPATH/src/rbrobout +# Parches para cambiar el fichero .gitmodules y poder trabajar con la clave ssh +RUN sed -i 's#https://github.com/#git@github.com:#g' .gitmodules +RUN sed -i 's#https://www.github.com/#git@github.com:#g' .gitmodules +RUN sed -i 's#http://github.com/#git@github.com:#g' .gitmodules +RUN sed -i 's#http://www.github.com/#git@github.com:#g' .gitmodules +# Parche para intentar que descargue gazebo_ros_pkgs en su version de melodic con libgazebo9 +RUN sed -i 's#gazebo_ros_pkgs.git#gazebo_ros_pkgs.git\n\tbranch = melodic-devel#g' .gitmodules + +RUN git submodule init +RUN git submodule update + +# ---------------------------------------------------------------------- + +# Cloning Robouton repository +# WORKDIR src/ +# RUN git clone --recurse-submodules git@github.com:Robotnik-Tecnalia/rbrobout.git +WORKDIR $DIRPATH +WORKDIR $DIRPATH/src/rbrobout/libraries +RUN chmod +x install.sh +RUN ./install.sh +WORKDIR $DIRPATH +# RUN apt update + +# RUN rosdep install --from-paths src --ignore-src -r -y --rosdistro melodic +RUN apt-get install -y ros-melodic-libpcan +RUN apt-get install -y ros-melodic-ueye-cam + +# RUN git clone git@github.com:RobotnikAutomation/summit_xl_sim.git +# RUN git clone git@github.com:RobotnikAutomation/summit_xl_common.git +# RUN git clone git@github.com:RobotnikAutomation/robotnik_msgs.git +# RUN git clone git@github.com:RobotnikAutomation/robotnik_sensors.git +# WORKDIR $DIRPATH +RUN rosdep install --from-paths src --ignore-src -r -y --rosdistro melodic || true +# # WORKDIR src/ +# RUN catkin build + +# Install PeakCan linux driver from sources +WORKDIR $DIRPATH/src/rbrobout/libraries/external +RUN tar xzvf peak-linux-driver-8.10.0.tar.gz +WORKDIR $DIRPATH/src/rbrobout/libraries/external/peak-linux-driver-8.10.0 +RUN apt-get install -y linux-headers-5.4.0-77-generic +RUN apt-get install -y libpopt-dev + +# Compile and install Pcan + +RUN make KERNEL_LOCATION=/usr/src/linux-headers-5.4.0-77-generic clean \ + && make KERNEL_LOCATION=/usr/src/linux-headers-5.4.0-77-generic \ + && make KERNEL_LOCATION=/usr/src/linux-headers-5.4.0-77-generic install || true \ + && sed -i '41d' Makefile \ + && make KERNEL_LOCATION=/usr/src/linux-headers-5.4.0-77-generic install + +# RUN make +# RUN make install +# Delete line 41 to not install the Pcan driver driver +# Only the hearders are needed +# RUN sed -i '41d' Makefile +# RUN make install + +RUN echo "source /root/ros/catkin_ws/devel/setup.bash" >> ~/.bashrc +WORKDIR $DIRPATH +RUN source devel/setup.bash +# ENTRYPOINT ["source", "devel/setup.bash"] +RUN catkin build + +CMD ["tail", "-f", "/dev/null"] diff --git a/dockerfiles/kawada_lab_application.ddeploy.yaml b/dockerfiles/kawada_lab_application.ddeploy.yaml new file mode 100644 index 0000000000000000000000000000000000000000..98b504746fc79c92d1463ddc26f654be2ae684f8 --- /dev/null +++ b/dockerfiles/kawada_lab_application.ddeploy.yaml @@ -0,0 +1,12 @@ +# kawada_lab_application.ddeploy.yaml +project_name: kawada_lab_application +ros_distro: melodic +project_sources: + - /home/andres/workspace/kawada_ws/src +image_name: tecnalia/kawada_lab_application +addon_name: melodic-kawada_lab_application +oci_source: https://git.code.tecnalia.com/tecnalia_robotics/kawada/kawada_lab_application +oci_title: kawada_lab_application deployment image +base_image: osrf/ros:melodic-desktop-full + + diff --git a/dockerfiles/ros_entrypoint.sh b/dockerfiles/ros_entrypoint.sh new file mode 100644 index 0000000000000000000000000000000000000000..4a33870bfda3926a3ed362adef2bcd9b91791c8b --- /dev/null +++ b/dockerfiles/ros_entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# Setup ros environment +source "/opt/ros/$ROS_DISTRO/setup.bash" +exec "$@" \ No newline at end of file diff --git a/dockerfiles/ssh.Dockerfile b/dockerfiles/ssh.Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..e427386831d264107de6e59f279df1168795f7ba --- /dev/null +++ b/dockerfiles/ssh.Dockerfile @@ -0,0 +1,155 @@ +### FIRST LAYER TO DOWNLOAD GIT REPOS +FROM osrf/ros:melodic-desktop-full as intermediate + +RUN apt-get update + +################################# +# Add ssh private key +RUN apt-get install -y ssh + +ARG SSH_PRIVATE_KEY +RUN mkdir ~/.ssh/ +RUN echo "${SSH_PRIVATE_KEY}" > /root/.ssh/id_rsa +RUN chmod 600 ~/.ssh/id_rsa +RUN ssh-keyscan git.code.tecnalia.com >> /root/.ssh/known_hosts && chmod 644 /root/.ssh/known_hosts + +#Print SSH_PRIVATE_KEY (for test) +#RUN echo "${SSH_PRIVATE_KEY}" + +RUN apt-get install -y git + +# Create workspace +RUN mkdir -p /root/dev_ws/src +WORKDIR /root/dev_ws/src + +# Install python-wstools +RUN apt-get install -y wget +RUN wget http://packages.ros.org/ros.key -O - | sudo apt-key add - +RUN apt-get update +RUN apt-get install -y python-catkin-tools +# Clone main package +WORKDIR /root/dev_ws/src +RUN git clone git@git.code.tecnalia.com:tecnalia_robotics/kawada/kawada_lab_application.git +# Populate dependencies with rosinstall +RUN mkdir /root/dev_ws/src/dependencies +WORKDIR /root/dev_ws/src/dependencies +RUN wstool init && wstool merge ../kawada_lab_application/.rosinstall && wstool update + + +### SECOND LAYER TO BUILD DEV-ENV +FROM osrf/ros:melodic-desktop-full + +ENV ROS_DISTRO melodic +# Avoid warnings by switching to noninteractive +ENV DEBIAN_FRONTEND=noninteractive + +# Setup environment +RUN apt-get update && apt-get install -y \ + locales && sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen en_US.UTF-8 +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US:en +ENV LC_ALL en_US.UTF-8 + +# Configure apt and install packages +RUN apt-get update \ + && apt-get -y install --no-install-recommends \ + apt-transport-https \ + ca-certificates \ + curl \ + gnupg-agent \ + software-properties-common \ + apt-utils dialog 2>&1 \ + # + # Verify git, process tools, lsb-release (common in install instructions for CLIs) installed + # Install the https transport support package for The Artifactory debian repository + && apt-get -y install git \ + git-lfs \ + nano \ + iproute2 \ + procps \ + lsb-release \ + curl \ + cmake \ + && apt-get -y install openssh-client \ + python-catkin-tools \ + python-osrf-pycommon \ + ros-${ROS_DISTRO}-rosmon \ + xterm \ + && rosdep init || true \ + && rm -rf /var/lib/apt/lists/* + +# Install docker-ce +RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - +RUN add-apt-repository \ + "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" +RUN apt-get update \ + && apt-get install -y \ + docker-ce-cli \ + && rm -rf /var/lib/apt/lists/* + +# Configure system to look for debian packages in the Artifactory repository +ARG USER_API_KEY_ARTIFACTS_TECNALIA +RUN sh -c "echo \ + 'deb https://${USER_API_KEY_ARTIFACTS_TECNALIA}@artifact.tecnalia.com/artifactory/tecnalia-robotics-debian xenial main' \ + >> /etc/apt/sources.list.d/tecnalia.list" + +# Import the key in order to be able to use the packages from the repository +RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 7E72C5B4111A50084C63C9489E7A9B1D990CF897 + +# Configure rosdep +RUN sh -c "echo 'yaml https://git.code.tecnalia.com/tecnalia_robotics-public/gitlab_templates/raw/master/rosdistro/rosdep_tecnalia.yaml' \ + >> /etc/ros/rosdep/sources.list.d/20-default.list" + +# Packages installed as dependecies of kawada_lab_aplication +RUN apt-get update && apt-get install -y \ + ros-melodic-ros-control-boilerplate \ + ros-melodic-moveit-planners-ompl \ + ros-melodic-moveit-plugins \ + ros-melodic-moveit-ros-visualization \ + ros-melodic-moveit-ros-planning-interface \ + ros-melodic-moveit-setup-assistant \ + ros-melodic-moveit-fake-controller-manager \ + ros-melodic-moveit-kinematics \ + ros-melodic-moveit-ros-move-group \ + ros-melodic-ur-msgs \ + ros-melodic-eigen-stl-containers \ + ros-melodic-industrial-robot-simulator \ + ros-melodic-move-base-msgs \ + ros-melodic-srdfdom \ + ros-melodic-joint-state-publisher-gui \ + python-pyside \ + python-lxml \ + python-qt4 \ + python-qt4-dev \ + libshiboken-dev \ + shiboken \ + libpyside-dev \ + libcomedi-dev \ + libmodbus-dev \ + libcanberra-gtk-module \ + libcanberra-gtk0 \ + && rm -rf /var/lib/apt/lists/* + +# Update final image +RUN apt-get update && apt-get -y upgrade + +# Install helping packages +RUN apt-get install -y terminator +RUN apt-get install -y less iputils-ping + +# Source ros setup.sh +RUN /bin/sh . "/opt/ros/$ROS_DISTRO/setup.bash" + +# Install python-wstools +RUN apt-get install -y wget +RUN wget http://packages.ros.org/ros.key -O - | sudo apt-key add - +RUN apt-get update +RUN apt-get install -y python-catkin-tools + +# Copy workspace with dependencies created in the previous layer +COPY --from=intermediate /root/dev_ws /root/dev_ws +WORKDIR /root/dev_ws +RUN catkin init && catkin config --extend /opt/ros/melodic && catkin build + +# Add source ros to .bashrc +RUN echo "#ROS\nsource /opt/ros/melodic/setup.bash\nsource /root/dev_ws/devel/setup.bash" >> /root/.bashrc diff --git a/dockerfiles/urko.Dockerfile b/dockerfiles/urko.Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..bba964489c170fa84f3ac1fb551d4f7614a37dc6 --- /dev/null +++ b/dockerfiles/urko.Dockerfile @@ -0,0 +1,161 @@ +### FIRST LAYER TO DOWNLOAD GIT REPOS +FROM osrf/ros:melodic-desktop-full as intermediate + +RUN apt-get update + +################################# +# Add ssh private key +RUN apt-get install -y ssh + +arg SSH_PRIVATE_KEY +RUN mkdir ~/.ssh/ +RUN echo "${SSH_PRIVATE_KEY}" > /root/.ssh/id_rsa +RUN chmod 600 ~/.ssh/id_rsa +RUN ssh-keyscan git.code.tecnalia.com >> /root/.ssh/known_hosts && chmod 644 /root/.ssh/known_hosts + +#Print SSH_PRIVATE_KEY (for test) +RUN echo "${SSH_PRIVATE_KEY}" + +RUN apt-get install -y git + +# Create workspace +RUN mkdir -p /root/dev_ws/src +WORKDIR /root/dev_ws/src + +# Install python-wstools +RUN apt-get install -y wget +RUN wget http://packages.ros.org/ros.key -O - | sudo apt-key add - +RUN apt-get update +RUN apt-get install -y python-catkin-tools +# Clone main package +WORKDIR /root/dev_ws/src +RUN git clone git@git.code.tecnalia.com:tecnalia_robotics/kawada/kawada_lab_application.git +# Populate dependencies with rosinstall +RUN mkdir /root/dev_ws/src/dependencies +WORKDIR /root/dev_ws/src/dependencies +RUN wstool init && wstool merge ../kawada_lab_application/.rosinstall && wstool update + + +#FROM tecnalia-robotics-docker.artifact.tecnalia.com/flexbotics-fat-devel:melodic +FROM osrf/ros:melodic-desktop-full + +ENV ROS_DISTRO melodic +# Avoid warnings by switching to noninteractive +ENV DEBIAN_FRONTEND=noninteractive + +# Setup environment +RUN apt-get update && apt-get install -y \ + locales \ + && locale-gen en_US.UTF-8 + +RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US:en +ENV LC_ALL en_US.UTF-8 + +# Configure apt and install packages +RUN apt-get update \ + && apt-get -y install --no-install-recommends \ + apt-transport-https \ + ca-certificates \ + curl \ + gnupg-agent \ + software-properties-common \ + apt-utils dialog 2>&1 \ + # + # Verify git, process tools, lsb-release (common in install instructions for CLIs) installed + # Install the https transport support package for The Artifactory debian repository + && apt-get -y install git \ + git-lfs \ + nano \ + iproute2 \ + procps \ + lsb-release \ + curl \ + cmake \ + && apt-get -y install openssh-client \ + python-catkin-tools \ + python-osrf-pycommon \ + ros-${ROS_DISTRO}-rosmon \ + xterm \ + && rosdep init || true \ + && rm -rf /var/lib/apt/lists/* + +RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - + +RUN add-apt-repository \ + "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" + +RUN apt-get update \ + && apt-get install -y \ + docker-ce-cli \ + && rm -rf /var/lib/apt/lists/* + +# Configure system to look for debian packages in the Artifactory repository +RUN sh -c "echo \ + 'deb https://andres.montano@tecnalia.com:AKCp8jQcqPn8BQrgnqSShfsqvkS4vMbJL5WNYduVAcxaH7kbpVCyQsLnQgEhr4UeQNZoSgwwk@artifact.tecnalia.com/artifactory/tecnalia-robotics-debian xenial main' \ + >> /etc/apt/sources.list.d/tecnalia.list" + +# Import the key in order to be able to use the packages from the repository +RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 7E72C5B4111A50084C63C9489E7A9B1D990CF897 + +# Configure rosdep +RUN sh -c "echo 'yaml https://git.code.tecnalia.com/tecnalia_robotics-public/gitlab_templates/raw/master/rosdistro/rosdep_tecnalia.yaml' \ + >> /etc/ros/rosdep/sources.list.d/20-default.list" + +# COPY ./catkin_ws_init.sh / +# Packages installed as dependecies of kawada_lab_aplication +RUN apt-get update && apt-get install -y \ + ros-melodic-ros-control-boilerplate \ + ros-melodic-moveit-planners-ompl \ + ros-melodic-moveit-plugins \ + ros-melodic-moveit-ros-visualization \ + ros-melodic-moveit-ros-planning-interface \ + ros-melodic-moveit-setup-assistant \ + ros-melodic-moveit-fake-controller-manager \ + ros-melodic-moveit-kinematics \ + ros-melodic-moveit-ros-move-group \ + ros-melodic-ur-msgs \ + ros-melodic-eigen-stl-containers \ + ros-melodic-industrial-robot-simulator \ + ros-melodic-move-base-msgs \ + ros-melodic-srdfdom \ + ros-melodic-joint-state-publisher-gui \ + python-pyside \ + python-lxml \ + python-qt4 \ + python-qt4-dev \ + libshiboken-dev \ + shiboken \ + libpyside-dev \ + libcomedi-dev \ + libmodbus-dev \ + libcanberra-gtk-module \ + libcanberra-gtk0 \ + && rm -rf /var/lib/apt/lists/* + +# Update final image +RUN apt-get update && apt-get -y upgrade + +# Install helping packages +RUN apt-get install -y terminator +RUN apt-get install -y less iputils-ping + + +# Source ros setup.sh +RUN /bin/sh . "/opt/ros/$ROS_DISTRO/setup.bash" + + +# Install python-wstools +RUN apt-get install -y wget +RUN wget http://packages.ros.org/ros.key -O - | sudo apt-key add - +RUN apt-get update +RUN apt-get install -y python-catkin-tools + +# Copy workspace with dependencies created in the previous layer +COPY --from=intermediate /root/dev_ws /root/dev_ws +WORKDIR /root/dev_ws +RUN catkin init && catkin config --extend /opt/ros/melodic && catkin build + +# Add source ros to .bashrc +RUN echo "#ROS\nsource /opt/ros/melodic/setup.bash\nsource /root/dev_ws/devel/setup.bash" >> /root/.bashrc diff --git a/dotfiles/.bashrc b/dotfiles/.bashrc new file mode 100644 index 0000000000000000000000000000000000000000..a302534ec13779311193e6afccdca1ddc4b2ecee --- /dev/null +++ b/dotfiles/.bashrc @@ -0,0 +1,90 @@ +# Add this lines at the top of .bashrc: +[[ $- == *i* ]] && source ~/.local/share/blesh/ble.sh --noattach + +# If not running interactively, don't do anything +case $- in + *i*) ;; + *) return;; +esac + +# Path to the bash it configuration +export BASH_IT="/home/andres/.bash_it" + +# Lock and Load a custom theme file. +# Leave empty to disable theming. +# location /.bash_it/themes/ +export BASH_IT_THEME='bira' + +# (Advanced): Change this to the name of your remote repo if you +# cloned bash-it with a remote other than origin such as `bash-it`. +# export BASH_IT_REMOTE='bash-it' + +# (Advanced): Change this to the name of the main development branch if +# you renamed it or if it was changed for some reason +# export BASH_IT_DEVELOPMENT_BRANCH='master' + +# Your place for hosting Git repos. I use this for private repos. +export GIT_HOSTING='git@git.domain.com' + +# Don't check mail when opening terminal. +unset MAILCHECK + +# Change this to your console based IRC client of choice. +export IRC_CLIENT='irssi' + +# Set this to the command you use for todo.txt-cli +export TODO="t" + +# Set this to false to turn off version control status checking within the prompt for all themes +export SCM_CHECK=true +# Set to actual location of gitstatus directory if installed +#export SCM_GIT_GITSTATUS_DIR="$HOME/gitstatus" +# per default gitstatus uses 2 times as many threads as CPU cores, you can change this here if you must +#export GITSTATUS_NUM_THREADS=8 + +# Set Xterm/screen/Tmux title with only a short hostname. +# Uncomment this (or set SHORT_HOSTNAME to something else), +# Will otherwise fall back on $HOSTNAME. +#export SHORT_HOSTNAME=$(hostname -s) + +# Set Xterm/screen/Tmux title with only a short username. +# Uncomment this (or set SHORT_USER to something else), +# Will otherwise fall back on $USER. +#export SHORT_USER=${USER:0:8} + +# If your theme use command duration, uncomment this to +# enable display of last command duration. +#export BASH_IT_COMMAND_DURATION=true +# You can choose the minimum time in seconds before +# command duration is displayed. +#export COMMAND_DURATION_MIN_SECONDS=1 + +# Set Xterm/screen/Tmux title with shortened command and directory. +# Uncomment this to set. +#export SHORT_TERM_LINE=true + +# Set vcprompt executable path for scm advance info in prompt (demula theme) +# https://github.com/djl/vcprompt +#export VCPROMPT_EXECUTABLE=~/.vcprompt/bin/vcprompt + +# (Advanced): Uncomment this to make Bash-it reload itself automatically +# after enabling or disabling aliases, plugins, and completions. +# export BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE=1 + +# Uncomment this to make Bash-it create alias reload. +# export BASH_IT_RELOAD_LEGACY=1 + +# Load Bash It +source "$BASH_IT"/bash_it.sh + +export PATH=~/apps/:$PATH +export PATH=~/.local/bin:$PATH +source ~/srcs/dotfiles/ros.bash +source ~/srcs/dotfiles/git.bash +source ~/srcs/dotfiles/docker.bash + +[[ ${BLE_VERSION-} ]] && ble-attach + +# Alternative to ble.sh +#bind 'set show-all-if-ambiguous on' +#bind 'TAB:menu-complete' diff --git a/dotfiles/.zshrc b/dotfiles/.zshrc new file mode 100644 index 0000000000000000000000000000000000000000..eb26c157dcc5eea1d73a05d4f36a6d868935596a --- /dev/null +++ b/dotfiles/.zshrc @@ -0,0 +1,125 @@ +#/bin/zsh + +# If you come from bash you might have to change your $PATH. +# export PATH=$HOME/bin:/usr/local/bin:$PATH + +# Path to your oh-my-zsh installation. +export ZSH="/home/inigo/.oh-my-zsh" + +# Set name of the theme to load --- if set to "random", it will +# load a random theme each time oh-my-zsh is loaded, in which case, +# to know which specific one was loaded, run: echo $RANDOM_THEME +# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes +ZSH_THEME="dst" + +# Set list of themes to pick from when loading at random +# Setting this variable when ZSH_THEME=random will cause zsh to load +# a theme from this variable instead of looking in $ZSH/themes/ +# If set to an empty array, this variable will have no effect. +# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" ) + +# Uncomment the following line to use case-sensitive completion. +# CASE_SENSITIVE="true" + +# Uncomment the following line to use hyphen-insensitive completion. +# Case-sensitive completion must be off. _ and - will be interchangeable. +# HYPHEN_INSENSITIVE="true" + +# Uncomment the following line to disable bi-weekly auto-update checks. +# DISABLE_AUTO_UPDATE="true" + +# Uncomment the following line to automatically update without prompting. +# DISABLE_UPDATE_PROMPT="true" + +# Uncomment the following line to change how often to auto-update (in days). +# export UPDATE_ZSH_DAYS=13 + +# Uncomment the following line if pasting URLs and other text is messed up. +# DISABLE_MAGIC_FUNCTIONS="true" + +# Uncomment the following line to disable colors in ls. +# DISABLE_LS_COLORS="true" + +# Uncomment the following line to disable auto-setting terminal title. +# DISABLE_AUTO_TITLE="true" + +# Uncomment the following line to enable command auto-correction. +# ENABLE_CORRECTION="true" + +# Uncomment the following line to display red dots whilst waiting for completion. +# Caution: this setting can cause issues with multiline prompts (zsh 5.7.1 and newer seem to work) +# See https://github.com/ohmyzsh/ohmyzsh/issues/5765 +# COMPLETION_WAITING_DOTS="true" + +# Uncomment the following line if you want to disable marking untracked files +# under VCS as dirty. This makes repository status check for large repositories +# much, much faster. +# DISABLE_UNTRACKED_FILES_DIRTY="true" + +# Uncomment the following line if you want to change the command execution time +# stamp shown in the history command output. +# You can set one of the optional three formats: +# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd" +# or set a custom format using the strftime function format specifications, +# see 'man strftime' for details. +# HIST_STAMPS="mm/dd/yyyy" + +# Would you like to use another custom folder than $ZSH/custom? +# ZSH_CUSTOM=/path/to/new-custom-folder + +# Which plugins would you like to load? +# Standard plugins can be found in $ZSH/plugins/ +# Custom plugins may be added to $ZSH_CUSTOM/plugins/ +# Example format: plugins=(rails git textmate ruby lighthouse) +# Add wisely, as too many plugins slow down shell startup. +plugins=(git history-substring-search zsh-autosuggestions) +autoload compinit && compinit + +source $ZSH/oh-my-zsh.sh + +bindkey "^[[A" history-beginning-search-backward +bindkey "^[[B" history-beginning-search-forward + +ZSH_AUTOSUGGEST_STRATEGY=(completion) #history, completion + +# User configuration + +# export MANPATH="/usr/local/man:$MANPATH" + +# You may need to manually set your language environment +# export LANG=en_US.UTF-8 + +# Preferred editor for local and remote sessions +# if [[ -n $SSH_CONNECTION ]]; then +# export EDITOR='vim' +# else +# export EDITOR='mvim' +# fi + +# Compilation flags +# export ARCHFLAGS="-arch x86_64" + +# Set personal aliases, overriding those provided by oh-my-zsh libs, +# plugins, and themes. Aliases can be placed here, though oh-my-zsh +# users are encouraged to define aliases within the ZSH_CUSTOM folder. +# For a full list of active aliases, run `alias`. +# +# Example aliases +# alias zshconfig="mate ~/.zshrc" +# alias ohmyzsh="mate ~/.oh-my-zsh" + +export PATH=~/.venv/ddeploy_venv/bin:$PATH +export PATH=~/.venv/rocker_venv/bin:$PATH +source /opt/ros/noetic/setup.zsh +if [ -f /.dockerenv ]; then + # echo "I'm inside matrix ;("; + source /ws/devel/setup.zsh +else + # echo "I'm living in real world!"; + source ~/ws/devel/setup.zsh + if xhost +local:docker +fi + +alias build='ddeploy --name ${PWD##*/} --distro melodic -s . -s ./.rosinstall -w 1 --keep-sources' +alias run='rocker --nocleanup --x11 --user --home --git --dev-helpers --ssh --name ${PWD##*/}' +alias dat='if [ "$(docker ps | wc -l)" -eq "2" ]; then docker exec -it "$(docker ps -lq)" bash; else echo "Only works when a single container is running\!"; fi' diff --git a/dotfiles/docker.bash b/dotfiles/docker.bash new file mode 100644 index 0000000000000000000000000000000000000000..9344e92434dce191f31f54e9fe8c0aa7c3b014d9 --- /dev/null +++ b/dotfiles/docker.bash @@ -0,0 +1,35 @@ +# Poining to pip venv +alias rocker="~/.venv/rocker/bin/rocker" +alias ddeploy="~/.venv/ddeploy/bin/ddeploy" + +# docker common commands +alias dim="docker images" +alias drm="docker rm" +alias drmi="docker rmi" + +alias dpsa="docker ps -a" +alias dps="docker ps" + +alias dsp="docker system prune --all" + +function dex() { + docker exec -it $1 ${2:-bash} +} + +function dsr() { + docker stop $1;docker rm $1 +} + +function rdoc() { + rocker --home --user --x11 --ssh --git --name melodic --net host devenv:melodic roscore +} + +function rundoc() { + rocker --home --user --x11 --ssh --git --name melodic devenv:melodic $1 +} + +function drma { + docker rm $(docker ps -a -f status=exited -q) +} + +alias dat="docker exec -it melodic bash" diff --git a/dotfiles/git.bash b/dotfiles/git.bash new file mode 100644 index 0000000000000000000000000000000000000000..e8f58189c14a7adc856613653c2427d7b398c88a --- /dev/null +++ b/dotfiles/git.bash @@ -0,0 +1,47 @@ +# ---------------------------- +# --------- Git -------------- +# ---- Print Terminal -------- +# ---------------------------- + +# CVS CONTROL -- Begin` +# Print nickname for git/hg/bzr/svn version control in CWD` +# Optional $1 of format string for printf, default "(%s) ` +# GET BRANCH +function be_get_branch { + local dir="$PWD" + local vcs + local nick + while [[ "$dir" != "/" ]]; do + for vcs in git hg svn bzr; do + if [[ -d "$dir/.$vcs" ]] && hash "$vcs" &>/dev/null; then + case "$vcs" in + git) __git_ps1 "${1:-(%s) }"; return;; + hg) nick=$(hg branch 2>/dev/null);; + svn) nick=$(svn info 2>/dev/null\ + | grep -e '^Repository Root:'\ + | sed -e 's#.*/##');; + bzr) + local conf="${dir}/.bzr/branch/branch.conf" # normal branch + [[ -f "$conf" ]] && nick=$(grep -E '^nickname =' "$conf" | cut -d' ' -f 3) + conf="${dir}/.bzr/branch/location" # colo/lightweight branch + [[ -z "$nick" ]] && [[ -f "$conf" ]] && nick="$(basename "$(< $conf)")" + [[ -z "$nick" ]] && nick="$(basename "$(readlink -f "$dir")")";; + esac + [[ -n "$nick" ]] && printf "${1:-(%s) }" "$nick" + return 0 + fi + done + dir="$(dirname "$dir")" + done +} +## Add branch to PS1 (based on $PS1 or $1), formatted as $2 +export GIT_PS1_SHOWDIRTYSTATE=yes +#pretty PS1: +export PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\n> ' +export PS1="\$(be_get_branch "$2")${PS1}"; + +# git aliases +alias gco="git checkout" +alias gci="git commit" +alias gst="git status" +alias gg="git log --oneline --decorate --graph --all" diff --git a/dotfiles/ros.bash b/dotfiles/ros.bash new file mode 100644 index 0000000000000000000000000000000000000000..4adfe149453dc81d826aa55e59746f87610d2eac --- /dev/null +++ b/dotfiles/ros.bash @@ -0,0 +1,37 @@ +################################################################### +# ROS +################################################################### + +alias sourcemelodic='source /opt/ros/melodic/setup.bash' +alias sourcenoetic='source /opt/ros/noetic/setup.bash' + +# Source the current workspace, replacing any previous repo sourcing commands +alias sourcethis='unset CMAKE_PREFIX_PATH;source ./devel/setup.bash' + +# Automatic return to your last-sourced catkin root directory +alias roshome='cd $(echo $CMAKE_PREFIX_PATH | cut -d ':' -f 1);cd ..' + +# Automatic catkin_make from any folder (use in conjunction with the above one-liner) +cb() { + (roshome && exec catkin build --summarize "$@") +} + +# Clean workspace (delete the generated folders, then catkin build) +alias cbclean='(roshome && rm -rf build devel install && cb)' + +# Change the format of ROS console output. This way you can get rid of the annoying timestamp. +# The total list of items you can add to this format string is available here. As of the time this article was written, the options were: +# severity message time thread logger file line function +export ROSCONSOLE_FORMAT='[${severity}] ${message}' + +# Export a package config, helps with finding some manually installed packages +export PKG_CONFIG_PATH=/home/andres/.local/lib/pkgconfig/:$PKG_CONFIG_PATH + +memaster() { + export ROS_MASTER_URI=http://localhost:11311/ + export ROS_IP=127.0.0.1 +} + +cib(){ + catkin init && catkin config --extend /opt/ros/melodic && catkin build +} diff --git a/notes/MP_chat b/notes/MP_chat new file mode 100644 index 0000000000000000000000000000000000000000..38a6f1a807073c03fda9cdf9a5afced3cd26c0f7 --- /dev/null +++ b/notes/MP_chat @@ -0,0 +1,75 @@ +Two useful tools: + +- Rocker to launch containerds and to develop inside them. + + https://github.com/osrf/rocker + + + Rocker is a small (smart) tool that allows to launch containers with extra options, easier than docker alone, e.g: + +rocker --home --user ros:melodic bash + +This launches a container from the image ros:melodic, mounting your home folder and seting up an user using your UID/GID (This allows to edit files inside the container, then outside at the host, the files remain edited by yourself) + +This is also posible to achieve using only docker, but rocker make the task easier. + +An useful idea is ti set up an alias in order to launch other bash instances inside the same container, in order to get more terminals in the same environment. + +One drawback using rocker (docker) is, all dependecies of the software and tools must be installed everytime a container is launched for first time, this is time consuming. + +In order to solve this issue, there is a second tool: ddeploy + + https://git.code.tecnalia.com/tecnalia_robotics/flexbotics/flexbotics_utils/ddeploy + +This is a simple script that allows to deploy applications as docker images. + +ddeploy take the application sources to be container-ized, and automaticaly build an image with all dependencies installed and the provided sources compiled and installed. + +Therefore, in order to work in the project XYZ, the first step is to build a custom image for the project using ddeploy, and then, you can to launch a "working" container from the built imagen using rocker. + +Both rocker and ddeploy could be installed in their own Python venvs. + +Python venvs is a Python tool to build virtual environments and to allow installing inside them projects with all dependencies solved, without need to modify the Python base set up. + +python3 -m venv ddeploy +git clone git@git.code.tecnalia.com:tecnalia_robotics/flexbotics/flexbotics_utils/ddeploy.git +git checkout current-folder-fix +source bin/activate +pip install -e src/ddeploy +deactivate +./bin/ddeploy --name cosa --distro melodic -s git+ssh://github.com/ros/std_msgs.git#kinetic-devel + +git clone https://github.com/ros/std_msgs.git +~/.venv/ddeploy/bin/ddeploy --name mensajes --distro melodic -s std_msgs + +python3 -m venv ddeploy + +rocker --home --user --x11 --nvidia --ssh --git osrf/ros:melodic-desktop-full bash + +rocker --home --user --x11 --nvidia --ssh --git ubuntu:bionic bash + + +Executing command: +docker run -it -v /etc/gitconfig:/etc/gitconfig:ro -v /home/andres/.gitconfig:/home/None/.gitconfig:ro -v /home/andres:/home/andres --gpus all -e SSH_AUTH_SOCK -v /run/user/1000/keyring/ssh:/run/user/1000/keyring/ssh -e DISPLAY -e TERM -e QT_X11_NO_MITSHM=1 -e XAUTHORITY=/tmp/.dockersd81ncol.xauth -v /tmp/.dockersd81ncol.xauth:/tmp/.dockersd81ncol.xauth -v /tmp/.X11-unix:/tmp/.X11-unix -v /etc/localtime:/etc/localtime:ro 5ba9d44fd173 bash + + +sudo usermod -aG docker USER.NAME +# docker login tecnalia-robotics-docker.artifact.tecnalia.com +git lfs install +# git config --global credential.helper 'cache --timeout=3600' +rosdep update +sudo apt update + +// # Lanzar imagen con parámetros básicos de rocker +rocker --home --user --x11 --nvidia --ssh --git devenv:melodic bash + +rocker --mp-dev-helpers --mp-dind-host --mp-en-us-locale --x11 --nvidia --home --user --ssh --git devenv:melodic bash + + + +kawada_lab_application.ddeploy.yaml + +ddeploy --name dummy:noetic --distro noetic -s git@git.code.tecnalia.com:tecnalia_robotics/flexbotics/flexbotics_test/dummy_application.git#noetic-devel -s dummy_application/.rosinstall -w 1 +Repository type 'git@git.code.tecnalia.com' is not supported + + diff --git a/notes/UE_chat b/notes/UE_chat new file mode 100644 index 0000000000000000000000000000000000000000..f68f1d49e44eddc40a24991f5ab4f67aad900a7b --- /dev/null +++ b/notes/UE_chat @@ -0,0 +1,24 @@ + El comando para hacer el build tiene que ser el siguiente + + docker build --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)" -t nombre_imagen . + + como ves añade el build-arg para guardar la llave ssh + + Si lo pruebas y te convence estaría bien añadirlo nuestro repo de gitlab de kawada junto con el readme que creaste + + así el siguiente que quiera usar este paquete tardará menos que nosotros + + +docker run -it --name melodic \ + --privileged \ + --env=NVIDIA_VISIBLE_DEVICES=all \ + --env=NVIDIA_DRIVER_CAPABILITIES=all \ + --env=DISPLAY \ + --env=QT_X11_NO_MITSHM=1 \ + -v /tmp/.X11-unix:/tmp/.X11-unix \ + --runtime=nvidia \ + --device /dev/snd \ + -e NVIDIA_VISIBLE_DEVICES=0 \ + devenv:melodic /bin/bash + +