Skip to content

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

  1. Introduction
  2. Prerequisites
  3. Setting Up Your ROS2 Application
  4. Creating a CI/CD Pipeline and Containerizing with Robotair
  5. Onboarding Your Robot to Robotair
  6. Creating a Robot Software Deployment with Robotair
  7. Deploying Updates OTA
  8. Testing the Application
  9. 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

  1. Clone Your Repository:

    git clone <your-repo-url>
    
  2. Create a New Branch:

    git checkout -b ci/robotair
    

Step 2: Onboard to Robotair Build

  1. Log In to Robotair:

    • Navigate to Robotair and log in to your account.
    • Go to the Builds section and click on "Create New Build".
  2. 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.
  3. 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.:
    ros2 launch <your_package> <your_launch_file.launch.py>
    
  4. 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:
    pip freeze > requirements.txt
    
  5. 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).
  6. 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

  1. 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 or arm64 for ARM-based robots.
  2. 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).

Step 4: Generate CI Files for Your Repository

  1. Finalize and Preview:

    • Review your build configuration.
    • Click Create to generate the CI files.
  2. 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

  1. Add CI Files to Your Repository:

    • Place the CI configuration file and Rigelfile in your repository as per instructions.
  2. 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.
  3. Commit and Push Changes:

    git add .
    git commit -m "ci: Added Robotair CI configuration"
    git push origin ci/robotair
    
  4. 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.

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

  1. Click on "Create Robot".

  2. Enter Robot Details:

    • Provide a name for your robot (e.g., my-robot).
    • Click Save.

Step 3: Connect Your Robot

  1. Copy the Installation Command:

    • After creating the robot, you'll see a command to install the Robotair agent.
    • The command looks like:
    curl -sSL https://agent.robotair.io/install.sh | sudo bash -s -- -k <your-secret-key>
    
  2. 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

  1. Provide Deployment Details:

    • Name: Use a meaningful name and version (e.g., face-detection-deployment-0.0.1).
  2. Choose a Docker Compose File:

    • Create Docker Compose File:

    • Select the option to upload a Docker Compose file to Robotair.

  3. 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

  1. 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).
  2. 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:

  1. Make Changes to Your Application:

    • Update your code in your local repository.
  2. 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.
  3. Update Deployment:

    • In Robotair, create a new deployment or update the existing one with the new image tag.
  4. 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.

  1. Check Service Status:

    • In the Robotair dashboard, ensure the service is running without errors.
  2. Access Logs:

    • View logs to check for any issues.
    • Use docker logs on the robot if necessary.
  3. 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.