Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IK and Docker implementation #14

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build_files/
ddsconfig.xml/
**/.vscode/
148 changes: 148 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
FROM nvidia/cuda:11.8.0-devel-ubuntu22.04

ENV DEBIAN_FRONTEND noninteractive
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8

ARG DEBIAN_FRONTEND=noninteractive

#NVIDIA ENV
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES graphics,utility,compute
ENV QT_X11_NO_MITSHM 1

RUN apt-get update && apt-get -y --quiet --no-install-recommends install \
ant \
binutils-dev \
ca-certificates \
ccache \
cmake \
cppcheck \
curl \
dirmngr \
doxygen \
g++-multilib \
gcc-multilib \
gdb \
gettext \
git \
gnupg \
gosu \
lcov \
libelf-dev \
libexpat-dev \
libvecmath-java \
libfreetype6-dev \
libgmp-dev \
libgtest-dev \
libisl-dev \
libmpc-dev \
libmpfr-dev \
libpng-dev \
libssl-dev \
lsb-release \
make \
ninja-build \
openssh-client \
openjdk-11-jre \
openjdk-11-jdk \
python3 \
python3-dev \
python3-pip \
rsync \
screen \
shellcheck \
tzdata \
texinfo \
u-boot-tools \
util-linux \
unzip \
valgrind \
wget \
xsltproc \
zip \
&& apt-get -y autoremove \
&& apt-get clean autoclean \
&& rm -rf /var/lib/apt/lists/{apt,dpkg,cache,log} /tmp/* /var/tmp/*

RUN apt update

RUN apt install -y cmake

RUN apt update && apt install locales && locale-gen en_US en_US.UTF-8 && update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 && export LANG=en_US.UTF-8

RUN apt install software-properties-common -y

RUN add-apt-repository universe

# Install vcpkg dependencies
RUN apt install -y \
git \
curl \
zip \
unzip \
tar \
pkg-config \
freeglut3-dev \
libglew-dev \
libglfw3-dev \
libfftw3-dev \
libcgal-dev \
python3

# ROS KEY
RUN curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg

RUN 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

# GZ-SIM KEY and GZ-SIM8 Install
RUN wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg && \
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null && \
apt-get update && apt-get install -y \
&& rm -rf /var/lib/apt/lists/*

# ROS INSTALLATION WITH DEPENDENCIES
RUN apt update && apt-get install -y \
python-is-python3 \
nano \
less \
apt-utils \
python3-pip \
nlohmann-json3-dev \
git cmake python3-vcstools curl \
clang lldb lld wget lsb-release gnupg openssl \
ros-humble-desktop \
ros-humble-sdformat-urdf \
ros-humble-hardware-interface\
ros-humble-ros2-control\
ros-humble-ros2-controllers\
libgflags-dev \
ros-humble-xacro \
tmux \
ros-humble-rmw-cyclonedds-cpp \
ros-humble-ign-ros2-control\
lsb-release wget gnupg/

RUN sudo wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null
RUN sudo apt-get update
RUN sudo apt-get update
RUN sudo apt-get install lsb-release wget gnupg
RUN sudo wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null
RUN sudo apt-get update
RUN sudo apt-get install ignition-fortress


RUN echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc

RUN echo "source /workspaces/hexapod_ws/install/setup.bash" >> ~/.bashrc

RUN echo "alias docker_stop='docker stop hexapod atom'" >> ~/.bashrc

RUN apt update && apt install python3-colcon-common-extensions -y

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

# Command to run when starting the container
CMD /bin/bash
109 changes: 109 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/bin/bash

# Map host's display socket to docker
DOCKER_ARGS+=("-v /tmp/.X11-unix:/tmp/.X11-unix")
DOCKER_ARGS+=("-v $HOME/.Xauthority:/home/admin/.Xauthority:rw")
# DOCKER_ARGS+=("-e DISPLAY")
DOCKER_ARGS+=("-e NVIDIA_VISIBLE_DEVICES=all")
DOCKER_ARGS+=("-e NVIDIA_DRIVER_CAPABILITIES=all")
gpu=$(lspci | grep -i '.* vga .* nvidia .*')

# DOCKER_ARGS+=("-e FASTRTPS_DEFAULT_PROFILES_FILE=/usr/local/share/middleware_profiles/rtps_udp_profile.xml")

xhost +local:root

image_name="hexapod_image"
container_name="hexapod_atom"

# Initialize variables
force_option=false
clean_option=false


# Parse options
while [[ $# -gt 0 ]]; do
case "$1" in
--force)
force_option=true
shift
;;

--clean)
clean_option=true
shift
;;

*)
echo "Invalid option: $1"
exit 1
;;
esac
done


if $force_option; then
echo "Buidling Existing Docker Image: $image_name"
docker build -f Dockerfile -t "$image_name":1.0 .
# ./build_image.sh

else
run_command='source /opt/ros/humble/setup.bash && colcon build --symlink-install && source install/setup.bash && exit'

if $clean_option; then
run_command='source /opt/ros/humble/setup.bash && rm -rf build log install && colcon build --symlink-install && source install/setup.bash && exit'
echo "Force Command Enabled"

else
echo "Force Command Disabled"
fi


if docker images --format '{{.Repository}}' | grep -q "$image_name"; then

echo "Found Docker Image: $image_name:1.0"

echo "Updating the existing Docker image: $image_name:1.0"

if [[ $gpu == *'NVIDIA'* ]]; then
printf 'Nvidia GPU is present: %s\n' "$gpu"
docker run -it --rm \
${DOCKER_ARGS[@]} \
-e DISPLAY=$DISPLAY \
-v $PWD/build_files:/workspaces/hexapod_ws/ \
-v $PWD:/workspaces/hexapod_ws/src \
-v /var/run/docker.sock:/var/run/docker.sock \
--name "$container_name" \
--workdir /workspaces/hexapod_ws \
-v $PWD/ddsconfig.xml:/ddsconfig.xml \
--env CYCLONEDDS_URI=/ddsconfig.xml \
--runtime nvidia \
--network host \
$@ \
"$image_name":1.0 \
bash -c "$run_command"

else
printf 'Nvidia GPU is not present: %s\n' "$gpu"
docker run -it --rm \
-e DISPLAY=$DISPLAY \
-v $PWD/build_files:/workspaces/hexapod_ws/ \
-v $PWD:/workspaces/hexapod_ws/src \
-v /var/run/docker.sock:/var/run/docker.sock \
--name "$container_name" \
--workdir /workspaces/hexapod_ws \
-v $PWD/ddsconfig.xml:/ddsconfig.xml \
--env CYCLONEDDS_URI=/ddsconfig.xml \
--network host \
$@ \
"$image_name":1.0 \
bash -c "$run_command"
fi

else
echo "Building a new Docker image: $image_name"

docker build -f Dockerfile -t "$image_name":1.0 .
./build.sh
fi

fi
8 changes: 2 additions & 6 deletions hexapod_control/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ find_package(tf2_ros REQUIRED)
find_package(control_msgs REQUIRED)
find_package(rclcpp_action REQUIRED)
find_package(std_msgs REQUIRED)

find_package(rosidl_default_generators REQUIRED)


if(BUILD_TESTING)
Expand All @@ -43,14 +43,10 @@ install(

install(PROGRAMS
scripts/bot_controller.py

DESTINATION lib/${PROJECT_NAME}
)
install(PROGRAMS
scripts/controller_backup.py
scripts/position_subcriber.py

DESTINATION lib/${PROJECT_NAME}
)


ament_package()
Empty file.
2 changes: 2 additions & 0 deletions hexapod_control/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<depend>trajectory_msgs</depend>



<export>
Expand Down
Binary file not shown.
Loading