layout: true
--- class: center, middle name: main_title # ROS-I Academy Training ### ROS 2 Filesystem --- ## Overview - What is a package? - How does the structure of workspace look like?  - How to create workspace and packages? --- ## Package - The software in ROS 2 is organized into **packages** - The smallest build part in ROS 2 - Dedicated to one functionality, e.g. : - Hardware driver - Algorithm - Visualization tool - Library ... - Packages can be grouped to metapackages (e.g [navigation2](https://github.com/ros-planning/navigation2/blob/main/navigation2/)) - references one or more related packages - only contain execution dependencies - beneficial for release and version control --- ## Package install options | Debian Package | Source Repositories | | ---------------| ------------------- | | Automatic installation | "Latest" code | | Stable versions | Manual compilation | | Prebuilt binaries | Allows code adjustments | --- ## Package installation (Debian) - Debian: ``` $ sudo apt install ros-
-package-name ROS ROS distribution package name ``` example: ``$ sudo apt install ros-jazzy-nav2-core`` **!** package_name: **nav2_core** --> install:ros-jazzy-**nav2-core** - Automatic installation - Location : /opt/ros/`
`/... - installs all required dependencies --- ## Package installation (Source) - Download from source (usually git): - Do it in your source space (e.g. ~/devel_ws/src): `$ git clone github_link` - example: `$ git clone https://github.com/ros/ros_tutorials.git -b jazzy ` - Install all dependencies of package(s) - **rosdep** : download and install dependencies required by ROS packages. ```bash $ rosdep install --from-paths src --ignore-src --rosdistro jazzy -y ``` - Manage multiple version-control packages: vcstool - A version control system (VCS) tool - A command-line tool to make working with multiple repositories easier. For example, importing the ROS 2 Jazzy source repositories into a separate workspace: ```bash $ mkdir -p ~/jazzy_source_ws/src $ cd ~/jazzy_source_ws $ wget https://raw.githubusercontent.com/ros2/ros2/jazzy/ros2.repos $ vcs import src < ros2.repos ``` --- name: two_columns ## Package content - Folder structure - Python package ``` $ ros2 pkg create --build-type ament_python --dependencies [deps] --node-name my_node my_package ``` .cols[ .fifty[
] .fifty[ Files: * setup.cfg: tell setuptools to put your executables in lib * setup.py: the build script for setuptools ] ] --- ## Package content - Folder structure - CMake package `$ ros2 pkg create --build-type ament_cmake --dependencies [deps] --node-name my_node my_package `  --- ### Package content - `package.xml`  --- ### Package content - `package.xml` - Meta information about the package - Lists dependencies of a package  --- ### Package content - `package.xml` #### Dependencies - Dependencies can be __Other ROS packages__ and __System libraries__ (e.g. `Boost`) - Dependencies: - `
`: Required for build tools - `
`: Required at execution-time (e.g. Python script) - `
`: Required for building (e.g. rclcpp, ament_cmake) - `
` : Required for running unit tests - `
` : If exported header dependes on other ones - `
` : All-in-one (`
`, `
` and `
`) --- ### Package content - `setup.py` (Python) Example (**turtlebot_teleop** package): package path: ~/devel_src/src/turtlebot/turtlebot_teleop .cols[ .fifty[  ] .fifty[ ``` setup( ... entry_points={ 'console_scripts': [ 'teleop_keyboard = turtlebot3_teleop.script.teleop_keyboard:main' ], }, ) ``` - install the executable **teleop_keyboard** to `devel_ws/install/turtlebot3_teleop/lib/ turtlebot3_teleop/` ] ] --- ### Package content - CMakeLists.txt (CMake package) Example:  - Defines build rules. For example: * Declare compilation for executables * How to resolve header files and library references - Mostly CMake, plus ament-specific ones --- CMakeLists.txt Example:  --- ### Colcon - a universal build tool - Build system: Operates on a single package - Build tool: Operates on a set of packages
Example: ``` # saves you from having to rebuild every time you tweak python scripts $ colcon build --symlink-install # builds the package you want $ colcon build --packages-up-to
``` **Helpful documentation: https://colcon.readthedocs.io/en/released/user/quick-start.html** --- ### Lint tools Lint tools : Static checking of Python or C++ source code for errors and standards compliance. - For Python package - package.xml ```
ament_copyright
ament_flake8
ament_pep257
``` - For CMake package - package.xml ```
ament_lint_auto
ament_lint_common
``` `ament_lint_auto`: ament_cmake_copyright, ament_cmake_cppcheck,ament_cmake_flake8, ament_cmake_lint_cmake, ament_cmake_pep257, ament_xmllint `ament_lint_common`: ament_clang_format, ament_clang_tidy, ament_cmake_clang_format, ament_cmake_clang_tidy --- ## Workspace - A directory containing ROS 2 packages with a particular structure - Structure  *__Colcon__* creats __build/__ __install/__ __log/__ as peers of the src/ --- ## Workspace #### Used for Development * Source Space (`src/`): Contains the source version of packages * Build Space (`build/`): Where CMake is invoked and generates artifacts #### Ready for Installation * Install Space (`install/`): Self-contained package ready for release * Package-structure like in /opt/ros/`
` --- ### Environment setup files - Setup file generated at initialization of a workspace: setup.bash, setup.zsh ... - Source your ROS 2 installation workspace before using ROS 2 ``$ source /opt/ros/
/setup.bash `` - Source your workspace: ``$ source
/install/setup.bash `` ** ---> ROS can find and use any resource inside the ROS environment** --- ### Compile workspace Example: * Go to your workspace: `$ cd ~/devel_ws` * Source ROS 2 installation workspace `$ source /opt/ros/jazzy/setup.bash ` * Install all dependencies of package(s) `rosdep` : download and install dependencies required by ROS packages. - For the first time, you need to run: ```bash $ sudo rosdep init $ rosdep update ``` * Install all dependencies of package(s) * Then you can use: ```bash $ rosdep install --from-paths src --ignore-src --rosdistro jazzy -y ``` * Compile the workspace ```bash $ colcon build --symlink-install ``` - After `colcon build` in your workspace, source ROS env : `$ source
/install/setup.bash` (including /opt/ros/`
`/setup.bash) --- ## Any Questions? 