From 57e0a71ae2abac6909cd7a06d860f57e3d3d0205 Mon Sep 17 00:00:00 2001
From: rschoene <rene.schoene@tu-dresden.de>
Date: Wed, 20 Jul 2022 19:10:15 +0200
Subject: [PATCH] description of setup, latest working setup and web-ui

---
 README.md                         | 54 ++++++++++++++++-----------
 docker-compose.yml                | 61 +++----------------------------
 robotic-controller/Dockerfile-vnc | 60 +++++-------------------------
 robotic-controller/vnc/run1.sh    |  1 +
 robotic-controller/vnc/run2.sh    |  1 +
 web-ros3rag                       |  2 +-
 6 files changed, 52 insertions(+), 127 deletions(-)

diff --git a/README.md b/README.md
index 7e8593e..3f4eb4e 100644
--- a/README.md
+++ b/README.md
@@ -1,35 +1,47 @@
 # Artifact for the paper "Incremental Causal Connection for Self-Adaptive Systems Based on Relational Reference Attribute Grammars"
 
-## Docker
+## Installation and Preparation
 
-To quickly run the graphical example applications, you can use Docker.
+To quickly run the graphical example applications, Docker is used.
 Please note that the setup uses vnc and thus offers limited graphics performance.
 
-:warning: TODO: check what is needed for VNC setup, and check everything labelled with "(OLD)"
-
 - Install Docker and docker-compose for your system (for Windows and Mac OS, install Docker Desktop)
-- (OLD) Build the container `docker build --tag cgvsim .`
-- (OLD) Run the container: `docker run -it -p 6080:80 --rm cgvsim`. A webserver is run inside the container that is exposed to port `6080` on your system.
-- (OLD) Open `http://localhost:6080` in a web browser
-
-## Installation and Preparation
-
-- Clone this repo and its submodules:
+- Clone this repo and its submodules (**Important**: Use `--recurse-submodules`):
     - `git clone --recurse-submodules https://git-st.inf.tu-dresden.de/ceti/ros/models2022.git models2022`
-    - (as a project member with a registered ssh key: `git clone --recurse-submodules git@git-st.inf.tu-dresden.de:ceti/ros/models2022.git models2022`)
-    - change into the workspace `cd models2022`
-- Prepare/Build all docker images: `docker-compose build`
+    - Change into the workspace `cd models2022`
+    - Prepare/Build all docker images: `docker-compose build` (this will take a while)
 
 ## Running the Case Study
 
-- (Optional) Use the Web UI to observe MQTT message and view the runtime model of place B
-    - `docker-compose up -d web_rag`
-    - Open your browser at <http://0.0.0.0:8050/>
-- (OLD) Start the case study
-    - (OLD) `docker-compose up [-d] coordinator` (the `-d` flag is optional to run the coordinator in the background)
+- Start the following containers (best to use different terminal tabs/windows):
+    - `docker-compose up web`
+    - `docker-compose up rag_place_a`
+    - `docker-compose up rag_place_b`
+    - `docker-compose up ros_place_b1`
+    - `docker-compose up ros_place_b2`
+- Open the Web-UI for the RAG application
+    - <http://localhost:8050/>
+    - This UI offers various controls (only a few are needed to control the case study), a filtered MQTT log, and a second tab to view the runtime model (see below)
+    - Start the RAG application for place B, hit "Start" in the (rightmost) section "*Commands Place B*"
+    - You should then see a message with "ready" for the topic "coordinating/rag-b/status" (in a line like `[<datetime> @ coordinating/rag-b/status ] ready`)
+- Open VNC using your browser to start the two robots
+    - <http://localhost:6081/> (First robot)
+    - <http://localhost:6082/> (Second robot)
+    - You should see a desktop environment with four desktop entries
+    - Right-click on "ros_ws" desktop entry -> "Open in terminal". A terminal window should open in directory "~/Desktop"
+    - Start the controller using either `./run1.sh` (for the first robot) or `./run2.sh` (for the second robot)
+    - You should see some log output in the terminal and the visualization program (RViz) for the respective robot should open
+- Back in the Web-UI for the RAG application
+    - You should see messages for the topics `/ceti_cell_placeworld/scene/update` and `/ceti_cell_placeworld2/scene/update`
+    - Start the RAG application for place A, hit "Start" in the (middle) section "*Commands Place A*"
+    - Then the case study begins, you should see a "ready" for the topic "coordinating/rag-a/status" and the first commands sent. Also the two robots should start to move executing their command. From then on, observe the mqtt messages sent and/or the robots moving
+- View the RAG runtime model
+    - While the case study runs or after it is finished, you can view the runtime state in the tab named "*SVG Model B*"
+    - After starting the RAG application for place B, the initial state is displayed
+    - To "request" a new model, hit the button "Model" in section "*Commands Place B*". This will both print the model (in the lower MQTT log) and create a visualization shown in the tab "*SVG Model B*"
 
 ## Experiment with RagConnect
 
--> Still TODO
+-> Still TODO (update ragconnect minimal example)
 
-To experiment with a less complex scenario and verify the functionality of the tool RagConnect itself, you can use the 
+To experiment with a less complex scenario and verify the functionality of the tool RagConnect itself, you can use the minimal example provided at <https://git-st.inf.tu-dresden.de/jastadd/ragconnect-minimal>.
diff --git a/docker-compose.yml b/docker-compose.yml
index 1a55769..e5c90e1 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,71 +1,23 @@
 version: '3'
 services:
-  # ros_core:
-  #   build: "robotic-controller"
-  #   user: "user"
-  #   command: ['roscore']
-
-  # ros_place_a:
-  #   build: "robotic-controller"
-  #   user: "user"
-  #   # TODO: update command
-  #   command: ['rosrun', 'cgv_connector', 'dummy_rag_connector']
-
   ros_place_b1:
-    # build: "robotic-controller"
     build:
       context: robotic-controller
       dockerfile: Dockerfile-vnc
-    # command: ['roslaunch', 'ccf_immersive_sorting', 'noop-sim-cell_ceti-table-1-placeworld.launch']
-    # command: ['roslaunch', 'ccf_immersive_sorting', 'noop-sim-cell_ceti-table-1-placeworld.launch', 'use_rviz:=false', 'mqtt_server:="tcp://mosquitto:1883"']
-    # deploy:
-    #   resources:
-    #     limits:
-    #       cpus: '0.50'
-    #       memory: 2G
     volumes:
-      # - "/tmp/.X11-unix:/tmp/.X11-unix:rw"
-      # - "/tmp/.docker.xauth:/tmp/.docker.xauth:rw"
       - "./ros_place_b1_logs/:/home/root/.ros/log"
-    # environment:
-    #   - "XAUTHORITY=/tmp/.docker.xauth"
-    #   - "DISPLAY=$DISPLAY"
-    # devices:
-    #   - "/dev/dri"
-    # user: "user"
     ports:
       - "6081:80"
 
   ros_place_b2:
-    build: "robotic-controller"
-    # command: ['roslaunch', 'ccf_immersive_sorting', 'noop-sim-cell_ceti-table-2-placeworld.launch']
-    # deploy:
-    #   resources:
-    #     limits:
-    #       cpus: '0.50'
-    #       memory: 2G
+    build:
+      context: robotic-controller
+      dockerfile: Dockerfile-vnc
     volumes:
-      # - "/tmp/.X11-unix:/tmp/.X11-unix:rw"
-      # - "/tmp/.docker.xauth:/tmp/.docker.xauth:rw"
       - "./ros_place_b2_logs/:/home/root/.ros/log"
-    # environment:
-    #   - "XAUTHORITY=/tmp/.docker.xauth"
-    #   - "DISPLAY=$DISPLAY"
-    # devices:
-    #   - "/dev/dri"
-    # user: "user"
     ports:
       - "6082:80"
 
-  coordinator:
-    privileged: true
-    build: coordinator
-    volumes:
-      # - "./coordinator/examples/ros3rag.coordinator:/config.coordinator"
-      - "./config/ros3rag.coordinator:/config.coordinator"
-    # TODO: remove --dry-run
-    entrypoint: ["/bin/bash", "-c", "./build/install/coordinator/bin/coordinator /config.coordinator --dry-run"]
-
   rag_place_a:
     build: ros3rag
     environment:
@@ -80,7 +32,7 @@ services:
       - "TARGET=ros3rag.placeB"
       - "CONFIG_FILE=/ros3rag/config-b-docker.yaml"
     volumes:
-      - "./shared_directory_images:/ros3rag/ros3rag.placeB/images"
+      - "./shared_directory_images:/ros3rag/images"
       - "./config/config-b-docker.yaml:/ros3rag/config-b-docker.yaml"
 
   web:
@@ -90,6 +42,8 @@ services:
       - "./config/web-config.yaml:/app/config.yaml"
     ports:
       - "8050:8050"
+    depends_on:
+      - mosquitto
 
   mosquitto:
     image: eclipse-mosquitto
@@ -97,6 +51,3 @@ services:
     restart: unless-stopped
     volumes:
       - ./config/mosquitto.conf:/mosquitto/config/mosquitto.conf
-    # ports:
-    #   - "41883:1883"
-    #   - "49001:9001"
diff --git a/robotic-controller/Dockerfile-vnc b/robotic-controller/Dockerfile-vnc
index 101df31..3585272 100644
--- a/robotic-controller/Dockerfile-vnc
+++ b/robotic-controller/Dockerfile-vnc
@@ -3,61 +3,23 @@ FROM dorowu/ubuntu-desktop-lxde-vnc:focal
 # Get public key for google
 RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
 
-# Fix dirmngr
-RUN apt-get purge dirmngr -y && apt-get update && apt-get install dirmngr -y
-
 # Adding keys for ROS
 RUN sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
 RUN sed -i 's/^deb/deb [trusted=yes]/' /etc/apt/sources.list.d/ros-latest.list
 
-# Installing ROS
-# RUN apt-get update && apt-get install -y ros-melodic-desktop-full wget nano python-rosdep
-# RUN apt-get install -y \
-      # ros-melodic-libfranka python-catkin-tools libeigen3-dev 
-RUN apt-get update && apt-get install -y \
-    ros-noetic-ros-core=1.5.0-1* \
+# Installing ROS components (and some rosdep dependencies manually to speed up process)
+RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y \
+    nano vim \
     python3-osrf-pycommon \
     python3-catkin-tools \
     build-essential \
     protobuf-compiler \
     libprotobuf-dev \
     python3-rosdep \
-    ca-certificates
-
-# update rosdep dependencies manually to speed up process
-RUN apt-get update && apt-get install -y \
-    # ros-noetic-gazebo-msgs \
-    libsdformat9-dev \
-    # ros-noetic-gazebo-ros \
-    ros-noetic-xacro \
-    ros-noetic-tf2 \
-    ros-noetic-moveit-ros-planning-interface \
-    ros-noetic-franka-gripper \
-    ros-noetic-controller-manager \
-    ros-noetic-effort-controllers \
-    # ros-noetic-gazebo-plugins \
-    # ros-noetic-gazebo-ros-control \
-    ros-noetic-joint-state-controller \
-    ros-noetic-joint-state-publisher \
-    ros-noetic-joint-trajectory-controller \
-    ros-noetic-robot-state-publisher \
-    ros-noetic-tf \
-    ros-noetic-moveit-simple-controller-manager \
-    ros-noetic-moveit-core \
-    ros-noetic-moveit-ros-perception \
-    ros-noetic-moveit-visual-tools \
-    ros-noetic-controller-interface \
-    ros-noetic-hardware-interface \
-    ros-noetic-moveit-ros-move-group \
-    ros-noetic-moveit-fake-controller-manager \
-    ros-noetic-moveit-kinematics \
-    ros-noetic-moveit-planners-ompl \
-    ros-noetic-moveit-ros-visualization \
-    ros-noetic-joint-state-publisher-gui \
+    ca-certificates \
     libnng1 \
-    libnng-dev
-
-RUN apt-get dist-upgrade -y
+    libnng-dev \
+    && rm -rf /var/lib/apt/lists/*
 
 # create initial workspace and desktop dir
 RUN mkdir -p /root/workspace /root/Desktop/
@@ -73,18 +35,19 @@ WORKDIR /root/workspace
 COPY ./src /root/workspace/src
 
 # initialize dependencies
-RUN rosdep init && rosdep update && rosdep install --from-paths /root/workspace/ -i -r -y
+RUN apt-get update && rosdep init && rosdep update && rosdep install --from-paths /root/workspace/ -i -y && rm -rf /var/lib/apt/lists/*
 
 # build
 RUN /bin/bash -c "source /opt/ros/noetic/setup.bash && catkin build"
 
-# setup script to run for each bash (sourcing workspace and cd into it)
+# setup script to run for each bash (limit file descriptors, sourcing workspace and cd into Desktop dir)
+# see https://answers.ros.org/question/336963/rosout-high-memory-usage/?answer=340381#post-id-340381
 RUN /bin/bash -c "echo -e 'umask 000\n \
       ulimit -Sn 1024\n \
       ulimit -Hn 524288\n \
       source /opt/ros/noetic/setup.bash\n \
       source /root/workspace/devel/setup.bash\n \
-      cd /root/Desktop/ros_ws/\n' >> /root/.bashrc "
+      cd /root/Desktop/\n' >> /root/.bashrc "
 
 # create working workspace
 RUN mkdir -p /root/Desktop/ros_ws
@@ -93,9 +56,6 @@ RUN mkdir -p /root/Desktop/ros_ws
 COPY vnc/copyws.sh /root/copyws.sh
 RUN chmod a+x /root/copyws.sh
 
-# limit file descriptors, see https://answers.ros.org/question/336963/rosout-high-memory-usage/?answer=340381#post-id-340381
-COPY vnc/30-nofilelimit.conf /etc/security/limits.d/30-nofilelimit.conf
-
 # prepare run scripts
 COPY vnc/run1.sh /root/Desktop/run1.sh
 COPY vnc/run2.sh /root/Desktop/run2.sh
diff --git a/robotic-controller/vnc/run1.sh b/robotic-controller/vnc/run1.sh
index fc80153..9bd3932 100644
--- a/robotic-controller/vnc/run1.sh
+++ b/robotic-controller/vnc/run1.sh
@@ -1,4 +1,5 @@
 #!/bin/bash
+pkill menu-cached
 source /opt/ros/noetic/setup.bash
 source /root/workspace/devel/setup.bash
 roslaunch ccf_immersive_sorting noop-sim-cell_ceti-table-1-placeworld.launch mqtt_server:=tcp://mosquitto:1883
diff --git a/robotic-controller/vnc/run2.sh b/robotic-controller/vnc/run2.sh
index c809408..3426ea0 100644
--- a/robotic-controller/vnc/run2.sh
+++ b/robotic-controller/vnc/run2.sh
@@ -1,4 +1,5 @@
 #!/bin/bash
+pkill menu-cached
 source /opt/ros/noetic/setup.bash
 source /root/workspace/devel/setup.bash
 roslaunch ccf_immersive_sorting noop-sim-cell_ceti-table-2-placeworld.launch mqtt_server:=tcp://mosquitto:1883
diff --git a/web-ros3rag b/web-ros3rag
index d51a74f..a82654a 160000
--- a/web-ros3rag
+++ b/web-ros3rag
@@ -1 +1 @@
-Subproject commit d51a74f17e25baf54b50b280b99037fe4934241c
+Subproject commit a82654a868d585be3b3b9af33d3c82c28bc216a8
-- 
GitLab