diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..008f54c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,44 @@ +ARG BASE_IMAGE + +FROM ${BASE_IMAGE} + +# For this build, we pull the entire ros image, and then merge the filesystem +# with the nvidia/opengl image, so that displaying to the screen on GPU +# (or without GPU) works through docker. +# I was unable to use the ROS_DISTRO variable here due to this issue: +# https://github.com/docker/for-mac/issues/2155 +COPY --from=osrf/ros:kinetic-desktop-full / / + +# Add ROS env vars to the bashrc +ENV BASH_ENV="/root/launch.sh" +SHELL ["/bin/bash", "-c"] +ENTRYPOINT ["/bin/bash", "-c"] +ARG ROS_DISTRO +RUN echo "source /opt/ros/${ROS_DISTRO}/setup.bash" >> $BASH_ENV + +# Install build dependencies +RUN apt-get update && \ + apt-get install -y \ + # ROS Build dependencies + python-rosinstall \ + python-rosinstall-generator \ + python-wstool \ + build-essential \ + # Project-specific build dependencies + python-pip \ + ros-${ROS_DISTRO}-serial \ + ros-${ROS_DISTRO}-joint-state-publisher-gui && \ + rm -rf /var/lib/apt/lists/* + +# Install python dependencies +ARG PYMYCOBOT_VERSION +RUN pip install "pymycobot $PYMYCOBOT_VERSION" --user + +# Build the project +WORKDIR /catkin_ws/src +ADD . myCobotROS +WORKDIR /catkin_ws +RUN catkin_make + +# Let ROS know about the projects launch options +RUN echo "source /catkin_ws/devel/setup.bash" >> $BASH_ENV diff --git a/README.md b/README.md index 07f95ac..82a20d4 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,39 @@ Download ROS [http://wiki.ros.org/ROS/Installation](http://wiki.ros.org/ROS/Installation) -## 1. Installation -### 1.1 Pre-Requriements +## 1. Installation +### Option 1: Docker +There are two ways to run this project. The first is by running the project in a container, and this requires +[installing docker](https://docs.docker.com/engine/install/ubuntu/) and +[installing docker-compose](https://docs.docker.com/compose/install/). The benefit of running in the container is that you can run the project in any version of linux, as long as your kernel +is new enough. + +Once docker is installed, run the following command, and the project should show up: + +``` +docker-compose build ros && xhost +local:root && docker-compose up ros +``` + +This command does three things: +1) `docker-compose build ros` + + This builds the project in a container. That means nothing is installed on your host machine! + The first time this runs, this command will take a long while. After running it once, caching + will allow this command to run quickly. + +2) `xhost +local:root` + + This command gives X the ability to display GUI's from within the docker container + +3) `docker-compose up ros` + + This runs the image specified in the `docker-compose.yml`, which by default runs + the command `roslaunch myCobotROS control_slider.launch` within the container. + + +### Option 2: Local +#### 1.1 Pre-Requriements For using this package, the [Python api](https://github.com/elephantrobotics/pymycobot.git) library should be installed first. @@ -28,7 +58,7 @@ For using this package, the [Python api](https://github.com/elephantrobotics/pym pip install pymycobot --user ``` -### 1.2 Package Download and Install +#### 1.2 Package Download and Install Install ros package in your src folder of your Catkin workspace. @@ -39,7 +69,7 @@ $ cd ~/catkin_ws $ catkin_make ``` -### 1.3 Test Python API +#### 1.3 Test Python API ```bash cd ~/catkin_ws/src/myCobotROS diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e11f3fb --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,31 @@ +version: '3.4' + +x-app: &common + command: [ "roslaunch myCobotROS control_slider.launch" ] + privileged: true + environment: + PYTHONUNBUFFERED: 1 + QT_X11_NO_MITSHM: 1 + DISPLAY: :1 + volumes: + - "/tmp/.X11-unix:/tmp/.X11-unix:rw" + build: + context: . + args: &common-args + ROS_DISTRO: "kinetic" + PYMYCOBOT_VERSION: ">=2<3" + BASE_IMAGE: nvidia/opengl:1.1-glvnd-runtime-ubuntu18.04 + + +services: + # This configuration builds the project for computers with NVIDIA hardware + nvidia-ros: *common + + # This is the default for computers that don't have nvidia hardware accelerators + ros: + <<: *common + build: + context: . + args: + <<: *common-args + BASE_IMAGE: ubuntu:18.04