Deploying a ROS 2 Face Detection Application Using Robotair⿻
Estimated time to read: 11 minutes
Welcome to this tutorial! In this guide, we'll walk you through deploying a ROS2 application that uses webcamera to detect facial landmarks. We'll leverage Robotair, an all-in-one DevOps platform to build our CI/CD pipeline, containerize our application, and deploy updates over-the-air (OTA) to robots anywhere in the world and also mointor the deployment.
As a robotics engineer, your time is best spent on innovation and not building deployment infrastructure. With Robotair, you can trust that all your deployment needs are handled, so you can focus on what truly matters: bringing your ideas to life.
By the end of this tutorial, you'll have your ROS2 application running on your robot/laptop, with the ability to deploy updates seamlessly using Robotair.
Table of Contents⿻
- Introduction
- Prerequisites
- Setting Up Your ROS2 Application
- Creating a CI/CD Pipeline and Containerizing with Robotair
- Onboarding Your Robot to Robotair
- Creating a Robot Software Deployment with Robotair
- Deploying Updates OTA
- Testing the Application
- Conclusion
Introduction⿻
Robotair simplifies and automates the management of your robotics projects, from CI/CD pipelines to over-the-air updates and performance monitoring. It allows you to accelerate development, reduce deployment risks, and maintain complete control over your robots.
In this tutorial, we'll focus on the process after the ROS2 package is created, guiding you through:
- Generating a CI/CD pipeline and containerizing your application with Robotair.
- Onboarding your robot to Robotair for remote management.
- Creating a deployment for your application.
- Deploying updates over-the-air (OTA) to your robot.
Prerequisites⿻
Before we begin, ensure you have the following:
- ROS2 Application: A ROS2 package that utilizes your computer's camera to detect face. You can fork the repo from our GitHub.
- Robotair Account: Sign up for an account on Robotair.
- Git Repository: A GitHub or GitLab repository containing your ROS2 application code.
- Container Registry: Access to a container registry (e.g., DockerHub) for storing your Docker images.
- Robot: A robot/laptop with Linux based OS, internet connectivity and SSH access.
- Camera: A camera connected to a robot/laptop.
Setting Up Your ROS2 Application⿻
While this tutorial focuses on the deployment process, ensure your ROS2 application follows:
- Proper Structure: Follows the standard ROS2 package structure.
- Version Control: Hosted in a Git repository (GitHub or GitLab).
- Tested Locally: Ensure it runs correctly on your development machine.
- Deployment Guidelines: To ensure robust and scalable robot deployments, adhere to the best practices.
Creating a CI/CD Pipeline and Containerizing with Robotair⿻
In this section, we'll use Robotair to automate the packaging and building of your ROS2 application using Docker.
Step 1: Prepare Your Repository⿻
-
Clone Your Repository:
-
Create a New Branch:
Step 2: Onboard to Robotair Build⿻
-
Log In to Robotair:
- Navigate to Robotair and log in to your account.
- Go to the Builds section and click on "Create New Build".
-
Configure Your Build:
- Name Your Build: Use a meaningful name (e.g.,
face-detection-app
). - Select ROS Version: Choose the ROS2 distribution your application needs (e.g., Foxy, Galactic).
- Click Next.
- Name Your Build: Use a meaningful name (e.g.,
-
Choose Build Requirements:
- Base Image: Use the default OSRF image or specify a custom one if needed.
- Compiler: Select your preferred compiler.
- Execution Command: Specify the command to run your application when the container starts, e.g.:
-
Add Dependencies:
- System Dependencies: List any system packages your application requires (these should be in your
package.xml
). - Python Dependencies: Provide path to the
requirements.txt
file. Generate one by running:
- System Dependencies: List any system packages your application requires (these should be in your
-
Add Deploy Keys for Private Repositories (if applicable):
- If your application depends on private repositories, add SSH deploy keys to access them.
- Hostname: Base URL of your Git service (e.g.,
https://github.com/
). - Secret Name: Name of the repository secret holding the SSH deploy key (e.g.,
SSH_KEYS
).
-
Add Startup Commands:
- Provide any startup commands or scripts your application needs. You can skip this if you are using docker compose to deploy the application.
Step 3: Packaging Your Application⿻
-
Configure Your Image:
- Image Name: Set the name and tag for your Docker image (e.g.,
username/face-detection-app:latest
). - Architecture: Choose
amd64
for most desktop CPUs orarm64
for ARM-based robots.
- Image Name: Set the name and tag for your Docker image (e.g.,
-
Configure Container Registry:
- Registry URL: Default is DockerHub (
https://index.docker.io/v1/
). - Username: Your container registry username.
- Password Secret Name: The name of the CI/CD pipeline secret holding your registry password (e.g.,
REGISTRY_PASSWORD
).
- Registry URL: Default is DockerHub (
Step 4: Generate CI Files for Your Repository⿻
-
Finalize and Preview:
- Review your build configuration.
- Click Create to generate the CI files.
-
Download CI Files:
- Download the CI configuration file for your Git service:
- GitHub: Download
main.yaml
(place in.github/workflows/
). - GitLab: Download
gitlab-ci.yml
, rename to.gitlab-ci.yml
, and palce in root. - Download the
Rigelfile
and place it in the root of your repository.
Step 5: Integrate the CI Files with Your Repository⿻
-
Add CI Files to Your Repository:
- Place the CI configuration file and
Rigelfile
in your repository as per instructions.
- Place the CI configuration file and
-
Set Secrets in Your Git Service:
- Registry Password:
- Add a secret named
REGISTRY_PASSWORD
with your container registry password. - For GitHub: Go to
Settings > Secrets and variables > Actions > New repository secret
. -
For GitLab: Go to
Settings > CI/CD > Variables
. -
SSH Deploy Keys (if using private repositories):
-
GitHub: Add a secret named
SSH_KEYS
containing your SSH private key. - GitLab: Add a variable in
Settings > CI/CD > Variables
.
-
Commit and Push Changes:
-
Merge Changes:
- Create a Pull Request (GitHub) or Merge Request (GitLab) to merge the
ci/robotair
branch into your main branch. - Once merged, the CI pipeline will run automatically.
- Create a Pull Request (GitHub) or Merge Request (GitLab) to merge the
Step 6: Monitor Build Pipeline⿻
- Check the CI/CD section in your Git service to monitor the build process.
- Upon successful completion, your Docker image will be pushed to your container registry.
Onboarding Your Robot to Robotair⿻
To deploy your application OTA, your robot needs to be connected to Robotair.
Step 1: Log In to Robotair⿻
- Go to the Robots section in your Robotair dashboard.
Step 2: Create a New Robot⿻
-
Click on "Create Robot".
-
Enter Robot Details:
- Provide a name for your robot (e.g.,
my-robot
). - Click Save.
- Provide a name for your robot (e.g.,
Step 3: Connect Your Robot⿻
-
Copy the Installation Command:
- After creating the robot, you'll see a command to install the Robotair agent.
- The command looks like:
-
Run the Command on Your Robot:
- SSH into your robot's terminal.
- Run the copied command.
- This will install the Robotair agent and securely connect your robot to the platform.
Step 4: Verify Connection⿻
Back in the Robotair dashboard, ensure your robot appears as Online in the Robots section.
Creating a Robot Software Deployment with Robotair⿻
Now that your robot is connected, you'll create a deployment that specifies which services (Docker containers) should run on your robot.
Step 1: Navigate to the Deployments Section⿻
- In Robotair, go to the Deployments section.
- Click on "Create Deployment".
Step 2: Create a Deployment⿻
-
Provide Deployment Details:
- Name: Use a meaningful name and version (e.g.,
face-detection-deployment-0.0.1
).
- Name: Use a meaningful name and version (e.g.,
-
Choose a Docker Compose File:
-
Create Docker Compose File:
-
Select the option to upload a Docker Compose file to Robotair.
-
-
Review and Create Deployment:
- After uploading, add the Registry secrets ( Registry where your image is stored ). You can skip this if you have a public image registry
- Review the deployment details.
- Click Create.
Step 3: Assign Deployment to Your Robot⿻
-
Assign Robots:
- In the deployment overview, click on "Assign Robots".
- Select your robot from the list.
- Choose the services to deploy (e.g.,
face-detection-service
).
-
Deploy to Robot:
- Click on "Deploy" to start the OTA deployment.
- Confirm the deployment.
Step 4: Monitor Deployment⿻
- In the Robotair dashboard, monitor the deployment status.
- Once deployment is complete, the services will be running on your robot.
Deploying Updates OTA⿻
To deploy updates to your application:
-
Make Changes to Your Application:
- Update your code in your local repository.
-
Push Changes to Repository:
- Commit and push changes to your branch and create a PR/MR with your main branch.
- The CI/CD pipeline will run automatically, building a new Docker image and pushing it to the registry.
-
Update Deployment:
- In Robotair, create a new deployment or update the existing one with the new image tag.
-
Deploy to Robot:
- Assign the updated deployment to your robot.
- Click Deploy to send the update OTA.
Testing the Application⿻
After deployment, verify that your application is running correctly on your robot.
-
Check Service Status:
- In the Robotair dashboard, ensure the service is running without errors.
-
Access Logs:
- View logs to check for any issues.
- Use
docker logs
on the robot if necessary.
-
Verify Face Detection:
- Ensure the robot's camera is functioning.
- Test the face detection by showing a face to the camera and observing the outputs.
Conclusion⿻
You've successfully deployed a ROS2 face detection application using Robotair. You've learned how to:
- Containerize your ROS2 application.
- Set up a CI/CD pipeline with Robotair.
- Onboard your robot to Robotair.
- Create deployments and deploy updates OTA.
With Robotair, you can streamline your robotics development workflow, automate deployments, and manage your robots remotely with ease.