Difference between revisions of "Advantech Robotic Suite/Container/Develop ROS Container"
| (3 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
= Develop ROS Container = | = Develop ROS Container = | ||
| − | Develop ROS container image that assists developers in building its own ROS containerized applications. | + | Develop ROS(foxy or humble) container image that assists developers in building its own ROS containerized applications. |
== How To == | == How To == | ||
| Line 7: | Line 7: | ||
=== Start docker container === | === Start docker container === | ||
| − | '''Step1: Launch the docker container of dev-ros2- | + | '''Step1: Launch the docker container of dev-ros2-<ROS_DISTRO>''' |
| − | < | + | <pre> |
$ cd /usr/local/Advantech/ros/container/docker | $ cd /usr/local/Advantech/ros/container/docker | ||
| − | $ ./launch.sh dev-ros2- | + | $ ./launch.sh dev-ros2-<ROS_DISTRO> |
| − | </ | + | </pre> |
'''Step2: Accessing the container for development and debugging''' | '''Step2: Accessing the container for development and debugging''' | ||
| − | < | + | <pre> |
| − | $ docker exec -it dev-ros2- | + | $ docker exec -it dev-ros2-<ROS_DISTRO> bash |
| − | </ | + | </pre> |
| | ||
| Line 33: | Line 33: | ||
=== Stop docker container === | === Stop docker container === | ||
| − | < | + | <pre> |
$ cd /usr/local/Advantech/ros/container/docker | $ cd /usr/local/Advantech/ros/container/docker | ||
| − | $ ./stop.sh dev-ros2- | + | $ ./stop.sh dev-ros2-<ROS_DISTRO> |
| − | </ | + | </pre> |
| | ||
| Line 46: | Line 46: | ||
=== Step1: Define a Dockerfile === | === Step1: Define a Dockerfile === | ||
| − | Create a file called "Dockerfile" that specifies the instructions for building the container based on '''dev-ros2- | + | Create a file called "Dockerfile" that specifies the instructions for building the container based on '''dev-ros2-<ROS_DISTRO>'''. This file includes details such as the base image, dependencies, environment variables, and commands to run inside the container. |
| − | <pre>FROM advigw/dev-ros2- | + | <pre>FROM advigw/dev-ros2-<ROS_DISTRO>:1.0.0 |
# 1. Copy prerequisites of your application into the container | # 1. Copy prerequisites of your application into the container | ||
| Line 64: | Line 64: | ||
Use the Docker command-line to build the Docker image based on the Dockerfile. This process involves pulling the necessary base image, executing the instructions in the Dockerfile, and creating a layered image with all the specified components. | Use the Docker command-line to build the Docker image based on the Dockerfile. This process involves pulling the necessary base image, executing the instructions in the Dockerfile, and creating a layered image with all the specified components. | ||
| − | < | + | <pre> |
$ docker build -t ros-example -f Dockerfile . | $ docker build -t ros-example -f Dockerfile . | ||
| − | </ | + | </pre> |
=== Step3: Define the Docker Compose services === | === Step3: Define the Docker Compose services === | ||
Create a file called "docker-compose.yml", in the Docker Compose file, define the services, their image references, and any necessary configurations such as environment variables, port mappings, volume bindings, etc. Use the syntax provided by Docker Compose to define each service. | Create a file called "docker-compose.yml", in the Docker Compose file, define the services, their image references, and any necessary configurations such as environment variables, port mappings, volume bindings, etc. Use the syntax provided by Docker Compose to define each service. | ||
| − | <pre>version: '2. | + | <pre>version: '2.1' |
services: | services: | ||
| Line 94: | Line 94: | ||
Execute the docker-compose up command in the directory where the Docker Compose file is located. This command will start the containers as defined in the Compose file.<br/> <span style="color:red;">Note: When using the docker-compose command, please avoid using 'sudo' if you need to use the ROS_DOMAIN_ID environment variable. Otherwise, the variable may not be found during execution.</span> | Execute the docker-compose up command in the directory where the Docker Compose file is located. This command will start the containers as defined in the Compose file.<br/> <span style="color:red;">Note: When using the docker-compose command, please avoid using 'sudo' if you need to use the ROS_DOMAIN_ID environment variable. Otherwise, the variable may not be found during execution.</span> | ||
| − | < | + | <pre> |
$ docker-compose -f docker-compose.yml up -d | $ docker-compose -f docker-compose.yml up -d | ||
| − | </ | + | </pre> |
=== Step5: Test and validate === | === Step5: Test and validate === | ||
Open a new interactive bash shell within the container. | Open a new interactive bash shell within the container. | ||
| − | < | + | <pre> |
$ docker exec -it ros-example bash | $ docker exec -it ros-example bash | ||
| − | </ | + | </pre> |
Then test [[#Examples|ROS2 Example]] and your applications in container. | Then test [[#Examples|ROS2 Example]] and your applications in container. | ||
Latest revision as of 04:22, 25 June 2025
Develop ROS Container
Develop ROS(foxy or humble) container image that assists developers in building its own ROS containerized applications.
How To
Start docker container
Step1: Launch the docker container of dev-ros2-<ROS_DISTRO>
$ cd /usr/local/Advantech/ros/container/docker $ ./launch.sh dev-ros2-<ROS_DISTRO>
Step2: Accessing the container for development and debugging
$ docker exec -it dev-ros2-<ROS_DISTRO> bash
Examples
Examples demonstration on how to subscribe to and control services of other ROS2 nodes.
Stop docker container
$ cd /usr/local/Advantech/ros/container/docker $ ./stop.sh dev-ros2-<ROS_DISTRO>
Build Your Docker Container
To build a Docker container for your ROS2 application and integrate Advantech's add-ons services, you can following the steps.
Step1: Define a Dockerfile
Create a file called "Dockerfile" that specifies the instructions for building the container based on dev-ros2-<ROS_DISTRO>. This file includes details such as the base image, dependencies, environment variables, and commands to run inside the container.
FROM advigw/dev-ros2-<ROS_DISTRO>:1.0.0 # 1. Copy prerequisites of your application into the container # WORKDIR /root # COPY prerequisite/<your_application> /root/prerequisite # 2. Install dependencies or libraries # RUN apt-get update # RUN apt-get install <some_dependency> # 3. Execute your application automatically upon container startup. # CMD [<application_command>]
Step2: Build the Docker image
Use the Docker command-line to build the Docker image based on the Dockerfile. This process involves pulling the necessary base image, executing the instructions in the Dockerfile, and creating a layered image with all the specified components.
$ docker build -t ros-example -f Dockerfile .
Step3: Define the Docker Compose services
Create a file called "docker-compose.yml", in the Docker Compose file, define the services, their image references, and any necessary configurations such as environment variables, port mappings, volume bindings, etc. Use the syntax provided by Docker Compose to define each service.
version: '2.1'
services:
ros-example:
image: ros-example
container_name: ros-example
restart: always
networks:
- adv-ros-network
logging:
options:
max-size: 10M
environment:
- ROS_DOMAIN_ID=${ROS_DOMAIN_ID}
networks:
adv-ros-network:
name: adv-ros-network
Step4: Start the containers using Docker Compose
Execute the docker-compose up command in the directory where the Docker Compose file is located. This command will start the containers as defined in the Compose file.
Note: When using the docker-compose command, please avoid using 'sudo' if you need to use the ROS_DOMAIN_ID environment variable. Otherwise, the variable may not be found during execution.
$ docker-compose -f docker-compose.yml up -d
Step5: Test and validate
Open a new interactive bash shell within the container.
$ docker exec -it ros-example bash
Then test ROS2 Example and your applications in container.