Skip to content

Commit b498a85

Browse files
committed
add dockerfile, scripts
1 parent 2397c53 commit b498a85

12 files changed

Lines changed: 270 additions & 14 deletions

File tree

docker/.dockerignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Ignore Git repository files
2+
.git
3+
.gitignore
4+
.gitmodules
5+
6+
# Ignore ROS 2 build artifacts
7+
build/
8+
install/
9+
log/
10+
11+
# Ignore IDE/editor configurations
12+
.vscode/
13+
.idea/
14+
15+
# Ignore Python cache files
16+
__pycache__/
17+
18+
# Ignore temporary and backup files
19+
*.swp
20+
*.swo
21+
*.bak
22+
*.tmp
23+
24+
# Ignore development environment and temporary files
25+
.devenv/
26+
colcon_ws.log
27+
28+
# Ignore secret environment variable files (if any)
29+
.env
30+
.env.*

docker/Dockerfile

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
FROM px4io/px4-dev-simulation-jammy
2+
LABEL maintainer="kmk <kmk6061602@gmail.com>"
3+
4+
ENV ROS_DISTRO=humble
5+
6+
RUN apt update && apt install -y \
7+
git \
8+
sudo
9+
10+
RUN echo user ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/user \
11+
&& chmod 0440 /etc/sudoers.d/user
12+
13+
# install ros2 humble
14+
RUN apt update && apt install -y locales \
15+
&& locale-gen en_US en_US.UTF-8 \
16+
&& update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 \
17+
&& export LANG=en_US.UTF-8 \
18+
&& apt install -y software-properties-common \
19+
&& add-apt-repository universe \
20+
&& apt update && apt install curl -y \
21+
&& curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg \
22+
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null \
23+
&& apt update && apt upgrade -y \
24+
&& apt install -y ros-$ROS_DISTRO-desktop \
25+
python3-colcon-common-extensions \
26+
&& apt -y autoremove \
27+
&& apt clean autoclean \
28+
&& rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log} /tmp/* /var/tmp/*
29+
30+
RUN git config --global http.postBuffer 524288000
31+
32+
# Install Micro XRCE-DDS Agent v3.0.1
33+
RUN git clone --branch v3.0.1 https://github.com/eProsima/Micro-XRCE-DDS-Agent.git /tmp/Micro-XRCE-DDS-Agent \
34+
&& cd /tmp/Micro-XRCE-DDS-Agent \
35+
&& mkdir build \
36+
&& cd build \
37+
&& cmake .. \
38+
&& make -j$(nproc) \
39+
&& make install && ldconfig \
40+
&& rm -rf /tmp/Micro-XRCE-DDS-Agent
41+
42+
WORKDIR /home/user
43+
USER user
44+
RUN mkdir realgazebo
45+
WORKDIR /home/user/realgazebo
46+
47+
RUN git clone --branch realgazebo-1.14 https://github.com/SUV-Lab/RealGazebo-PX4-Autopilot.git --recursive \
48+
&& git clone https://github.com/SUV-Lab/RealGazebo-ROS2.git --recursive
49+
50+
RUN cd /home/user/realgazebo/RealGazebo-PX4-Autopilot && ./Tools/setup/ubuntu.sh --no-nuttx
51+
52+
USER root
53+
RUN curl -sSL http://get.gazebosim.org | sh
54+
RUN apt update \
55+
&& apt install -y ros-$ROS_DISTRO-gazebo-ros-pkgs \
56+
ros-$ROS_DISTRO-gazebo-ros \
57+
xterm \
58+
&& apt-get -y autoremove \
59+
&& apt-get clean autoclean \
60+
&& rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log} /tmp/* /var/tmp/*
61+
62+
RUN pip3 install gdown
63+
64+
USER user
65+
RUN cd /home/user/realgazebo/RealGazebo-PX4-Autopilot \
66+
&& ./Tools/download_ctrack.sh \
67+
&& DONT_RUN=1 make px4_sitl_default gazebo-classic \
68+
&& cd /home/user/realgazebo/RealGazebo-ROS2 \
69+
&& . /opt/ros/humble/setup.sh \
70+
&& colcon build --symlink-install
71+
72+
USER root
73+
# Add setup file at bashrc
74+
RUN echo "source /opt/ros/$ROS_DISTRO/setup.bash" >> /home/user/.bashrc \
75+
&& echo "source /home/user/realgazebo/RealGazebo-ROS2/install/setup.bash" >> /home/user/.bashrc \
76+
&& chown user:user /home/user/.bashrc
77+
78+
# Entrypoint
79+
COPY scripts/entrypoint.sh /usr/local/bin/entrypoint.sh
80+
RUN chmod +x /usr/local/bin/entrypoint.sh
81+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
82+
83+
CMD ["/bin/bash"]

docker/scripts/entrypoint.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# Start virtual X server in the background
4+
# - DISPLAY default is :99, set in dockerfile
5+
# - Users can override with `-e DISPLAY=` in `docker run` command to avoid
6+
# running Xvfb and attach their screen
7+
if [[ -x "$(command -v Xvfb)" && "$DISPLAY" == ":99" ]]; then
8+
echo "Starting Xvfb"
9+
Xvfb :99 -screen 0 1600x1200x24+32 &
10+
fi
11+
12+
# Check if the ROS_DISTRO is passed and use it
13+
# to source the ROS environment
14+
if [ -n "${ROS_DISTRO}" ]; then
15+
source "/opt/ros/$ROS_DISTRO/setup.bash"
16+
fi
17+
18+
# Use the LOCAL_USER_ID if passed in at runtime
19+
if [ -n "${LOCAL_USER_ID}" ]; then
20+
echo "Starting with UID : $LOCAL_USER_ID"
21+
chown -R "$LOCAL_USER_ID:$LOCAL_USER_ID" /home/user || true
22+
23+
# modify existing user's id
24+
usermod -u $LOCAL_USER_ID user
25+
# run as user
26+
exec gosu user "$@"
27+
else
28+
exec "$@"
29+
fi

scripts/edit_realgazebo.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
container_name="edit_realgazebo"
2+
3+
docker stop "$container_name" 2>/dev/null
4+
docker rm "$container_name" 2>/dev/null
5+
6+
docker run --gpus all -it --privileged \
7+
-e DISPLAY=$DISPLAY \
8+
--env="QT_X11_NO_MITSHM=1" \
9+
-e NVIDIA_DRIVER_CAPABILITIES=all \
10+
-v /tmp/.X11-unix:/tmp/.X11-unix \
11+
-v /dev:/dev:rw \
12+
-u user \
13+
--hostname $(hostname) \
14+
--network host \
15+
--name "$container_name" aware4docker/realgazebo-dev:0.1 bash
16+

scripts/example.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# example.yaml
2+
3+
px4_target:
4+
# - A mapping of build targets identified by unique numeric keys.
5+
0 : /home/user/realgazebo/RealGazebo-PX4-Autopilot
6+
# 1: /path/to/your/PX4-Autopilot
7+
8+
vehicles:
9+
# - Each entity is identified by a unique numeric key (e.g., 0, 1, 2, 3).
10+
# - 'type': Specifies the type of the entity.
11+
# - 'build_target': References the PX4 target defined above, determining which PX4-Autopilot build to use.
12+
# - 'spawnpoint' : Defines the spawn location in a 3D space using coordinates and a yaw value (in radians) (x, y, z, yaw).
13+
0 :
14+
type : iris
15+
build_target : 0
16+
spawnpoint : (18.846, 7.80, -1.75, -3.14)
17+
18+
1 :
19+
type : lc_62
20+
build_target : 0
21+
spawnpoint : (18.846, -19.053, -1, -3.14)
22+
23+
2 :
24+
type : x500
25+
build_target : 0
26+
spawnpoint : (18.846, -29.643, -0.75, -3.14)
27+
28+
3 :
29+
type : iris
30+
build_target : 0
31+
spawnpoint : (-24.458, -12.013, -0.2, -3.14)
32+
33+
4 :
34+
type : iris
35+
build_target : 0
36+
spawnpoint : (-24.458, 16.23, -0.2, -3.14)
37+
38+
5 :
39+
type : rover
40+
build_target : 0
41+
spawnpoint : (25.8707, 14.751, -1, -3.14)
42+
43+
6 :
44+
type : rover
45+
build_target : 0
46+
spawnpoint : (25.8707, -36.317, -0.7, -3.14)
47+
48+
7 :
49+
type : rover
50+
build_target : 0
51+
spawnpoint : (25.8707, -10.5, -0.5, -3.14)
52+
53+
8 :
54+
type : boat
55+
build_target : 0
56+
spawnpoint : (-281.27, -225.26, 8.5, -1.57)
57+
58+
9 :
59+
type : wamv
60+
build_target : 0
61+
spawnpoint : (-265.74, -215.94, 8.5, -1.57)
62+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docker exec -it -u user realgazebo bash -c "source /opt/ros/humble/setup.bash && source /home/user/realgazebo/RealGazebo-ROS2/install/setup.bash && ros2 launch realgazebo control_multi_vehicle.launch.py"

scripts/run_control_one_drone.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docker exec -it -u user realgazebo bash -c "source /opt/ros/humble/setup.bash && source /home/user/realgazebo/RealGazebo-ROS2/install/setup.bash && ros2 launch realgazebo control_one_drone.launch.py"

scripts/run_realgazebo.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
if [ "$#" -ne 2 ]; then
2+
echo "Usage: $0 <file_path> <server_ip>"
3+
exit 1
4+
fi
5+
6+
if [ ! -f "$1" ]; then
7+
echo "Error: The specified file does not exist."
8+
exit 1
9+
fi
10+
11+
container_name="realgazebo"
12+
13+
docker stop "$container_name" 2>/dev/null
14+
docker rm "$container_name" 2>/dev/null
15+
16+
docker run --gpus all -d -it --privileged \
17+
-e DISPLAY=$DISPLAY \
18+
--env="QT_X11_NO_MITSHM=1" \
19+
-e NVIDIA_DRIVER_CAPABILITIES=all \
20+
-v /tmp/.X11-unix:/tmp/.X11-unix \
21+
-v /dev:/dev:rw \
22+
--hostname $(hostname) \
23+
--network host \
24+
--name "$container_name" aware4docker/realgazebo-dev:0.1
25+
26+
docker cp $1 "$container_name":/home/user/
27+
28+
docker exec -u user -it "$container_name" bash -c "source /opt/ros/humble/setup.bash && source /home/user/realgazebo/RealGazebo-ROS2/install/setup.bash && ros2 launch realgazebo realgazebo.launch.py vehicle:=/home/user/$(basename "$1") server_ip:=$2"
29+
30+
docker stop "$container_name" 2>/dev/null
31+
docker rm "$container_name" 2>/dev/null

src/manager/manager/px4_ros2.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,14 @@ def main_cmd_callback(self, msg):
107107
self.control_setpoint(self.vehicle_local_position_msg_.x, self.vehicle_local_position_msg_.y - 300, self.vehicle_local_position_msg_.z, self.vehicle_local_position_msg_.heading)
108108
elif self.system_id_ == 2:
109109
self.control_setpoint(self.vehicle_local_position_msg_.x, self.vehicle_local_position_msg_.y - 300, self.vehicle_local_position_msg_.z, self.vehicle_local_position_msg_.heading)
110-
elif self.system_id_ == 8:
111-
self.control_setpoint(self.vehicle_local_position_msg_.x - 100, self.vehicle_local_position_msg_.y, self.vehicle_local_position_msg_.z, self.vehicle_local_position_msg_.heading)
110+
elif self.system_id_ == 6:
111+
self.control_setpoint(self.vehicle_local_position_msg_.x, self.vehicle_local_position_msg_.y - 300, self.vehicle_local_position_msg_.z, self.vehicle_local_position_msg_.heading)
112+
elif self.system_id_ == 7:
113+
self.control_setpoint(self.vehicle_local_position_msg_.x, self.vehicle_local_position_msg_.y - 300, self.vehicle_local_position_msg_.z, self.vehicle_local_position_msg_.heading)
112114
elif self.system_id_ == 9:
113115
self.control_setpoint(self.vehicle_local_position_msg_.x - 100, self.vehicle_local_position_msg_.y, self.vehicle_local_position_msg_.z, self.vehicle_local_position_msg_.heading)
116+
elif self.system_id_ == 10:
117+
self.control_setpoint(self.vehicle_local_position_msg_.x - 100, self.vehicle_local_position_msg_.y, self.vehicle_local_position_msg_.z, self.vehicle_local_position_msg_.heading)
114118
else:
115119
self.control_setpoint(self.vehicle_local_position_msg_.x, self.vehicle_local_position_msg_.y - 70, self.vehicle_local_position_msg_.z, self.vehicle_local_position_msg_.heading)
116120

src/realgazebo/launch/realgazebo.launch.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,8 @@ def generate_launch_description():
217217
declared_arguments.append(
218218
DeclareLaunchArgument(
219219
'vehicle',
220-
# default_value='/home/user/ws/Colosseum/ros2/src/realgazebo/yaml/example.yaml',
221-
default_value='/home/kmk/docker/colosseum_ws/ws/ros2_ws/src/realgazebo/yaml/example.yaml',
222-
description='path to yaml file ex)/home/user/cisim3/Colosseum/ros2/src/realgazebo/yaml/example.yaml'
220+
default_value='/home/user/realgazebo/RealGazebo-ROS2/src/realgazebo/yaml/example.yaml',
221+
description='path to yaml file ex)/home/user/realgazebo/RealGazebo-ROS2/src/realgazebo/yaml/example.yaml'
223222
)
224223
)
225224

0 commit comments

Comments
 (0)