From aa129c6dab31285ed659fa0e5aa68dc118f911d2 Mon Sep 17 00:00:00 2001 From: Sebastian Nimpsch Date: Fri, 1 Jan 2021 19:28:32 +0100 Subject: [PATCH 1/3] Adds docker files for gqccn in ros --- docker/ros/Dockerfile.ros | 42 ++++++++++++++++++++++++++++ docker/ros/config.env | 6 ++++ docker/ros/docker-compose.yml | 48 ++++++++++++++++++++++++++++++++ ros_nodes/grasp_planner_node.py | 2 +- scripts/docker/run_docker_ros.sh | 42 ++++++++++++++++++++++++++++ 5 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 docker/ros/Dockerfile.ros create mode 100644 docker/ros/config.env create mode 100644 docker/ros/docker-compose.yml create mode 100755 scripts/docker/run_docker_ros.sh diff --git a/docker/ros/Dockerfile.ros b/docker/ros/Dockerfile.ros new file mode 100644 index 00000000..8cb6219a --- /dev/null +++ b/docker/ros/Dockerfile.ros @@ -0,0 +1,42 @@ +FROM ros:noetic-ros-core + +ARG cpu_or_gpu + +RUN apt-get update && apt-get install --no-install-recommends -y \ + software-properties-common \ + build-essential \ + curl \ + libsm6 \ + libxext6 \ + libglib2.0-0 \ + libxrender1 \ + wget \ + libpng-dev \ + pkg-config \ + libfreetype6-dev \ + ros-noetic-cv-bridge \ + freeglut3-dev \ + unzip + +RUN add-apt-repository ppa:deadsnakes/ppa + +RUN apt-get update && apt-get -y install \ + python3.7 \ + python3.7-dev \ + python3-pip \ + python3.7-tk + +RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1 +RUN python3.7 -m pip install --no-cache-dir --upgrade setuptools pip wheel numpy netifaces pyglet pycryptodomex crypto + +RUN /bin/bash -c "mkdir -p /root/catkin_ws/src" +ENV CATKIN_WS /root/catkin_ws + +WORKDIR $CATKIN_WS + +COPY [ "gqcnn/", "$CATKIN_WS/src/gqcnn/" ] + +RUN python3 -m pip install --no-cache-dir -r $CATKIN_WS/src/gqcnn/requirements/${cpu_or_gpu}_requirements.txt + +RUN /bin/bash -c "source /opt/ros/noetic/setup.bash \ + && catkin_make install -DCMAKE_INSTALL_PREFIX=/opt/ros/noetic/" diff --git a/docker/ros/config.env b/docker/ros/config.env new file mode 100644 index 00000000..60954d6c --- /dev/null +++ b/docker/ros/config.env @@ -0,0 +1,6 @@ +export COMPOSE_PROJECT_NAME=berkeley_automation +export HOST_IP=127.0.0.1 +export ROS_MASTER_URI=http://${HOST_IP}:11311 +export ROS_IP=${HOST_IP} +export MODEL=GQCNN-4.0-PJ +export cpu_or_gpu=cpu # or gpu diff --git a/docker/ros/docker-compose.yml b/docker/ros/docker-compose.yml new file mode 100644 index 00000000..54832db9 --- /dev/null +++ b/docker/ros/docker-compose.yml @@ -0,0 +1,48 @@ +version: '3.4' + +services: + ros_master: + image: ros:kinetic-ros-core + network_mode: host + environment: + - ROS_MASTER_URI=${ROS_MASTER_URI} + - ROS_IP=${ROS_IP} + command: stdbuf -o L roscore + + gqcnn: + image: gqcnn_${cpu_or_gpu}:latest + build: + args: + cpu_or_gpu: $cpu_or_gpu + context: ../../../ + dockerfile: gqcnn/docker/ros/Dockerfile.ros + network_mode: host + environment: + - ROS_MASTER_URI=${ROS_MASTER_URI} + - ROS_IP=${ROS_IP} + volumes: + - ../../../gqcnn/:/root/catkin_ws/src/gqcnn/:ro + depends_on: + - ros_master + command: "bash -c 'source /root/catkin_ws/devel/setup.bash; roslaunch --wait gqcnn grasp_planning_service.launch model_name:=${MODEL};'" + + + #gqcnn_example: + # image: gqcnn_${cpu_or_gpu}:latest + # build: + # args: + # cpu_or_gpu: $cpu_or_gpu + # context: ../../../ + # dockerfile: gqcnn/docker/ros/Dockerfile.ros + # network_mode: host + # environment: + # - DISPLAY=$DISPLAY + # - ROS_MASTER_URI=${ROS_MASTER_URI} + # - ROS_IP=${ROS_IP} + # volumes: + # - ../../../gqcnn/:/root/catkin_ws/src/gqcnn/:ro + # - /tmp/.X11-unix:/tmp/.X11-unix:ro + # - $HOME/.Xauthority:/.Xauthority:ro + # depends_on: + # - gqcnn + # command: "bash -c 'source /root/catkin_ws/devel/setup.bash; python3 /root/catkin_ws/src/gqcnn/examples/policy_ros.py'" diff --git a/ros_nodes/grasp_planner_node.py b/ros_nodes/grasp_planner_node.py index 56729073..de9b1e9d 100755 --- a/ros_nodes/grasp_planner_node.py +++ b/ros_nodes/grasp_planner_node.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Copyright ©2017. The Regents of the University of California (Regents). diff --git a/scripts/docker/run_docker_ros.sh b/scripts/docker/run_docker_ros.sh new file mode 100755 index 00000000..b58a3fc9 --- /dev/null +++ b/scripts/docker/run_docker_ros.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Copyright ©2017. The Regents of the University of California (Regents). +# All Rights Reserved. Permission to use, copy, modify, and distribute this +# software and its documentation for educational, research, and not-for-profit +# purposes, without fee and without a signed licensing agreement, is hereby +# granted, provided that the above copyright notice, this paragraph and the +# following two paragraphs appear in all copies, modifications, and +# distributions. Contact The Office of Technology Licensing, UC Berkeley, 2150 +# Shattuck Avenue, Suite 510, Berkeley, CA 94720-1620, (510) 643-7201, +# otl@berkeley.edu, +# http://ipira.berkeley.edu/industry-info for commercial licensing opportunities. + +# IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, +# INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF +# THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED +# HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE +# MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + +# Run the docker CPU image. + +function ctrl_c() { + #handle ctl+C + xhost -local:docker +} +ctrl_c + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +echo $SCRIPT_DIR +cd $SCRIPT_DIR +cd ../../.. +source ./gqcnn/docker/ros/config.env + +xhost +local:docker +#docker-compose -f gqcnn/docker/ros/docker-compose.yml build --no-cache --parellel +docker-compose -f gqcnn/docker/ros/docker-compose.yml up +xhost -local:docker From cef7aa1b83bc9d58db1f237f82c40fa53fe91df6 Mon Sep 17 00:00:00 2001 From: nimpsch Date: Sat, 2 Jan 2021 14:46:46 +0100 Subject: [PATCH 2/3] removes debug echo, typo --- scripts/docker/run_docker_ros.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/docker/run_docker_ros.sh b/scripts/docker/run_docker_ros.sh index b58a3fc9..3cd98341 100755 --- a/scripts/docker/run_docker_ros.sh +++ b/scripts/docker/run_docker_ros.sh @@ -31,12 +31,12 @@ function ctrl_c() { ctrl_c SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -echo $SCRIPT_DIR + cd $SCRIPT_DIR cd ../../.. source ./gqcnn/docker/ros/config.env xhost +local:docker -#docker-compose -f gqcnn/docker/ros/docker-compose.yml build --no-cache --parellel +#docker-compose -f gqcnn/docker/ros/docker-compose.yml build --no-cache --parallel docker-compose -f gqcnn/docker/ros/docker-compose.yml up xhost -local:docker From 08b76e2a4109998332776704902644ba956c62f3 Mon Sep 17 00:00:00 2001 From: nimpsch <48222352+nimpsch@users.noreply.github.com> Date: Wed, 6 Jan 2021 08:20:52 +0100 Subject: [PATCH 3/3] Update run_docker_ros.sh --- scripts/docker/run_docker_ros.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/docker/run_docker_ros.sh b/scripts/docker/run_docker_ros.sh index 3cd98341..8f08e80c 100755 --- a/scripts/docker/run_docker_ros.sh +++ b/scripts/docker/run_docker_ros.sh @@ -29,6 +29,7 @@ function ctrl_c() { xhost -local:docker } ctrl_c +trap ctrl_c INT SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"