diff --git a/.gitignore b/.gitignore index a3062be..168374a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,54 @@ .vscode/* +build_files/* + +devel/ +logs/ +build/ +bin/ +lib/ +msg_gen/ +srv_gen/ +msg/*Action.msg +msg/*ActionFeedback.msg +msg/*ActionGoal.msg +msg/*ActionResult.msg +msg/*Feedback.msg +msg/*Goal.msg +msg/*Result.msg +msg/_*.py +build_isolated/ +devel_isolated/ + +# Generated by dynamic reconfigure +*.cfgc +/cfg/cpp/ +/cfg/*.py + +# Ignore generated docs +*.dox +*.wikidoc + +# eclipse stuff +.project +.cproject + +# qcreator stuff +CMakeLists.txt.user + +srv/_*.py +*.pcd +*.pyc +qtcreator-* +*.user + +/planning/cfg +/planning/docs +/planning/src + +*~ + +# Emacs +.#* + +# Catkin custom files +CATKIN_IGNORE \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0c33603 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +FROM osrf/ros:noetic-desktop-full + +SHELL ["/bin/bash","-c"] + +RUN echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc +RUN echo "source /workspaces/mr_robo_ws/devel/setup.bash" >> ~/.bashrc +RUN echo "source /usr/share/gazebo-11/setup.sh" >> ~/.bashrc +RUN echo "export LIBGL_ALWAYS_SOFTWARE=1" >> ~/.bashrc + + +RUN apt-get update + +RUN apt-get install --no-install-recommends -yqqq \ + python3-pip + +RUN pip3 install ultralytics +RUN apt-get install --no-install-recommends -yqqq \ + tmux \ + libfreenect-dev + + +RUN apt-get install --no-install-recommends -yqqq \ + ros-noetic-turtlebot3-gazebo\ + ros-noetic-turtlebot3-description\ + ros-noetic-turtlebot3-navigation\ + ros-noetic-ros-control \ + ros-noetic-gazebo-ros-pkgs \ + libopencv-dev \ + python3-opencv \ + ros-noetic-map-server \ + ros-noetic-move-base \ + ros-noetic-amcl \ + libgazebo11-dev \ + ros-noetic-rgbd-launch + +RUN mkdir -p /workspaces/mr_robo_ws/src + +RUN rm -rf /var/lib/apt/lists/* \ +&& apt-get clean + +CMD ["sleep", "infinity"] \ No newline at end of file diff --git a/build_image.sh b/build_image.sh new file mode 100755 index 0000000..9d5ca92 --- /dev/null +++ b/build_image.sh @@ -0,0 +1,89 @@ +#!/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") +# DOCKER_ARGS+=("-e FASTRTPS_DEFAULT_PROFILES_FILE=/usr/local/share/middleware_profiles/rtps_udp_profile.xml") + +xhost +local:root + +image_name="mr_robot_docker" +container_name="mr_robot_docker_build" + +# 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/noetic/setup.bash && catkin_make && source devel/setup.bash && exit' + + if $clean_option; then + run_command='source /opt/ros/noetic/setup.bash && rm -rf build devel && catkin_make && source devel/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" + + docker run -it --rm=false \ + --privileged \ + ${DOCKER_ARGS[@]} \ + -e DISPLAY=$DISPLAY \ + -v $PWD/build_files:/workspaces/mr_robo_ws/ \ + -v $PWD:/workspaces/mr_robo_ws/src \ + -v /etc/localtime:/etc/localtime:ro \ + --name "$container_name" \ + --runtime nvidia \ + --workdir /workspaces/mr_robo_ws \ + $@ \ + "$image_name":1.0 \ + bash -c "$run_command" + + docker rm "$container_name" + + # ./run_image.sh + + else + echo "Building a new Docker image: $image_name" + docker build -f Dockerfile -t "$image_name":1.0 . + ./build_image.sh + fi + +fi \ No newline at end of file diff --git a/mr_robot_description/package.xml b/mr_robot_description/package.xml index 594d3d2..465257f 100644 --- a/mr_robot_description/package.xml +++ b/mr_robot_description/package.xml @@ -7,7 +7,7 @@ - syuntoku14 + singh diff --git a/run_image.sh b/run_image.sh new file mode 100755 index 0000000..32a4492 --- /dev/null +++ b/run_image.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# Map host's display socket to Docker +DOCKER_ARGS+=("-v $HOME/.Xauthority:/home/admin/.Xauthority:rw") +DOCKER_ARGS+=("-e DISPLAY") +DOCKER_ARGS+=("-e LIBGL_ALWAYS_SOFTWARE=1") # Enable software rendering by default + +xhost +local:root +image_name="mr_robot_docker" +container_name="mr_robot_docker_build" + +# Check if NVIDIA GPU is available +if command -v nvidia-smi &>/dev/null && nvidia-smi -L &>/dev/null; then + echo "NVIDIA GPU detected. Configuring for NVIDIA runtime..." + DOCKER_ARGS+=("--runtime=nvidia") + DOCKER_ARGS+=("-e NVIDIA_VISIBLE_DEVICES=all") + DOCKER_ARGS+=("-e NVIDIA_DRIVER_CAPABILITIES=all") +else + echo "No NVIDIA GPU detected. Configuring for software rendering..." + DOCKER_ARGS+=("-e LIBGL_ALWAYS_SOFTWARE=1") # Ensure software rendering +fi + +# Check if container is already running +if docker ps --format '{{.Names}}' | grep -q "$container_name"; then + docker exec -it $container_name /bin/bash +else + docker run -it --rm \ + ${DOCKER_ARGS[@]} \ + -e DISPLAY=$DISPLAY \ + -v /tmp/.X11-unix:/tmp/.X11-unix \ + -v $PWD/build_files:/workspaces/mr_robo_ws/ \ + -v $PWD:/workspaces/mr_robo_ws/src \ + -v /etc/localtime:/etc/localtime:ro \ + --name "$container_name" \ + --workdir /workspaces/mr_robo_ws \ + "$image_name":1.0 \ + /bin/bash +fi