Example of generic package development of DV pipeline packages for ROS2 Jazzy. You should create a new repository from this template (by clicking Use this template → Create a new repository) and replace the content with your own package, source code, and documentation.
For this new CI Branch for pre-commits
./setupenv.shIf you just want to check C++ Code Correctness for modified C++ files before adding to commit =>
./tidy-code.sh- Our final pipeline will be constructed using Docker-compose to launch all individual packages. This will be based on the Dockerfiles from each package repo.
- ROS2 uses a decentralized architecture with DDS (Data Distribution Service), so no separate ROS master is needed.
- All packages will firstly be built through an entrypoint script using
colcon buildand then launched with a launch file using the command (CMD) instruction in the Docker-compose file.
-
Repository name ending with "_pkg".
-
Main branch always in a deployable state.
-
ROS2 package must be runnable standalone from other ROS nodes without the package nodes crashing.
-
Document what messages and message types are used in the package in the ROS messages markdown file. This is to make it easier to understand the inputs and outputs of the package and to make it easier to integrate with other packages.
-
Dockerfile installs all package dependencies and sets up the workspace directory in a Docker container.
-
Working ROS2 package that can be built with
colcon buildusing docker-entrypoint.sh, this requires having both package.xml, CMakeLists.txt, as well as a working launch.py file in the launch directory (of course, rename this to a suitable name of your package). -
Docker-compose file builds and launches the package with a launch file specified in the launch directory. The compose uses
network_mode: hostfor ROS2 DDS communication. -
Read more about our Software Development Guidelines on the KTHFS wiki.
-
Avoid hard-coding variables and instead utilize configuration files defined in the configuration folder.
-
Incorporating unit testing with github actions to automatically run tests on pull requests.
-
Visualize codebase by adding
in the README. Note: this diagram is automatically generated on push to the main branch as defined in the Github Action file.
This section provides step-by-step instructions on how to create a new ROS2 package and integrate it with Docker using this template.
-
Choose a suitable Docker base image based on your package's requirements. In many cases, the 'ros-base' image is sufficient. For ROS2 Jazzy, use ros:jazzy-ros-base-noble. For packages related to machine learning, consider the dustynv jetpack containers. Ensure that all the package dependencies are installed and set up in the Dockerfile. Also, remember to adjust the
ROS_DISTROvariables in accordance with the ROS distribution you're using. -
Ensure that the ROS2 package is complete and can be built using
colcon build. This entails adding source code, primarily in C++, to thesrcdirectory and incorporating Python scripts in thescriptsdirectory. Additionally, modifications should be made to package.xml, CMakeLists.txt, docker-entrypoint.sh, and launch.py (rename this launch file to a suitable name for your package). Refer to the provided files and the ROS2 documentation for guidance. -
Update the Docker-compose file. Ensure that the service name aligns with the package's name and modify the launch command to the correct package and launch file name. Also, set the
ROS_DOMAIN_IDappropriately for your environment. Additionally, if required, include extra mounted volumes in thesrcdirectory or adjust other arguments as appropriate. -
Test the package compose file using
docker compose up. Make sure that the package is launched correctly, for example withdocker exec ros_container bash -c "source /ws/install/setup.bash && ros2 node list". See Usage for further guidance. This testing is incorporated in the CI workflow. -
Add a GitHub token to the repository's GitHub secrets. This token should come from an account with access to all submodules utilized in the package build.
The docker-compose.yml includes a noVNC service that enables GUI support through X11 forwarding. The service is based on the theasp/novnc image. The service allows graphical applications to be run in your web browser by connecting to the container's VNC server (default http://localhost:8080/vnc.html).
For example, you might want to run rviz2 in your ROS2 container, this solution allows you to do so. To do this, you need to:
-
Enter the container:
docker exec -it <container id or name> /bin/bash
-
Run
rviz2(or any other GUI application):rviz2
-
Open a web browser and navigate to
http://localhost:8080/vnc.html.
You can now interact with the GUI application in your browser for development or for other purposes.
This section provides step-by-step instructions on how to test and deploy the torque_vectoring_pkg using Docker.
-
Ensure that the Dockerfile, docker-compose, launch files configuration and environment variables are set up as per the package requirements.
-
Make sure you have Docker, or another container runtime, along with Docker Compose, installed on your machine. If not, you can get them from here.
-
Clone the Repository:
git clone <your-package-repo-url> cd <your-package-repo-name>
-
Build the Docker Image:
docker compose build
-
Run the Package:
docker compose up
This will run your package and necessary docker containers as described in the
docker-compose.ymlfile. Your ROS2 package should now be up and running within the Docker environment. If this command is run beforedocker compose build, it will automatically perform the building process as well. -
To interact or debug within the running container:
docker exec -it <container id or name> /bin/bash
To get the name and id of all containers, run:
docker ps
To list all containers, including those that have exited, run:
docker ps -a
-
To stop the running services:
docker compose stop
-
To stop and remove the containers:
docker compose down
-
If you wish to remove the built images to free up space:
docker rmi <image-name>
After launching the package, it's essential to validate its functionality:
-
Check Package Health:
docker exec container_name bash -c "source /ws/install/setup.bash && ros2 node list"
This should list the nodes exposed by your ROS2 package, indicating they're running correctly.
-
Check Topics:
docker exec container_name bash -c "source /ws/install/setup.bash && ros2 topic list"
-
If unit tests have been integrated, run them to ensure package integrity:
docker exec container_name bash -c "source /ws/install/setup.bash && colcon test"
To ensure that the package is functional and can be built successfully, a GitHub CI workflow is included in the repository. This workflow is triggered whenever a pull request is opened, updated, or reopened. The workflow is defined in the .github/workflows/docker-ci.yml file. Below is a brief description of the workflow.
Trigger:
- The CI workflow gets initiated whenever a pull request (PR) is:
- Opened
- Updated (synchronized)
- Reopened
Jobs:
-
Check for Essential Files:
- Ensure the presence of
Dockerfile,docker-compose.yml, anddocker-entrypoint.shin the repository.
- Ensure the presence of
-
Docker Operations:
- After verifying essential files, execute Docker Compose.
-
Container Health Check:
- Wait and check if the Docker container is running, with a maximum wait time defined by
COMPOSE_UP_TIMEOUT_SECONDS.
- Wait and check if the Docker container is running, with a maximum wait time defined by
-
Build Validation:
- After a short initial wait (5 seconds), inspect the Docker container for a sentinel file named
.CONTAINER_INITIALIZED_PLACEHOLDERindicating build completion. The maximum wait time for this operation isCOLCON_BUILD_TIMEOUT_SECONDS.
- After a short initial wait (5 seconds), inspect the Docker container for a sentinel file named
-
ROS2 Node Verification:
- Confirm the health and operation of ROS2 nodes by checking for expected nodes using:
docker exec container_name bash -c "source /ws/install/setup.bash && ros2 node list"
If you encounter difficulties, the logs generated during the Docker-compose build and execution phases are your best first reference. These logs can provide insights into issues such as missing dependencies or other common errors.
Frequently observed challenges include:
- Launch command in Docker compose not set up correctly to match package name and launch file name.
- Failure to update the
CMakeLists.txtwith the appropriate package name. - Discrepancies between the package name specified in the launch command and those in
package.xmlor the launch file. - Not updating the variables for the relevant ROS distribution in both the
Dockerfileanddocker-entrypoint.sh. - DDS communication issues. Check the
ROS_DOMAIN_IDenvironment variable and network configuration. - FS_msgs or other submodule not initialized.
git submodule update --init --recursive.
-
ROS2 (Robot Operating System 2):
-
Colcon Build System:
-
Docker:
-
Docker Compose:
-
Github Actions:
-
CI guide -Wiki Page Regarding CI