Skip to content

Commit

Permalink
Added Dockerfile.x86 for building a Docker image with CUDA and PyTorc…
Browse files Browse the repository at this point in the history
…h support.

Added build.sh script for building the Docker image.
Added run.sh script for launching a container from the Docker image.
Modified turtlesim_example.launch to accept an argument for the RViz configuration file.
Modified turtlesim_init.launch to include the turtlebot3_gazebo launch file and spawn the turtlebot3 model.
Modified requirements.txt to comment out the cupy package.
  • Loading branch information
mktk1117 committed Nov 23, 2023
1 parent b7a8f30 commit 2e36f82
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 6 deletions.
46 changes: 46 additions & 0 deletions docker/Dockerfile.x86
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
FROM nvidia/cuda:11.6.2-cudnn8-devel-ubuntu20.04

# Set noninteractive mode for apt-get
ENV DEBIAN_FRONTEND=noninteractive

# Preconfigure tzdata
RUN echo "Etc/UTC" > /etc/timezone && \
ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime && \
apt-get update && apt-get install -y tzdata && \
dpkg-reconfigure --frontend noninteractive tzdata

# Install Python
RUN apt-get update && apt-get install -y \
python3.8 \
python3-pip \
git

# Install PyTorch
RUN pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
COPY requirements.txt /tmp/requirements.txt
RUN pip3 install -r /tmp/requirements.txt

# Install other Python packages
RUN pip3 install cupy-cuda11x scikit-learn
RUN pip3 install 'git+https://github.com/facebookresearch/detectron2.git'

# Install ROS
RUN apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
RUN sh -c 'echo "deb http://packages.ros.org/ros/ubuntu focal main" > /etc/apt/sources.list.d/ros-latest.list'

RUN apt-get update && apt-get install -y --no-install-recommends \
ros-noetic-desktop-full

# Install ROS packages
RUN apt install -y ros-noetic-pybind11-catkin \
ros-noetic-grid-map-core ros-noetic-grid-map-msgs ros-noetic-grid-map-ros ros-noetic-grid-map-rviz-plugin \
libopencv-dev \
libeigen3-dev \
libgmp-dev \
libmpfr-dev \
libboost-all-dev \
ros-noetic-turtlebot3-gazebo ros-noetic-turtlebot3-teleop \
ros-noetic-ros-numpy

RUN pip3 install catkin-tools
ENV TURTLEBOT3_MODEL=waffle
3 changes: 3 additions & 0 deletions docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/bash
home=`realpath "$(dirname "$0")"/../`
cd $home && sudo docker build -t elevation_mapping_cupy -f docker/Dockerfile.x86 --no-cache .
49 changes: 49 additions & 0 deletions docker/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
IMAGE_NAME="elevation_mapping_cupy:latest"

# Define environment variables for enabling graphical output for the container.
XSOCK=/tmp/.X11-unix
XAUTH=/tmp/.docker.xauth
if [ ! -f $XAUTH ]
then
touch $XAUTH
xauth_list=$(xauth nlist :0 | sed -e 's/^..../ffff/')
xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -
chmod a+r $XAUTH
fi

#==
# Launch container
#==

# Create symlinks to user configs within the build context.
mkdir -p .etc && cd .etc
ln -sf /etc/passwd .
ln -sf /etc/shadow .
ln -sf /etc/group .
cd ..

# Launch a container from the prebuilt image.
echo "---------------------"
RUN_COMMAND="docker run \
--volume=$XSOCK:$XSOCK:rw \
--volume=$XAUTH:$XAUTH:rw \
--env="QT_X11_NO_MITSHM=1" \
--env="XAUTHORITY=$XAUTH" \
--env="DISPLAY=$DISPLAY" \
--ulimit rtprio=99 \
--cap-add=sys_nice \
--privileged \
--net=host \
-eHOST_USERNAME=$(whoami) \
-v$HOME:$HOME \
-v$(pwd)/.etc/shadow:/etc/shadow \
-v$(pwd)/.etc/passwd:/etc/passwd \
-v$(pwd)/.etc/group:/etc/group \
-v/media:/media \
--gpus all \
-it $IMAGE_NAME"
echo -e "[run.sh]: \e[1;32mThe final run command is\n\e[0;35m$RUN_COMMAND\e[0m."
$RUN_COMMAND
echo -e "[run.sh]: \e[1;32mDocker terminal closed.\e[0m"
# --entrypoint=$ENTRYPOINT \
3 changes: 2 additions & 1 deletion elevation_mapping_cupy/launch/turtlesim_example.launch
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>

<launch>
<arg name="rviz_config" default="$(find elevation_mapping_cupy)/rviz/turtle_example.rviz"/>

<!-- Launch elevation mapping turtle sim. -->
<include file="$(find elevation_mapping_cupy)/launch/turtlesim_init.launch">
<arg name="rviz_config" value="$(find elevation_mapping_cupy)/rviz/turtle_example.rviz"/>
<arg name="rviz_config" value="$(arg rviz_config)"/>
</include>

<node pkg="elevation_mapping_cupy" type="elevation_mapping_node" name="elevation_mapping" output="screen">
Expand Down
21 changes: 17 additions & 4 deletions elevation_mapping_cupy/launch/turtlesim_init.launch
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
<launch>
<arg name="use_sim_time" default="true"/>
<arg name="rviz_config" default="$(find elevation_mapping_cupy)/rviz/turtle_semantic_example.rviz"/>
<arg name="model" default="waffle" doc="model type [burger, waffle, waffle_pi]"/>
<arg name="x_pos" default="-2.0"/>
<arg name="y_pos" default="-0.5"/>
<arg name="z_pos" default="0.0"/>

<param name="/use_sim_time" type="bool" value="$(arg use_sim_time)"/>

<include file="$(find gazebo_ros)/launch/empty_world.launch">
<arg name="world_name" value="$(find turtlebot3_gazebo)/worlds/turtlebot3_world.world"/>
<arg name="paused" value="false"/>
<arg name="use_sim_time" value="true"/>
<arg name="gui" value="false"/>
<arg name="headless" value="false"/>
<arg name="debug" value="false"/>
</include>

<param name="robot_description" command="$(find xacro)/xacro --inorder $(find turtlebot3_description)/urdf/turtlebot3_$(arg model).urdf.xacro" />

<!-- Start gazebo simulation. -->
<include file="$(find turtlebot3_gazebo)/launch/turtlebot3_world.launch" />
<node pkg="gazebo_ros" type="spawn_model" name="spawn_urdf" args="-urdf -model turtlebot3_$(arg model) -x $(arg x_pos) -y $(arg y_pos) -z $(arg z_pos) -param robot_description" />

<!-- Publish turtlebot3 tf's. -->
<node pkg="robot_state_publisher" type="robot_state_publisher" name="waffle_state_publisher"/>


<node name="rviz" pkg="rviz" type="rviz" args="-d $(arg rviz_config)"/>
<node name="rviz" pkg="rviz" type="rviz" args="-d $(arg rviz_config)"/>

</launch>
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ opencv-python
simple-parsing
scikit-image
matplotlib
cupy
# cupy

###### Requirements with Version Specifiers ######`
shapely==1.7.1

0 comments on commit 2e36f82

Please sign in to comment.