Skip to content

Commit

Permalink
Merge pull request #152 from xfiderek/issue/142
Browse files Browse the repository at this point in the history
Pin navigation2 repos and simplify docker build (#142).
  • Loading branch information
eholum authored Oct 22, 2024
2 parents 09ec444 + 5c8467d commit 045f144
Show file tree
Hide file tree
Showing 12 changed files with 766 additions and 133 deletions.
6 changes: 3 additions & 3 deletions nav2_demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ Start the space_nav2 container and launch the navigation2 nodes:

```
./run.sh
ros2 launch nav2_bringup navigation_launch.py use_sim_time:=True params_file:=nav2_params.yaml
ros2 launch space_nav2_bringup navigation_launch.py use_sim_time:=True params_file:=nav2_params.yaml
```

## Terminal 3 - launch localization with map

```
docker exec -it osrf_space_nav2_demo bash
source install/setup.bash
ros2 launch nav2_bringup localization_launch.py use_sim_time:=True map:=mars_map.yaml
ros2 launch space_nav2_bringup localization_launch.py use_sim_time:=True map:=mars_map.yaml params_file:=nav2_params.yaml
```

## Terminal 4 - launch Rviz

Exec into the same space_nav2 container and launch Rviz2:

```
docker exec -it -e DISPLAY=:0 osrf_space_nav2_demo bash
docker exec -it -e DISPLAY osrf_space_nav2_demo bash
source /opt/ros/humble/setup.bash
source install/setup.bash
ros2 launch nav2_bringup rviz_launch.py
Expand Down
79 changes: 23 additions & 56 deletions navigation2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,69 +41,36 @@ LABEL org.label-schema.vcs-ref=${VCS_REF}
# Disable prompting during package installation
ARG DEBIAN_FRONTEND=noninteractive

SHELL ["/bin/bash", "-c"]

# Define workspace locations
ENV NAVIGATION2_WS=${HOME_DIR}/nav2_ws
ENV NAV2_DEPS_WS=${HOME_DIR}/nav2_deps_ws

# Get the Navigation2 source code
RUN mkdir -p ${NAVIGATION2_WS}/src
WORKDIR ${NAVIGATION2_WS}/src
ARG NAV2_BRANCH=humble
RUN sudo git clone --branch $NAV2_BRANCH https://github.com/ros-navigation/navigation2.git

# Get keys for Nav2 dependencies
WORKDIR ${NAVIGATION2_WS}/
SHELL ["/bin/bash", "-c"]
RUN source ${SPACEROS_DIR}/install/setup.bash && sudo apt update && rosdep keys --from-paths src --ignore-src --rosdistro humble -y > ${NAVIGATION2_WS}/nav2_dep_keys.txt

# Get rosinstall_generator
RUN sudo apt-get update -y && sudo apt-get install -y python3-rosinstall-generator

# Clone Space ROS sources temporarily as input to rosinstall_generator
RUN mkdir ${SPACEROS_DIR}/src \
&& vcs import ${SPACEROS_DIR}/src < ${SPACEROS_DIR}/exact.repos

# Generate repos file for nav2 dependencies, exclude packages from Space ROS src
RUN rosinstall_generator \
--rosdistro ${ROS_DISTRO} \
--deps \
--exclude-path ${SPACEROS_DIR}/src -- \
-- $(cat ${NAVIGATION2_WS}/nav2_dep_keys.txt) \
> ${NAVIGATION2_WS}/nav2_deps.repos

# Remove unneeded src files now that repos are generated
RUN rm -rf ${SPACEROS_DIR}/src

# Get the repositories required by Nav2
RUN mkdir -p ${NAV2_DEPS_WS}/src
WORKDIR ${NAV2_DEPS_WS}
RUN sudo vcs import src < ${NAVIGATION2_WS}/nav2_deps.repos

# Update the ownership of the source files
RUN sudo chown -R ${USERNAME}:${USERNAME} ${NAV2_DEPS_WS}

# Install nav2_deps_ws dependencies
SHELL ["/bin/bash", "-c"]
RUN source ${SPACEROS_DIR}/install/setup.bash && sudo apt update && rosdep install --from-paths src --ignore-src --rosdistro humble -y \
--skip-keys "composition demo_nodes_py ikos lifecycle rmw_connextdds rmw_fastrtps_dynamic_cpp rmw_fastrtps_cpp \
rosidl_typesupport_fastrtps_c rosidl_typesupport_fastrtps_cpp urdfdom_headers"

# Build dependencies
RUN source ${SPACEROS_DIR}/install/setup.bash && colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

# Install remaining nav2 dependencies (not in rosdistro)
WORKDIR ${NAVIGATION2_WS}
SHELL ["/bin/bash", "-c"]
RUN source ${NAV2_DEPS_WS}/install/setup.bash && sudo apt update && rosdep install --from-paths src --ignore-src --rosdistro humble -y \
--skip-keys "composition demo_nodes_py ikos lifecycle rmw_connextdds rmw_fastrtps_dynamic_cpp rmw_fastrtps_cpp \
rosidl_typesupport_fastrtps_c rosidl_typesupport_fastrtps_cpp urdfdom_headers"

# Build Navigation2
SHELL ["/bin/bash", "-c"]
RUN source ${NAV2_DEPS_WS}/install/setup.bash && colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

# Install rviz2 to send goals to Nav2
RUN sudo apt update && sudo apt install -y ros-humble-rviz2
COPY navigation2.repos .
COPY excluded-pkgs.txt .
RUN vcs import --shallow src < navigation2.repos
COPY --chown=spaceros-user:spaceros-user src/ src

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
source ${SPACEROS_DIR}/install/setup.bash && \
sudo apt update && \
rosdep install -i --from-path src --skip-keys $(cat excluded-pkgs.txt) -y
RUN source ${SPACEROS_DIR}/install/setup.bash && \
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON --no-warn-unused-cli
RUN rm -rf src build log


# Install rviz2 to send goals to Nav2.
# TODO(xfiderek): Remove rviz2 and humble-nav2 froms this image
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
sudo apt update && \
sudo apt install -y ros-humble-rviz2 ros-humble-nav2-bringup

# Set up the entrypoint
COPY ./entrypoint.sh /
Expand Down
34 changes: 28 additions & 6 deletions navigation2/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Navigation2 Docker Image

The Navigation2 Docker image uses the Space ROS docker image (*osrf/space-ros:latest*) as its base image.
The Navigation2 Dockerfile installs all of the prerequisite system dependencies to build Navigation2
The Navigation2 Dockerfile installs all of the prerequisite system dependencies to build Navigation2.
All the required nav2 packages are cloned and built from sources using the `navigation2.repos` file. The `nav2_rviz_plugins` and `nav2_bringup` packages together with their dependencies (Rviz, Gazebo, etc) are excluded to reduce package dependencies. The image also contains a custom `space_nav2_bringup` package that can be used as a starting point for creating mission-specific nav2 launch files.

## Building the Navigation2 Image

To build the docker image, run:
Expand Down Expand Up @@ -33,8 +35,7 @@ The output will look something like this:
```
REPOSITORY TAG IMAGE ID CREATED SIZE
osrf/space_nav2 latest 6edb2edc9643 10 hours ago 15.5GB
openrobotics/spaceros latest 629b13cf7b74 12 hours ago 7.8GB
nvidia/cudagl 11.4.1-devel-ubuntu20.04 336416dfcbba 1 week ago 5.35GB
osrf/space-ros latest 629b13cf7b74 12 hours ago 7.8GB
```

The new image is named **osrf/space_nav2:latest**.
Expand All @@ -45,13 +46,34 @@ There is a run.sh script provided for convenience that will run the spaceros ima
./run.sh
```

Upon startup, the container automatically runs the entrypoint.sh script, which sources the MoveIt2 and Space ROS environment files.
Upon startup, the container automatically runs the entrypoint.sh script, which sources the Nav2 and Space ROS environment files.
You'll now be running inside the container and should see a prompt similar to this:

```
root@ip-your-ip-address:/home/spaceros-user/nav2_ws#
spaceros-user@ip-your-ip-address:/home/spaceros-user/nav2_ws#
```

## Running Navigation2 Demo

To run the latest demo, see the README in the nav2_demos folder
To run the latest demo, see the README in the [nav2_demo](../nav2_demo/README.md) folder.

## Updating navigation2 packages

The `navigation2.repos` file available in this repository provides a list of repos that are required to build the nav2 stack. ROS packages already included in the SpaceROS base image are omited from this file.

To update navigation2 packages used to build the space nav2 image, run the `docker_update_nav2_repos.sh` script:

```
./docker_update_nav2_repos.sh
```

This will update the `navigation2.repos` file with the newest versions of nav2 packages. The script resolves missing packages in base spaceros image and creates a list with their latest versions. The `navigation2.repos` file is then copied during build to the docker image with space nav2, and packages specified in the file are cloned and installed.

By default, this update nav2 repositories using the latest released version of the Space ROS base image (typically `osrf/space-ros:latest`).
If building locally, the underlying base image can be set in the through the environment with:

```
SPACE_ROS_IMAGE=osrf/space-ros:main ./docker_update_nav2_repos.sh
```

To generate a list of required packages for any other ROS workspace (e.g. your custom workspace built on top of SpaceROS that already has some nav2 dependencies installed), consider using the `update_nav2_repos.sh` as your starting point. You may also need to clone `generate-repos.sh` script from the main spaceros repository.
8 changes: 8 additions & 0 deletions navigation2/docker_update_nav2_repos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
SPACE_ROS_IMAGE="${SPACE_ROS_IMAGE:-osrf/space-ros:latest}"

docker run --rm \
-v ./:/home/spaceros-user/mount/ \
-w /home/spaceros-user/mount/ \
$SPACE_ROS_IMAGE \
bash -c './update_nav2_repos.sh'
1 change: 1 addition & 0 deletions navigation2/excluded-pkgs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nav2_rviz_plugins
1 change: 1 addition & 0 deletions navigation2/navigation2-pkgs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
navigation2
Loading

0 comments on commit 045f144

Please sign in to comment.