Skip to content

Commit 9e1c116

Browse files
committed
Update cruft
1 parent bf636cc commit 9e1c116

7 files changed

Lines changed: 157 additions & 23 deletions

File tree

.cruft.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"template": "https://github.com/UrbanMachine/create-ros-app.git",
3-
"commit": "8c8e34317b3cf0db5459958d7a50accfd0cc93cd",
3+
"commit": "340d2e1a720c27568b2729fa4ae27a1a28a08335",
44
"checkout": null,
55
"context": {
66
"cookiecutter": {

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ __pycache__/
2323
.docker_volumes
2424

2525
# URDF
26-
*.part
26+
*.part
27+
28+
# Dev specific overrides
29+
*.override.yaml

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ services:
2424
# Mounts the 'launch-profiles/LAUNCH_PROFILE' directory into '/robot/launch-profile/'
2525
# This way you can save configuration files from GUI's like rviz right back to your source dir
2626
# LAUNCH_PROFILE is set in docker/_shared.sh
27-
- "./launch-profiles/${LAUNCH_PROFILE}:/robot/launch-profile/"
27+
- ./launch-profiles/${LAUNCH_PROFILE:- ''}:/robot/launch-profile
2828
# Necessary for display passthrough
2929
- "/tmp/.X11-unix:/tmp/.X11-unix:rw"
3030
# Necessary for PulseAudio passthrough

docker/Dockerfile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ RUN --mount=type=cache,target="${APT_CACHE}" \
4141
# ROS2
4242
ros-${ROS2_DISTRO}-ros-base \
4343
ros-${ROS2_DISTRO}-rosbridge-suite \
44-
ros-${ROS2_DISTRO}-rmw-cyclonedds-cpp \
4544
# Build tools
4645
build-essential \
4746
git \
@@ -98,7 +97,21 @@ COPY pkgs/node_helpers/poetry.lock pkgs/node_helpers/poetry.lock
9897
COPY pkgs/node_helpers/pyproject.toml pkgs/node_helpers/pyproject.toml
9998
######################################################################
10099
101-
# Install Poetry dependencies for each package
100+
######################################################################
101+
########## Add Git ROS2 Packages
102+
########## NOTE TO TEMPLATE USERS: If you need to depend on a package that is not in the ROS2 distro, you can add it here
103+
WORKDIR /ros-git-deps/
104+
RUN --mount=type=cache,target="${PIP_CACHE}" \
105+
--mount=type=cache,target="${APT_CACHE}" \
106+
install-ros-package-from-git \
107+
https://github.com/UrbanMachine/node_helpers.git main pkgs && \
108+
##################### Add your packages here!
109+
########### install-ros-package-from-git {URL} {BRANCH} {PKGS PATH IN REPO}
110+
echo "Done installing ROS2 packages from git"
111+
######################################################################
112+
113+
# Install Poetry dependencies for each package in this repo
114+
WORKDIR /robot
102115
RUN --mount=type=cache,target="${PIP_CACHE}" \
103116
python3 -m colcon_poetry_ros.dependencies.install --base-paths pkgs
104117
@@ -116,7 +129,7 @@ RUN --mount=type=cache,target="${BUILD_CACHE}" restore-build-cache
116129
# Build all packages, copying project files under a root `/robot/` directory in the container
117130
COPY ../launch-profiles /robot/launch-profiles
118131
COPY ../pkgs /robot/pkgs
119-
RUN enter-workspaces colcon build
132+
RUN enter-workspaces colcon build --packages-select $(ls pkgs)
120133
RUN add-workspace /robot/install/setup.bash
121134
122135
# Move the build cache back into the Docker cache mount so it can be reused on

docker/grafana/grafana.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ org_name = Main Org.
99
org_role = Admin
1010

1111
[users]
12-
default_theme = light
12+
default_theme = dark
1313
home_page = /d/logs_dashboard/logs
1414

1515
[dashboards]
Lines changed: 82 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,92 @@
11
#!/usr/bin/env bash
22

3-
# Clones a git ros2 repo, checks out a specific branch, then builds and installs it.
3+
# Installs ROS packages from a Git repository into the Docker image.
44
#
5-
# Usage: install-ros-package-from-git {repo_url} {commit_hash}
5+
# This script:
6+
# - Requires specifying the repository URL, branch/tag, and the relative path to a pkgs directory.
7+
# - Clones the repository to a temporary directory.
8+
# - Checks out the specified branch or tag.
9+
# - Moves the contents of the given pkgs directory into a new directory (named after the repo) in the current directory.
10+
# - Installs dependencies and builds all packages found in that directory.
11+
#
12+
# Usage:
13+
# install-ros-package-from-git {repository_url} {branch_or_tag} {pkgs_subdir}
14+
#
15+
# Example:
16+
# install-ros-package-from-git https://github.com/UrbanMachine/example_repo.git main pkgs
17+
#
18+
# This might produce a structure like:
19+
# current_dir/
20+
# example_repo/
21+
# some_pkg_A/
22+
# some_pkg_B/
623

724
set -o errexit
825
set -o pipefail
926
set -o nounset
1027

11-
# Get a directory name based on the URL of the git repo
12-
REPO_PATH=$(pwd)/$(basename "$1" .git)
28+
function usage {
29+
echo "Usage: install-ros-package-from-git {repository_url} {branch_or_tag} {pkgs_subdir}" >&2
30+
exit 1
31+
}
32+
33+
function main {
34+
if [[ "$#" -ne 3 ]]; then
35+
usage
36+
fi
37+
38+
local repo_url="$1"
39+
local branch_or_tag="$2"
40+
local pkgs_subdir="$3"
41+
42+
local original_dir
43+
original_dir="$(pwd)"
44+
45+
# Derive the package name from the repo URL
46+
local package_name
47+
package_name="$(basename "${repo_url}" .git)"
48+
49+
local dest_dir="${original_dir}/${package_name}"
50+
if [[ -d "${dest_dir}" ]]; then
51+
echo "Directory ${dest_dir} already exists. Remove it or choose a different repository." >&2
52+
exit 1
53+
fi
54+
55+
# Create a temporary directory for cloning
56+
local temp_dir
57+
temp_dir="$(mktemp -d)"
58+
59+
# Clone the repository into the temp directory
60+
git clone "${repo_url}" "${temp_dir}"
61+
cd "${temp_dir}"
62+
63+
# Checkout the specified branch or tag
64+
git checkout "${branch_or_tag}"
65+
66+
# Verify that the specified pkgs_subdir exists
67+
if [[ ! -d "${pkgs_subdir}" ]]; then
68+
echo "The specified pkgs_subdir '${pkgs_subdir}' does not exist in the repository." >&2
69+
exit 1
70+
fi
71+
72+
# Create the destination directory and move the packages
73+
mkdir -p "${dest_dir}"
74+
# Move everything from pkgs_subdir into the new directory
75+
mv "${pkgs_subdir}"/* "${dest_dir}/"
76+
77+
# Return to the original directory to install dependencies and build
78+
cd "${original_dir}"
79+
80+
# Install ROS dependencies with rosdep
81+
with-package-list rosdep install -i --from-path "${dest_dir}" --rosdistro "${ROS2_DISTRO:-foxy}" -y
82+
83+
# Install Poetry dependencies for the packages
84+
python3 -m colcon_poetry_ros.dependencies.install --base-paths "${dest_dir}"
1385

14-
# Clone and check out the requisite stuff
15-
git clone "$1"
16-
cd "${REPO_PATH}"
17-
git checkout "$2"
86+
# Build the packages using colcon
87+
# We use enter-workspaces to ensure all previously added workspaces are sourced.
88+
enter-workspaces colcon build --base-paths "${package_name}"
89+
add-workspace "${original_dir}/install/setup.bash"
90+
}
1891

19-
# Install dependencies, build the package, and add it to the ros2 workspaces
20-
with-package-list rosdep install -i --rosdistro "${ROS2_DISTRO}" -y --from-path .
21-
enter-workspaces colcon build
22-
add-workspace "${REPO_PATH}/install/setup.bash"
92+
main "$@"

docs/about_template.md

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@ Here's a quick guide on the features of this template
3737

3838
### Things You Likely Want To Do
3939

40+
- **Create a new package**: It's recommended to just start by developing with the example package that comes with the
41+
template after generation. Once you're familiar with development with the template and want to create a second package,
42+
you can follow the steps under [Adding a New Package](#adding-a-new-package).
4043
- **Add new dependencies:**
41-
- **Python dependencies:** can be added under `pkgs/<package_name>/pyproject.toml`. Run `poetry lock` after.
42-
- **ROS dependencies:** can be added under `pkgs/<package_name>/package.xml`.
4344
- **System dependencies:** can be added under `docker/Dockerfile`, under the `install-packages` section.
45+
- **Python dependencies:** can be added under `pkgs/<package_name>/pyproject.toml`. Run `poetry lock` after.
46+
- **ROS dependencies:** can be added under `pkgs/<package_name>/package.xml`.
47+
- **ROS Git dependencies:** If you need to add a ROS package that isn't available in the ROS package index, you can add it as a git dependency in the `docker/Dockerfile` under the `Add Git ROS2 Packages` section.
4448

4549
After any changes, the container will automatically re-build on the next launch.
4650
- **Save persistent data:** The `/robot/persistent` directory is mounted to `.docker_volumes/ros-nodes/` on your local machine. Save data there to persist across container runs, and to view it in your file manager.
@@ -49,7 +53,34 @@ Here's a quick guide on the features of this template
4953
- Add a directory under `docker/launch-profiles/`
5054
- Add a `launching.py` file that launches your ROS nodes inside your new profile directory
5155
- Fill out the `launching.py` file with the nodes you want to launch.
52-
56+
- The directory you created will be mounted under `/robot/launch-profile/` at launch. This is a great place to store configuration files, URDFs, and other specifics for your launch profile.
57+
58+
59+
## Container Structure
60+
61+
### `/robot` Directory
62+
63+
The `/robot` directory is where your source code lives after building the container.
64+
You can find your:
65+
- `pkgs/` directory
66+
- `build/`, `install/` from the colcon build
67+
68+
### `/robot/launch-profile/` Directory
69+
A directory pointing towards the launch profile chosen in `docker/launch <launch profile>`
70+
is mounted under `/robot/launch-profile/`.
71+
72+
### `/robot/persistent/` Directory
73+
For saving persistent data, `/robot/persistent` is mounted to `.docker_volumes/ros-nodes/` on your local machine.
74+
This is a great place to save any serialized data, databases, etc. For static configuration,
75+
it's recommended to use the `launch-profile` directory.
76+
77+
### `/ros-git-deps/` Directory
78+
79+
In the `Dockerfile`, there's a section for adding ROS packages that aren't available in
80+
the ROS package index. These are added as git dependencies. The `ros-git-deps/`
81+
directory is where these packages are cloned to, and built.
82+
83+
5384
## Project Structure
5485

5586
### `pkgs/`
@@ -144,4 +175,21 @@ The `/robot/persistent` directory is intended for you, the developer, to use. So
144175

145176
The `.gitattributes` file is used to configure common binary file formats that are used in
146177
robots such that git uses Large File Storage (LFS) to store them. It also specified certain
147-
line endings so that docker support works on windows.
178+
line endings so that docker support works on windows.
179+
180+
# Adding a New Package
181+
182+
It's recommended to start by developing with the example package that comes with the
183+
template after generation. Once you're familiar with development with the template and want to create a second package,
184+
you can follow the steps below:
185+
186+
1. Create a new package directory under `pkgs/`
187+
2. Add a `package.xml` file to the package directory, follow the standard ROS2 package.xml format
188+
3. Create a pyproject.toml file. Follow the example in the `example_package` directory.
189+
4. Create a `resource` directory in the package directory, with an empty file in it called `{your package name}`
190+
5. Create a directory for your code in the package directory, and it's recommended to create a `{your_package_name}_test` directory as well.
191+
6. Add a few things to the Dockerfile:
192+
- Under the `Add package.xml's of each package` section, copy the `package.xml` file into the container
193+
- Under the `Add pyproject.toml's of each package` section, copy the `pyproject.toml` file into the container
194+
195+
You should be good to go! Next time you run `docker/launch`, your new package will be built and available in the container.

0 commit comments

Comments
 (0)