Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add description on mounting host volume #16

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ RUN apt-get update && apt-get install -y \
python3-pip \
&& rm -rf /var/lib/apt/lists/*

# Install ROS2 plugins
RUN apt-get install -y \
ros-foxy-ros2bag \
ros-foxy-rosbag2-converter-default-plugins \
Expand All @@ -26,8 +27,7 @@ RUN mkdir -p /bag_files

# Install python packages
RUN pip3 install --upgrade pip
RUN pip3 install numpy matplotlib scipy scikit-learn
RUN pip3 install h5py torchvision==0.16.2 torch==2.1.2+cpu -f https://download.pytorch.org/whl/torch_stable.html
RUN pip3 install numpy
RUN rm -rf /root/.cache/pip

# Clone the ros2-vicon-receiver package
Expand Down
72 changes: 46 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This Docker image is designed to provide a pre-configured environment for roboti
## Features

- ROS2 Foxy desktop installation
- Python 3.8 (installed with ROS2 docker image)
- Vicon SDK and necessary dependencies
- Pre-configured for integration between ROS2 and Vicon systems
- Suitable for robotics research and development involving motion capture
Expand Down Expand Up @@ -69,6 +70,7 @@ To find more details on how to use Docker, please refer Docker's official docume
| ------------ | ------------ | ----------- |
| `-i` | | keeps `STDIN` open even if not attached, allowing for interactive use |
| `-t` | | allocates a pseudo-TTY, which provides an interactive shell in the container |
| `-v` | `<host_path>:<container_path>` | Mount the host volume to container |
| `--rm` | | automatically removes the container when it exits. It's useful for creating temporary containers that clean up after themselves |
| `--entrypoint` | `bash` | overrides the default entrypoint of the container with bash. It means that instead of running whatever command was specified as the default in the `Dockerfile`, the container will start a bash shell. |
| | `<name>` | name of the Docker image to use for creating the container.
Expand Down Expand Up @@ -160,44 +162,62 @@ docker run -it --rm <name> ros2 launch vicon_receiver mock_client.launch.py
```


#### Ros2bag
### Record using Ros2bag

More documentation can be found [here](https://docs.ros.org/en/foxy/Tutorials/Beginner-CLI-Tools/Recording-And-Playing-Back-Data/Recording-And-Playing-Back-Data.html).

The docker image includes the directory `/bag_files` for users to save the file. To use directory as your working directory for `ros2bag`, you will need to use two terminals.
#### Save in the host folder

Using the docker `-v` flag which mounts the host directory, data can be directly saved in host file system.

In the first one, create a container
```zsh
docker run -it --rm <name>
```
and when you want to start the record, run
```bash
ros2 bag record -o bag_files/<record_name> /topic1 /topic2 /topic3
docker run -it --rm \
-v <host_directory_path>:/bag_files \
<name> \
ros2 bag record -o /bag_files/<record_name> /topic1 /topic2 /topic3
```
where `-o` tag means output file directory.

To finish the recording, press `control+c` directly.
This will stop the recording and save the data in the folder `<record_name>` directly under the `bag_files` directory.
#### Save in the container folder

To move the recording outside of the container, run the following command in the second terminal
```zsh
docker cp <container_id>:/bag_files/<record_name> /path/to/your/local/directory
```
and you are done!
<details>
<summary>Click me for more detail.</summary>

To move the recording `<record_name>` from your local end into the container, run
```zsh
docker cp /path/to/your/local/directory/<record_name> <container_id>:/bag_files/
```
The docker image includes the directory `/bag_files` for users to save the file. To use directory as your working directory for `ros2bag`, you will need to use two terminals.

To replay the recording `<record_name>` in the container, run
```bash
ros2 bag play bag_files/<record_name>
```
In the first one, create a container
```zsh
docker run -it --rm <name>
```
and when you want to start the record, run
```bash
ros2 bag record -o bag_files/<record_name> /topic1 /topic2 /topic3
```
where `-o` tag means output file directory.

To finish the recording, press `control+c` directly.
This will stop the recording and save the data in the folder `<record_name>` directly under the `bag_files` directory.

To move the recording outside of the container, run the following command in the second terminal
```zsh
docker cp <container_id>:/bag_files/<record_name> <host_directory_path>
```
and you are done!

To move the recording `<record_name>` from your local end into the container, run
```zsh
docker cp <host_directory_path>/<record_name> <container_id>:/bag_files/
```

To replay the recording `<record_name>` in the container, run
```bash
ros2 bag play bag_files/<record_name>
```

> When you use `ros2bag`, make sure you download the saved `bag_files` before exiting or removing the docker container.

> When you use `ros2bag`, make sure you download the saved `bag_files` before exiting or removing the docker container.
</details>

#### Ros2 Tips
### Other Ros2 Tips

More commands are available in official ROS2 documentation. Here, I'm providing few that will be useful
to debug the `docker` container.
Expand Down