Skip to content

Commit ed3521a

Browse files
authored
Merge pull request #1124 from ROBOTIS-GIT/feature-docker-update
Support Dockerfile
2 parents 9d216c1 + e8d5765 commit ed3521a

File tree

26 files changed

+416
-52
lines changed

26 files changed

+416
-52
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ build-*/
5959
*.txt.user
6060
*.gch
6161
/.project
62+
.DS_Store

Dockerfile

Lines changed: 0 additions & 35 deletions
This file was deleted.

docker/humble/Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Use the base ROS2 humble image
2+
FROM ros:humble-ros-base
3+
4+
# Set environment variables
5+
ENV DEBIAN_FRONTEND=noninteractive
6+
ENV COLCON_WS=/root/turtlebot3_ws
7+
8+
# Install the required packages in a single layer and clean up afterwards
9+
RUN apt-get update && \
10+
apt-get install -y --no-install-recommends \
11+
ros-${ROS_DISTRO}-desktop \
12+
python3-argcomplete \
13+
python3-colcon-common-extensions \
14+
libboost-system-dev \
15+
build-essential \
16+
libudev-dev \
17+
udev \
18+
git \
19+
nano \
20+
ros-${ROS_DISTRO}-cartographer \
21+
ros-${ROS_DISTRO}-cartographer-ros \
22+
ros-${ROS_DISTRO}-navigation2 \
23+
ros-${ROS_DISTRO}-nav2-bringup \
24+
ros-${ROS_DISTRO}-turtlebot3-msgs \
25+
ros-${ROS_DISTRO}-dynamixel-sdk \
26+
ros-${ROS_DISTRO}-xacro \
27+
ros-${ROS_DISTRO}-hls-lfcd-lds-driver \
28+
ros-${ROS_DISTRO}-ld08-driver \
29+
ros-${ROS_DISTRO}-coin-d4-driver \
30+
&& rm -rf /var/lib/apt/lists/*
31+
32+
WORKDIR ${COLCON_WS}
33+
34+
RUN mkdir -p ${COLCON_WS}/src && \
35+
cd ${COLCON_WS}/src && \
36+
git clone -b humble https://github.com/ROBOTIS-GIT/turtlebot3.git
37+
38+
RUN bash -c "source /opt/ros/${ROS_DISTRO}/setup.bash && \
39+
cd ${COLCON_WS} && \
40+
colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release"
41+
42+
RUN echo "source /opt/ros/${ROS_DISTRO}/setup.bash" >> ~/.bashrc && \
43+
echo "source ${COLCON_WS}/install/setup.bash" >> ~/.bashrc && \
44+
echo "alias cb='colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release'" >> ~/.bashrc && \
45+
echo "export ROS_DOMAIN_ID=30 # TURTLEBOT3" >> ~/.bashrc && \
46+
echo "# export TURTLEBOT3_MODEL= # burger, waffle, waffle_pi" >> ~/.bashrc && \
47+
echo "# export LDS_MODEL= # LDS-01, LDS-02, LDS-03" >> ~/.bashrc
48+
49+
CMD ["bash"]

docker/humble/container.sh

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/bin/bash
2+
3+
# Get the directory where the script is located
4+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
CONTAINER_NAME="turtlebot3"
6+
7+
# Determine whether to use docker-compose or docker compose
8+
if docker compose version &> /dev/null; then
9+
COMPOSE_CMD="docker compose"
10+
else
11+
COMPOSE_CMD="docker-compose"
12+
fi
13+
14+
# Function to display help
15+
show_help() {
16+
echo "Usage: $0 [command]"
17+
echo ""
18+
echo "Commands:"
19+
echo " help Show this help message"
20+
echo " start Start the container"
21+
echo " enter Enter the running container"
22+
echo " stop Stop the container"
23+
echo ""
24+
echo "Examples:"
25+
echo " $0 start Start container"
26+
echo " $0 enter Enter the running container"
27+
echo " $0 stop Stop the container"
28+
}
29+
30+
# Function to start the container
31+
start_container() {
32+
# Set up X11 forwarding only if DISPLAY is set
33+
if [ -n "$DISPLAY" ]; then
34+
echo "Setting up X11 forwarding..."
35+
xhost +local:docker || true
36+
else
37+
echo "Warning: DISPLAY environment variable is not set. X11 forwarding will not be available."
38+
fi
39+
40+
echo "Starting Turtlebot3 container..."
41+
42+
# Copy udev rule for TurtleBot3
43+
sudo tee /etc/udev/rules.d/99-tb3.rules > /dev/null <<EOF
44+
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", ENV{ID_MM_DEVICE_IGNORE}="1", MODE:="0666"
45+
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="df11", MODE:="0666"
46+
ATTRS{idVendor}=="fff1", ATTRS{idProduct}=="ff48", ENV{ID_MM_DEVICE_IGNORE}="1", MODE:="0666"
47+
ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", ENV{ID_MM_DEVICE_IGNORE}="1", MODE:="0666", SYMLINK+="tb3_lidar"
48+
EOF
49+
50+
# Reload udev rules
51+
echo "Reloading udev rules..."
52+
sudo udevadm control --reload-rules
53+
sudo udevadm trigger
54+
55+
# Pull the latest images
56+
$COMPOSE_CMD -f "${SCRIPT_DIR}/docker-compose.yml" pull
57+
58+
# Run docker-compose
59+
$COMPOSE_CMD -f "${SCRIPT_DIR}/docker-compose.yml" up -d
60+
}
61+
62+
# Function to enter the container
63+
enter_container() {
64+
# Set up X11 forwarding only if DISPLAY is set
65+
if [ -n "$DISPLAY" ]; then
66+
echo "Setting up X11 forwarding..."
67+
xhost +local:docker || true
68+
else
69+
echo "Warning: DISPLAY environment variable is not set. X11 forwarding will not be available."
70+
fi
71+
72+
if ! docker ps | grep -q "$CONTAINER_NAME"; then
73+
echo "Error: Container is not running"
74+
exit 1
75+
fi
76+
docker exec -it "$CONTAINER_NAME" bash
77+
}
78+
79+
# Function to stop the container
80+
stop_container() {
81+
if ! docker ps | grep -q "$CONTAINER_NAME"; then
82+
echo "Error: Container is not running"
83+
exit 1
84+
fi
85+
86+
echo "Warning: This will stop and remove the container. All unsaved data in the container will be lost."
87+
read -p "Are you sure you want to continue? [y/N] " -n 1 -r
88+
echo
89+
if [[ $REPLY =~ ^[Yy]$ ]]; then
90+
$COMPOSE_CMD -f "${SCRIPT_DIR}/docker-compose.yml" down
91+
else
92+
echo "Operation cancelled."
93+
exit 0
94+
fi
95+
}
96+
97+
# Main command handling
98+
case "$1" in
99+
"help")
100+
show_help
101+
;;
102+
"start")
103+
start_container
104+
;;
105+
"enter")
106+
enter_container
107+
;;
108+
"stop")
109+
stop_container
110+
;;
111+
*)
112+
echo "Error: Unknown command"
113+
show_help
114+
exit 1
115+
;;
116+
esac

docker/humble/docker-compose.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
services:
2+
turtlebot3:
3+
container_name: turtlebot3
4+
image: robotis/turtlebot3:humble-latest
5+
# build:
6+
# context: .
7+
# dockerfile: Dockerfile.pc
8+
tty: true
9+
restart: unless-stopped
10+
cap_add:
11+
- SYS_NICE
12+
ulimits:
13+
rtprio: 99
14+
rttime: -1
15+
memlock: 8428281856
16+
network_mode: host
17+
ipc: host
18+
pid: host
19+
environment:
20+
- DISPLAY=${DISPLAY}
21+
- QT_X11_NO_MITSHM=1
22+
volumes:
23+
- /dev:/dev
24+
- /dev/shm:/dev/shm
25+
- /tmp/.X11-unix:/tmp/.X11-unix:rw
26+
- /tmp/.docker.xauth:/tmp/.docker.xauth:rw
27+
- ./workspace:/workspace
28+
- ../../:/root/turtlebot3_ws/src/turtlebot3
29+
privileged: true
30+
command: bash

docker/jazzy/Dockerfile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Use the base ROS2 jazzy image
2+
FROM ros:jazzy-ros-base
3+
4+
# Set environment variables
5+
ENV DEBIAN_FRONTEND=noninteractive
6+
ENV COLCON_WS=/root/turtlebot3_ws
7+
8+
# Install the required packages in a single layer and clean up afterwards
9+
RUN apt-get update && \
10+
apt-get install -y --no-install-recommends \
11+
ros-${ROS_DISTRO}-desktop \
12+
python3-argcomplete \
13+
python3-colcon-common-extensions \
14+
libboost-system-dev \
15+
build-essential \
16+
libudev-dev \
17+
udev \
18+
git \
19+
nano \
20+
ros-${ROS_DISTRO}-cartographer \
21+
ros-${ROS_DISTRO}-cartographer-ros \
22+
ros-${ROS_DISTRO}-navigation2 \
23+
ros-${ROS_DISTRO}-nav2-bringup \
24+
ros-${ROS_DISTRO}-nav2-route \
25+
ros-${ROS_DISTRO}-turtlebot3-msgs \
26+
ros-${ROS_DISTRO}-dynamixel-sdk \
27+
ros-${ROS_DISTRO}-xacro \
28+
ros-${ROS_DISTRO}-hls-lfcd-lds-driver \
29+
ros-${ROS_DISTRO}-ld08-driver \
30+
ros-${ROS_DISTRO}-coin-d4-driver \
31+
&& rm -rf /var/lib/apt/lists/*
32+
33+
WORKDIR ${COLCON_WS}
34+
35+
RUN mkdir -p ${COLCON_WS}/src && \
36+
cd ${COLCON_WS}/src && \
37+
git clone -b jazzy https://github.com/ROBOTIS-GIT/turtlebot3.git
38+
39+
RUN bash -c "source /opt/ros/${ROS_DISTRO}/setup.bash && \
40+
cd ${COLCON_WS} && \
41+
colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release"
42+
43+
RUN echo "source /opt/ros/${ROS_DISTRO}/setup.bash" >> ~/.bashrc && \
44+
echo "source ${COLCON_WS}/install/setup.bash" >> ~/.bashrc && \
45+
echo "alias cb='colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release'" >> ~/.bashrc && \
46+
echo "export ROS_DOMAIN_ID=30 # TURTLEBOT3" >> ~/.bashrc && \
47+
echo "# export TURTLEBOT3_MODEL= # burger, waffle, waffle_pi" >> ~/.bashrc && \
48+
echo "# export LDS_MODEL= # LDS-01, LDS-02, LDS-03" >> ~/.bashrc
49+
50+
CMD ["bash"]

0 commit comments

Comments
 (0)