Skip to content
Open
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
60 changes: 34 additions & 26 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,60 +18,68 @@ FROM osrf/ros:${ROS_DISTRO}-desktop-full
ARG DEPENDENCIES=core_only
ENV DEBIAN_FRONTEND=noninteractive
# Increase timeout for Poetry requests.
ENV POETRY_REQUESTS_TIMEOUT=300

# Check whether the $DEPENDENCIES ARG has a valid value
RUN /bin/bash -c 'if [ "${DEPENDENCIES}" != "core_only" ] && [ "${DEPENDENCIES}" != "all_groups" ]; then \
echo Error: invalid DEPENDENCIES value. Valid values "core_only", "all_groups" && exit 1; \
fi'

ENV NVIDIA_VISIBLE_DEVICES=all \
NVIDIA_DRIVER_CAPABILITIES=all

# Install dependencies
RUN apt update && apt install -y \
python3 \
python3-pip \
git \
wget \
zip
zip \
libglu1-mesa-dev \
libxcb-xinerama0 \
libfontconfig1-dev \
libnvidia-gl-470 \
libxcb-xkb-dev \
libxkbcommon-x11-dev \
libxkbcommon-dev \
libxcb-xfixes0-dev \
libxcb-xinput-dev \
libxcb-xinput0 \
libpcre2-16-0 \
libunwind-dev

# Install Poetry
RUN curl -sSL https://install.python-poetry.org | python3 - --version 2.1.3
RUN --mount=type=cache,target=/root/.cache/pypoetry/cache curl -sSL https://install.python-poetry.org \
| python3 - --version 2.3.2

ENV PATH="/root/.local/bin:$PATH"

# Copy the RAI repository
COPY . /rai
WORKDIR /rai

# Set up the environment to use Fast DDS
ENV FASTRTPS_DEFAULT_PROFILES_FILE=/rai/docker/fastrtps_config.xml
ENV RMW_IMPLEMENTATION=rmw_fastrtps_cpp
ENV POETRY_REQUESTS_TIMEOUT=100 \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100

RUN /bin/bash -c 'if [ "${DEPENDENCIES}" = "core_only" ]; then \
poetry install; \

RUN --mount=type=cache,target=/root/.cache/pypoetry/cache \
--mount=type=cache,target=/root/.cache/pypoetry/artifacts \
/bin/bash -c 'if [ "${DEPENDENCIES}" = "core_only" ]; then \
poetry install -v; \
else \
poetry install --all-groups; \
poetry install --all-groups -v; \
fi'

# Install ROS dependencies
RUN /bin/bash -c '. /opt/ros/${ROS_DISTRO}/setup.bash && \
rosdep update && \
rosdep install --from-paths src --ignore-src -r -y'

# Build the workspace
RUN /bin/bash -c '. /opt/ros/${ROS_DISTRO}/setup.bash && colcon build --symlink-install'

# Install libraries required for GUI and NVIDIA support
RUN apt install -y \
libglu1-mesa-dev \
libxcb-xinerama0 \
libfontconfig1-dev \
libnvidia-gl-470 \
libxcb-xkb-dev \
libxkbcommon-x11-dev \
libxkbcommon-dev \
libxcb-xfixes0-dev \
libxcb-xinput-dev \
libxcb-xinput0 \
libpcre2-16-0 \
libunwind-dev

ENV NVIDIA_VISIBLE_DEVICES=all
ENV NVIDIA_DRIVER_CAPABILITIES=all
# Set up the environment to use Fast DDS
ENV FASTRTPS_DEFAULT_PROFILES_FILE=/rai/docker/fastrtps_config.xml
ENV RMW_IMPLEMENTATION=rmw_fastrtps_cpp
35 changes: 35 additions & 0 deletions docker/Dockerfile.manipulation-demo
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (C) 2024 Robotec.AI
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

ARG ROS_DISTRO=jazzy
FROM rai:${ROS_DISTRO}

# Import additional repos for demo
RUN vcs import < demos.repos

# Install ROS dependencies for newly imported repos
RUN /bin/bash -c '. /opt/ros/${ROS_DISTRO}/setup.bash && \
rosdep install --from-paths src --ignore-src -r -y'

RUN ./scripts/download_demo.sh manipulation

# Install all dependencies
RUN --mount=type=cache,target=/root/.cache/pypoetry/cache \
--mount=type=cache,target=/root/.cache/pypoetry/artifacts \
/bin/bash -c 'poetry install --with perception,simbench -v'

RUN /bin/bash -c '. /opt/ros/${ROS_DISTRO}/setup.bash && colcon build --symlink-install'

RUN /bin/bash -c ". setup_shell.sh && poetry run python src/rai_extensions/rai_perception/rai_perception/scripts/download_weights.py"
ENTRYPOINT ["bash", "-c", ". setup_shell.sh && streamlit run examples/manipulation-demo-streamlit.py \"$@\""]
36 changes: 17 additions & 19 deletions docs/demos/manipulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,46 +97,44 @@ manipulation techniques.

#### 1. Setting up the demo

1. Set up docker as outlined in the [docker setup guide](../setup/setup_docker.md). During the setup, build the docker image with all dependencies (i.e., use the `--build-arg DEPENDENCIES=all_groups` argument)
1. Set up docker as outlined in the [docker setup guide](../setup/setup_docker.md). Build base image with flag `DEPENDENCIES=core_only`

2. Enable X11 access for the docker container:
2. Build docker manipulation demo image:

```shell
xhost +local:root
docker build -t rai-manipulation-demo:jazzy --build-arg ROS_DISTRO=jazzy -f docker/Dockerfile.manipulation-demo .
```

3. Run the docker container with the following command:
3. Enable X11 access for the docker container:

```shell
docker run --net=host --ipc=host --pid=host -e ROS_DOMAIN_ID=$ROS_DOMAIN_ID -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix --gpus all -it rai:jazzy # or rai:humble
xhost +local:root
```

!!! tip "NVIDIA Container Toolkit"

In order to use the `--gpus all` flag, the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html) must be installed on the host machine.

4. (Inside the docker container) By default, RAI uses OpenAI as the vendor. Thus, it is necessary
to set the `$OPENAI_API_KEY` environmental variable. The command below may be utilized to set
the variable and add it to the container's `.bashrc` file:
4. Set the `$OPENAI_API_KEY` environment variable.

```shell
export OPENAI_API_KEY=YOUR_OPEN_AI_API_KEY
echo "export OPENAI_API_KEY=$OPENAI_API_KEY" >> ~/.bashrc
```

!!! note AI vendor change

The default vendor can be changed to a different provider via the [RAI configuration tool](../setup/install.md#15-configure-rai)

5. After this, follow the steps in the [Local Setup](#local-setup) from step 2 onwards.
5. Run the docker container with the following command:

!!! tip "New terminal in docker"
```shell
docker run -p 8501:8501 -e DISPLAY=$DISPLAY -e OPENAI_API_KEY=$OPENAI_API_KEY -v /tmp/.X11-unix:/tmp/.X11-unix --gpus all -it rai-manipulation-demo:jazzy # or rai-manipulation-demo:humble
```

!!! tip "NVIDIA Container Toolkit"

In order to open a new terminal in the same docker container, you can use the following command:
In order to use the `--gpus all` flag, the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html) must be installed on the host machine.

```shell
docker exec -it <container_id> bash
```
6. To access the demo web interface, open your web browser and navigate to :
```
http://localhost:8501
```

## How it works

Expand Down
5 changes: 2 additions & 3 deletions docs/setup/setup_docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,18 @@ To allow the container to communicate with the host machine, configure the host
### 3.1. Humble

```bash
docker run --net=host --ipc=host --pid=host -e ROS_DOMAIN_ID=$ROS_DOMAIN_ID -it rai:humble
docker run -e ROS_DOMAIN_ID=$ROS_DOMAIN_ID -it rai:humble
```

### 3.2. Jazzy

```bash
docker run --net=host --ipc=host --pid=host -e ROS_DOMAIN_ID=$ROS_DOMAIN_ID -it rai:jazzy
docker run -e ROS_DOMAIN_ID=$ROS_DOMAIN_ID -it rai:jazzy
```

## 4. Run the tests to confirm the setup

```sh
cd /rai
source setup_shell.sh
poetry run pytest tests/{agents,messages,tools,types}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (C) 2025 Robotec.AI
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging

from rai_perception.services.detection_service import DetectionService
from rai_perception.services.segmentation_service import SegmentationService
from rai_perception.services.weights import download_weights

SERVICES = [DetectionService, SegmentationService]

if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

for service_class in SERVICES:
weights_path = (
service_class.DEFAULT_WEIGHTS_ROOT_PATH
/ service_class.WEIGHTS_DIR_PATH_PART
/ service_class.WEIGHTS_FILENAME
)
weights_path.parent.mkdir(parents=True, exist_ok=True)
if not weights_path.exists():
download_weights(weights_path, logger, service_class.WEIGHTS_URL)
else:
logger.info(f"Weights already exist at {weights_path}, skipping download.")
Loading