diff --git a/Dockerfile b/Dockerfile index cfcfc4a..9a21986 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,10 +16,9 @@ RUN apt-get update && apt-get install -y \ vim \ && rm -rf /var/lib/apt/lists/* -RUN echo "source /opt/ros/foxy/setup.bash" >> /root/.bashrc # Clone the ros2-vicon-receiver package -ENV WS=/vicon_ws +ENV WS /vicon_ws RUN mkdir -p $WS/src && \ cd $WS/src && \ git clone https://github.com/skim0119/ros2-vicon-receiver && \ @@ -30,7 +29,15 @@ RUN mkdir -p $WS/src && \ WORKDIR $WS RUN source /opt/ros/foxy/setup.bash && \ colcon build --symlink-install -RUN echo "source /vicon_ws/install/setup.bash" >> /root/.bashrc + +WORKDIR / +RUN source vicon_ws/install/setup.bash + +RUN echo ". /opt/ros/foxy/setup.bash" >> /root/.bashrc +RUN echo ". /vicon_ws/install/setup.bash" >> /root/.bashrc + +RUN sed -e '/[ -z "$PS1" ] && return/s/^/#/g' -i /root/.bashrc # Set the entrypoint to use ROS 2 -ENTRYPOINT ["/bin/bash", "-c", "ros2 launch vicon_receiver client.lanuch.py && exec \"$@\"", "--"] +ENTRYPOINT ["/bin/bash", "-c", "source ~/.bashrc && exec \"$@\"", "--"] +CMD ["bash"] \ No newline at end of file diff --git a/README.md b/README.md index 8e08e6d..d2346f0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Publish Docker Image to Docker Hub CI](https://github.com/hanson-hschang/ros2-vicon/actions/workflows/docker-image.yml/badge.svg?branch=main)](https://github.com/hanson-hschang/ros2-vicon/actions/workflows/docker-image.yml) -This repository contains a Dockerfile and associated scripts for creating a Docker image that combines ROS2 (Robot Operating System 2) with Vicon motion capture system integration. +This repository contains a Dockerfile and associated scripts for creating a Docker image that combines ROS2 (Robot Operating System 2) with Vicon motion capture system integration. The image includes this [ros2-node](https://github.com/OPT4SMART/ros2-vicon-receiver) to communicate with external Vicon system. ## Overview @@ -20,9 +20,22 @@ This Docker image is designed to provide a pre-configured environment for roboti - [Docker](https://www.docker.com/) installed on your system - Git (for cloning this repository) -## Building the Docker Image +## Download the Docker Image -To build the Docker image: +### Method 1: Pull from Docker Hub + +Docker image is built using `github-action`, and uploaded to [Docker Hub](https://hub.docker.com/r/hansonhschang/ros2-vicon). + +```zsh +docker pull hansonhschang/ros2-vicon:latest +``` + +> The variable `` in following sections will be `hansonhschang/ros2-vicon`. + + +### Method 2: Build locally from Dockrfile + +To build the Docker image locally: 1. Clone this repostitory ```zsh @@ -47,6 +60,7 @@ To build the Docker image: 1. To create and start a new container from the image, run the following command ```zsh + docker run -i -t --rm docker run -i -t --rm --entrypoint bash ``` | flag                         | value                 | function | @@ -98,6 +112,52 @@ To build the Docker image: For GUI applications, you may need to set up X11 forwarding or use other methods to enable GUI support. +## How to use + +You can run `ros2` commands as if you have `ros2` installed on local machine. Just prepend `docker run -it --rm ros2`. + +> To use your own script or folder outside of the container, you have to create the container without `--rm` flag, and copy the contents inside. Take a look [here](https://docs.docker.com/reference/cli/docker/container/cp/). + +### Test Ros2: Talker and Listener + +> The structure is similar to [this](https://docs.ros.org/en/foxy/How-To-Guides/Run-2-nodes-in-single-or-separate-docker-containers.html#run-two-nodes-in-two-separate-docker-containers). + +Run the following ros2 nodes on each terminal: + +```zsh +docker run -it --rm ros2 run demo_nodes_cpp talker +docker run -it --rm ros2 run demo_nodes_cpp listener +``` + +### Launch Vicon + +> The default host ip is `192.168.1.12`. + +```zsh +docker run -it --rm ros2 launch vicon_receiver client.launch.py +``` + +To see the data, you can implement your own listener or use `ros2 topic echo `. + +#### Mock Vicon System + +Mock system can be launched when Vicon system is not available. + +```zsh +docker run -it --rm ros2 launch vicon_receiver mock_client.launch.py +``` + +#### Ros2 Tips + +More commands are available in official ROS2 documentation. Here, I'm providing few that will be useful +to debug the `docker` container. + +```zsh +docker run -it --rm ros2 pkg list # list all available ros2 packages +docker run -it --rm ros2 topic list # list all available ros2 topics +docker run -it --rm ros2 topic echo # listen a topic data +``` + ## CI/CD This repository uses GitHub Actions for continuous integration and delivery. On each pull request to the main branch, the workflow will: @@ -109,4 +169,4 @@ The workflow can also be manually triggered from the GitHub Actions tab. ## Contributing -Contributions to improve this Docker image are welcome. Please submit issues and pull requests on this GitHub repository. \ No newline at end of file +Contributions to improve this Docker image are welcome. Please submit issues and pull requests on this GitHub repository.