From bc9b9158138173c4dd95b17880d669c99fae2e83 Mon Sep 17 00:00:00 2001 From: Tom Meulenkamp <39053610+supertom01@users.noreply.github.com> Date: Sun, 27 Aug 2023 16:55:47 +0200 Subject: [PATCH 01/10] Update doxy-action.yml It does not make sense to generate doxygen documentation for a PR. You only want to have documentation available for the current main branch. This can simply be updated on a push to the main branch. --- .github/workflows/doxy-action.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/doxy-action.yml b/.github/workflows/doxy-action.yml index 3acf6d44c..a45989ad8 100644 --- a/.github/workflows/doxy-action.yml +++ b/.github/workflows/doxy-action.yml @@ -9,8 +9,6 @@ on: # Triggers the action on push or pull request events but only for the main branch push: branches: [ main ] - pull_request: - branches: [ main ] # Allows you to run this action manually from the Actions tab workflow_dispatch: From 66cd93b796e7b219e6728424b9d8f9e0e304b7c9 Mon Sep 17 00:00:00 2001 From: Simone Tollardo Date: Mon, 2 Oct 2023 12:38:44 +0200 Subject: [PATCH 02/10] Improve dockerfile architecture: introduce builder, game and simulator convenient docker compose --- .github/workflows/docker-action.yml | 13 ++- .gitignore | 3 +- .gitmodules | 3 + build.sh | 40 +++++++++ checkout_branch.py | 31 ------- docker/Dockerfile | 121 ++++++++++++++++------------ docker/README.md | 105 ++++++++++++++++++++---- docker/builder/docker-compose.yml | 15 ++++ docker/game/docker-compose.yml | 101 +++++++++++++++++++++++ docker/simulator/docker-compose.yml | 105 ++++++++++++++++++++++++ external/framework | 1 + install_UBUNTU_22_04.sh | 42 ---------- 12 files changed, 439 insertions(+), 141 deletions(-) create mode 100644 .gitmodules create mode 100755 build.sh delete mode 100755 checkout_branch.py create mode 100644 docker/builder/docker-compose.yml create mode 100644 docker/game/docker-compose.yml create mode 100644 docker/simulator/docker-compose.yml create mode 160000 external/framework delete mode 100755 install_UBUNTU_22_04.sh diff --git a/.github/workflows/docker-action.yml b/.github/workflows/docker-action.yml index 9941b7022..ee670a033 100644 --- a/.github/workflows/docker-action.yml +++ b/.github/workflows/docker-action.yml @@ -13,6 +13,8 @@ jobs: - name: Checkout uses: actions/checkout@v3 + with: + submodules: recursive - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -33,11 +35,20 @@ jobs: push: true target: development tags: roboteamtwente/roboteam:development + - + name: Build sources + uses: addnab/docker-run-action@v3 + with: + image: roboteamtwente/roboteam:development + options: -v ${{ github.workspace }}:/home/roboteamtwente/ + run: | + sudo ./build.sh - name: Build and push release uses: docker/build-push-action@v4 with: - context: ./docker + context: . + file: ./docker/Dockerfile push: true target: release tags: roboteamtwente/roboteam:latest \ No newline at end of file diff --git a/.gitignore b/.gitignore index 91934be2e..bc7f3a271 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ .idea/ cmake-build-debug/ cmake-build-release/ -build*/ +**/build +.cache /.vscode .DS_Store diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..16032327d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "external/framework"] + path = external/framework + url = https://github.com/robotics-erlangen/framework.git diff --git a/build.sh b/build.sh new file mode 100755 index 000000000..f31b2cfce --- /dev/null +++ b/build.sh @@ -0,0 +1,40 @@ +#! /bin/bash + +set -e + +if [ "$1" == "-y" ]; +then + OK=1 +fi + +if [ -f /.dockerenv ] || [ "$OK" = "1" ]; +then + if [ "$0" == "./build.sh" ]; + then + #rm -rf build + mkdir -p build + pushd build + echo "Building RoboTeamTwente software" + cmake .. -DCMAKE_BUILD_TYPE=Release && make -j$(nproc) roboteam_observer roboteam_ai roboteam_robothub + popd + echo "Installing interface" + pushd roboteam_interface + yarn install + popd + pushd external + echo "Building external" + pushd framework + echo "Building external/framework" + mkdir -p build && pushd build + cmake .. && make simulator-cli -j$(nproc) + popd + popd + echo "Done, exiting builder.." + else + echo "E: The script must be called from the root folder" + exit 1 + fi +else + echo "W: If you really want to build outside the container call the script with -y argument." + exit 1 +fi diff --git a/checkout_branch.py b/checkout_branch.py deleted file mode 100755 index 2bfa4cd23..000000000 --- a/checkout_branch.py +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/python3 - -import os -import argparse -from typing import List - -def checkout_repo_branch(repo: str, branch: str): - if not os.system(f"cd {repo} && git pull origin {branch} && cd .."): - return - - raise Exception(f"Failed to checkout repo {repo} to branch {branch}") - -def checkout_main_repos_branch(branch: str): - main_repos: List[str] = [ - "roboteam_ai", - "roboteam_proto", - "roboteam_robothub", - "roboteam_utils", - "roboteam_world", - "roboteam_central_server" - ] - for each in main_repos: - checkout_repo_branch(each, branch) - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Checkout the main roboteam branches") - parser.add_argument("branch_name", type=str, help='The branch to checkout the repos on') - - args = parser.parse_args() - checkout_main_repos_branch(args.branch_name) \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile index 498847840..17507aedb 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,68 +1,85 @@ -# ========================== # -# INSTRUCTIONS # -# ========================== # +# RTT Build Environment +# The purpose of this container is to have a stable, quick and reliable environment +# to build RTT software. # -# ==== QUICKLY BOOT -# $ docker run --init --rm --net=host roboteamtwente/roboteam:latest ./roboteam_robothub -# $ docker run --init --rm --net=host roboteamtwente/roboteam:latest ./roboteam_observer -# $ xhost local: -# $ docker run --init --rm --net=host -v /tmp/.X11-unix/ -e DISPLAY=$DISPLAY rtt-release /roboteam_ai +# =========================================================================== # # +# Manually build the container: +# docker build -t rtt-build-env . # +# Spin-up the container: +# docker run -itd --name rtt-build-env -h rtt-build-env -v /:/home/roboteamtwente/roboteam rtt-build-env # -# ==== DO IT YOURSELF -# Step 1.1: Build -# $ docker build . --target development -t rtt-development -# $ docker build . --target release -t rtt-release +# Start/Stop container: +# docker rtt-build-env # -# Step 2: Allow X11 access -# $ xhost local: -# This will give local VMs acces to the X11-server, which is needed to do GUI stuff -# https://stackoverflow.com/questions/25281992/alternatives-to-ssh-x11-forwarding-for-docker-containers +# Attach to the container: +# docker exec -it -w /home/roboteamtwente rtt-build-env /bin/bash # -# Step 3.1: Create a development container, to which you can e.g. hook into with VSCode -# $ docker run -it -v /tmp/.X11-unix/ -e DISPLAY=$DISPLAY --net=host --name rtt rtt-development -# OR -# Step 3.2: Start any executable -# $ docker run --init --rm --net=host rtt-release /roboteam_observer -# $ docker run --init --rm --net=host -v /tmp/.X11-unix/ -e DISPLAY=$DISPLAY rtt-release /roboteam_ai -# $ docker run --init --rm --net=host rtt-release /roboteam_robothub +# =========================================================================== # # -# ========================== # +# Development target +FROM alpine:3.18 AS development +ENV TZ="Europe/Rome" +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone -# ========================== # -# DEVELOPMENT CONTAINER # -# ========================== # -FROM ubuntu:22.04 AS development -RUN apt-get update -y && apt-get upgrade -y -RUN apt-get install -y vim git cmake pkg-config python3 python3-pip ccache +ARG USERNAME=roboteamtwente -RUN git clone https://github.com/RoboTeamTwente/roboteam.git --recursive -WORKDIR /roboteam -RUN ./install_UBUNTU_22_04.sh -RUN mkdir build -WORKDIR /roboteam/build -RUN cmake .. -DCMAKE_BUILD_TYPE=Release && make -j$(nproc) roboteam_observer roboteam_ai roboteam_robothub -WORKDIR /roboteam +RUN apk add --no-cache bash build-base cmake make musl-dev libtool \ + clang ninja-build autoconf automake pkgconfig \ + python3 py3-pip git ccache sudo \ + libzmq zeromq-dev libzmq-static eigen-dev gtest-dev \ + libtbb-dev boost-dev curl unzip wget zlib-dev zip nodejs npm \ + openssl-dev sdl2-dev libudev-zero libudev-zero-dev libusb libusb-dev \ + qt5-qtbase-dev qt5-qtcharts-dev qt5-qtdeclarative-dev qt5-qtsvg-dev +RUN npm install -g yarn +WORKDIR /root/protobuf +RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v3.20.3/protobuf-cpp-3.20.3.zip -O protobuf.zip && unzip protobuf.zip && rm protobuf.zip +WORKDIR /root/protobuf/protobuf-3.20.3 +RUN ./configure && make -j$(nproc) && make check -j$(nproc) && make install && ldconfig . && cd .. && rm -rf /root/protobuf/protobuf-3.20.3 +ENV HOME=/home/$USERNAME +ENV USER=$USERNAME -# ========================== # -# RELEASE CONTAINER # -# ========================== # -FROM ubuntu:22.04 AS release -COPY --from=development /roboteam/build/release/bin/roboteam_observer /roboteam_observer -COPY --from=development /roboteam/build/release/bin/roboteam_ai /roboteam_ai -COPY --from=development /roboteam/build/release/bin/roboteam_robothub /roboteam_robothub +RUN adduser -D $USER && \ + echo "$USER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$USER && \ + chmod 0440 /etc/sudoers.d/$USER -COPY --from=development /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu -COPY --from=development /usr/share/fonts /usr/share/fonts -COPY --from=development /roboteam/build/release/lib/libzmqpp.so /usr/lib/libzmqpp.so -COPY --from=development /roboteam/build/release/lib/libNFParam.so /usr/lib/libNFParam.so -COPY --from=development /usr/local/lib/libprotobuf.so.30.0.6 /usr/lib/libprotobuf.so.30 +USER $USER +WORKDIR $HOME -# The entire /usr/lib/x86_64-linux-gnu folder is cloned since it's too much of a hassle to figure out what is and isn't needed -# TODO figure out how to exlude large files such as /usr/lib/x86_64-linux-gnu/libLLVM* (200+MB) -# Can't use .dockerignore for this https://github.com/moby/moby/issues/33923 +# Release target +FROM alpine:3.18 AS release + +ENV TZ="Europe/Rome" +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +ARG USERNAME=roboteamtwente +ENV HOME=/home/$USERNAME +ENV USER=$USERNAME + +RUN apk add --no-cache \ + libtool libzmq libzmq-static libudev-zero libusb \ + zeromq-dev eigen-dev gtest-dev \ + libtbb-dev boost-dev zlib-dev \ + openssl-dev sdl2-dev \ + qt5-qtbase-dev qt5-qtcharts-dev qt5-qtdeclarative-dev qt5-qtsvg-dev \ + sudo nodejs npm +RUN npm install -g yarn + +COPY --from=development --chown=root:root /usr/local/lib/libprotobuf.so.31 /usr/local/lib/libprotobuf.so.31 +COPY --from=development --chown=root:root /usr/local/bin/protoc /usr/local/bin/protoc + +RUN adduser -D $USER && \ + echo "$USER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$USER && \ + chmod 0440 /etc/sudoers.d/$USER + +USER $USER +WORKDIR $HOME + +ENV LD_LIBRARY_PATH=$HOME/lib/ +# Note: cannot COPY from outside context, build from parent folder +COPY --chown=$USER:$USER ../build/release/ $HOME/ \ No newline at end of file diff --git a/docker/README.md b/docker/README.md index afba1595c..c486fd24b 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,24 +1,101 @@ # Docker setup for RTT - ## Why docker? -Docker can create a virtual environment with pre installed depencendies. This makes sure everyone with this virtual environment can run our code. +Docker can create a virtual environment with pre installed depencendies. This makes sure everyone with this virtual environment can build or run our code. For a simulation tournament (2022/04), every team had to put their program in a docker image, so that their image could run on the server of the people that hosted the tournament (So less delay between our program and the simulator). -## How to make? -The `Dockerfile` file contains the steps to create the image. It contains all the commands that need to be run to install the required dependencies. It also copies the `clone.sh` script to the image so you dont have to type git clone for our repo. -- To create the image: (note the dot at the end) - - docker build -t roboteamtwente/practice_tournament . -- To run the image in a container: - docker run -e VNC_PW=12345 -p 5901:5901 -p 2222:2222 -it roboteamtwente/practice_tournament +## Structure +The description of the environment is located in the Dockerfile inside the `docker` folder. The file is divided in two targets: "development" and "release". + +Release target is only intended as a GitHub Action target, its purpose is to create the Docker image containing runnable binaries that can be pushed into a Registry. If you really want to build it locally you can do it by first building the development target, then compile sources with it and then build the release target. Development target is intended as a normal usage target. -This image that will be created is also publicly available at [the docker hub](https://hub.docker.com/r/roboteamtwente/practice_tournament). This allows others to run our image. Be sure to update that docker once in a while. +Inside `docker` folder there are three subdirectories: `builder` `game` and `simulator`. +Every folder contains a convenient docker compose file: + - builder is used by lazy people like me to build sources without building and then directly executing command on a container + - simulator is used to start every service needed to start a simulation (apart from some external software, see [Normal Usage](#normal-usage) + - game is used to start roboteam software in real game mode +Docker composes use volumes because this way it's possible to compile sources and start up just built services without rebuilding any container. ## How to use? -On startup, the container will open a VNC session. With this you can remote desktop into the container, where you will be able to run our code. Download a VNC viewer for the remote desktopping(I suggest [this one](https://www.realvnc.com/en/connect/download/viewer/linux/), and log in with the VNC password you set in the `docker run` command (12345). +First things first: for convenience create an ENV VAR containing the path to this repo (change rc file accordingly to your shell). Make sure to be in the repo root folder (should be one level up from the folder in which this README is) and then: +``` +echo ROBOTEAM_REPO=$(pwd)/ >> ~/.bashrc +source ~/.bashrc +``` + +Every subproject is meant to be executed as a service using its own container from a docker-compose. +Every RTT subproject (service) runs in its own 'rtt-build-env' container, this way that all dependencies and requirements are satisfied. +Subproject containers start their own software from `build/release/bin` folder mounted as a volume. + +### Normal usage +1) Make your edits on RTT sources +2) Spin-up "builder" compose +3) Spin-up "simulator"/"game" compose +4) (Game-only) Download, install and run ssl-vision +4) Download and run ssl-game-controller (https://github.com/RoboCup-SSL/ssl-game-controller/releases) +5) (opt.) Download, install and run an autoref (e.g. https://github.com/robotics-erlangen/autoref) + +As simple as that. + +1. Whenever you want to build all RTT services (normal operation) you simply need to run: +``` +cd $ROBOTEAM_REPO/docker/builder +docker-compose up +``` +2. Start services: +``` +cd $ROBOTEAM_REPO/docker/ +docker-compose up <-d> +``` +When you want to stop services: +``` +docker compose down +``` + +Note: you may want to use `docker logs -t ` to see command output of a specific container (service). +Example: `docker logs -t RTT_roboteam_primary_ai` + +#### TODO +https://lemariva.com/blog/2020/10/vscode-c-development-and-debugging-containers + +### Docker geeks +#### Build environment +You can manually build the 'build environment' container doing: +``` +docker build -t rtt-build-env . +``` + +Spin-up the just built container: +``` +docker run -itd --name rtt-build-env -h rtt-build-env -v $ROBOTEAM_REPO:/home/roboteamtwente/roboteam rtt-build-env +``` + +Then, you can compile sources using `build.sh` script located in the repo root folder from inside the container. +First, attach to a contanier shell: +``` +docker exec -it -u roboteamtwente -w /home/roboteamtwente/roboteam rtt-build-env /bin/bash +``` +then you can execute build script (or manually compiler whatever you want): +``` +./build.sh +``` + +Remember that you can stop/start 'rtt-build-env' container simply using: +``` +docker rtt-build-env +``` + +Note: avoid tagging the "run" stage container with the same name "rtt-build-env", otherwise when you will start the "build" compose you won't be able to compile sources (because the compose will be re-using the container with that name). +#### Manually starting a service +You can start a service by simply executing the binary from the rtt-build-env container. +Example: +Log into a container shell: +``` +docker exec -it -u roboteamtwente -w /home/roboteamtwente/ -v /:/home/roboteamtwente/ rtt-build-env /bin/bash +``` +execute roboteam_ai: +``` +./release/bin/roboteam_ai --primary_ai +``` -## Nice to know -- The image already has the text editor sublime text. To start it, open a terminal, and enter `subl ` to open that specific folder. -- Use the sript `clone.sh` to clone the roboteam repo located at `/`. \ No newline at end of file diff --git a/docker/builder/docker-compose.yml b/docker/builder/docker-compose.yml new file mode 100644 index 000000000..005f2ea12 --- /dev/null +++ b/docker/builder/docker-compose.yml @@ -0,0 +1,15 @@ +version: '3' + +services: + + roboteam_builder: + build: + context: ../ + target: development + image: rtt-build-env:latest + container_name: RTT_roboteam_builder + restart: "no" + working_dir: "/home/roboteamtwente/" + command: sh -c "./build.sh" + volumes: + - ../../:/home/roboteamtwente/ \ No newline at end of file diff --git a/docker/game/docker-compose.yml b/docker/game/docker-compose.yml new file mode 100644 index 000000000..833ae37b8 --- /dev/null +++ b/docker/game/docker-compose.yml @@ -0,0 +1,101 @@ +version: '3' + +services: + + roboteam_primary_ai: + build: + context: ../ + target: development + image: rtt-build-env:latest + container_name: RTT_roboteam_primary_ai + restart: always + working_dir: "/home/roboteamtwente/" + command: sh -c "./bin/roboteam_ai --primary-ai --basestation" + network_mode: "host" # Workaround to connect from interface on host to AI websocket, please fix + expose: + - 1-65535:1-65535 # For zeromq ports + - 12676:12676 # Primary AI Port + ports: + - 12676:12676 # Primary AI Port + environment: + - LD_LIBRARY_PATH=/home/roboteamtwente/lib/ + volumes: + - ../../build/release/:/home/roboteamtwente/ + + roboteam_secondary_ai: + image: rtt-build-env:latest + container_name: RTT_roboteam_secondary_ai + restart: always + working_dir: "/home/roboteamtwente/" + command: sh -c "./bin/roboteam_ai --secondary-ai --basestation" + network_mode: "host" # Workaround to connect from interface on host to AI websocket, please fix + expose: + - 1-65535:1-65535 # For zeromq ports + - 12677:12677 # Secondary AI Port + ports: + - 12677:12677 # Secondary AI Port + environment: + - LD_LIBRARY_PATH=/home/roboteamtwente/lib/ + volumes: + - ../../build/release/:/home/roboteamtwente/ + + roboteam_observer: + image: rtt-build-env:latest + container_name: RTT_roboteam_observer + restart: always + working_dir: "/home/roboteamtwente/" + command: sh -c "./bin/roboteam_observer --vision-ip 224.5.23.2 --referee-ip 224.5.23.1 --vision-port 10006 --referee-port 10003" + network_mode: "host" # Workaround to connect from interface on host to AI websocket, please fix + expose: + - 1-65535:1-65535 # For zeromq ports + - 10006:10006 # Vision port vision + - 10020:10020 # Vision port simulator + - 10003:10003 # Referee port + environment: + - LD_LIBRARY_PATH=/home/roboteamtwente/lib/ + volumes: + - ../../build/release/:/home/roboteamtwente/ + + roboteam_robothub: + image: rtt-build-env:latest + container_name: RTT_roboteam_robothub + restart: always + working_dir: "/home/roboteamtwente/" + command: sh -c "./bin/roboteam_robothub" + network_mode: "host" # Workaround to connect from interface on host to AI websocket, please fix + expose: + - 1-65535:1-65535 # For zeromq ports + - 10301:10301 #Blue Control Port + - 30011:30011 #Blue Feedback Port + - 10302:10302 #Yellow Control Port + - 30012:30012 #Yellow Feedback Port + - 10300:10300 #Simulation Control Port + - 30013:30013 #Simulation Feedback Port + environment: + - LD_LIBRARY_PATH=/home/roboteamtwente/lib/ + volumes: + - ../../build/release/:/home/roboteamtwente/ + + roboteam_interface: + image: rtt-build-env:latest + container_name: RTT_roboteam_interface + restart: always + working_dir: "/home/roboteamtwente/" + command: sh -c "yarn serve --host 0.0.0.0" + ports: + - 8080:8080 + volumes: + - ../../roboteam_interface/:/home/roboteamtwente/ + +# ssl_vision: +# image: rtt-build-env:latest +# container_name: RTT_ssl_vision +# restart: always +# working_dir: "/home/roboteamtwente/" +# command: sh -c "./bin/vision" +# expose: +# - 10006:10006 # Vision port +# environment: +# - LC_NUMERIC=en_US.UTF-8 +# volumes: +# - ../../external/ssl-vision/:/home/roboteamtwente/ \ No newline at end of file diff --git a/docker/simulator/docker-compose.yml b/docker/simulator/docker-compose.yml new file mode 100644 index 000000000..25044a612 --- /dev/null +++ b/docker/simulator/docker-compose.yml @@ -0,0 +1,105 @@ +version: '3' + +services: + + roboteam_primary_ai: + build: + context: ../ + target: run + image: rtt-build-env:latest + container_name: RTT_roboteam_primary_ai + restart: always + working_dir: "/home/roboteamtwente/" + command: sh -c "./bin/roboteam_ai --primary-ai" + network_mode: "host" # Workaround to connect from interface on host to AI websocket, please fix + expose: + - 1-65535:1-65535 # For zeromq ports + - 12676:12676 # Primary AI Port + ports: + - 12676:12676 # Primary AI Port + environment: + - LD_LIBRARY_PATH=/home/roboteamtwente/lib/ + volumes: + - ../../build/release/:/home/roboteamtwente/ + + roboteam_secondary_ai: + image: rtt-build-env:latest + container_name: RTT_roboteam_secondary_ai + restart: always + working_dir: "/home/roboteamtwente/" + command: sh -c "./bin/roboteam_ai --secondary-ai" + network_mode: "host" # Workaround to connect from interface on host to AI websocket, please fix + expose: + - 1-65535:1-65535 # For zeromq ports + - 12677:12677 # Secondary AI Port + ports: + - 12677:12677 # Secondary AI Port + environment: + - LD_LIBRARY_PATH=/home/roboteamtwente/lib/ + volumes: + - ../../build/release/:/home/roboteamtwente/ + + roboteam_observer: + image: rtt-build-env:latest + container_name: RTT_roboteam_observer + restart: always + working_dir: "/home/roboteamtwente/" + command: sh -c "./bin/roboteam_observer --vision-ip 224.5.23.2 --referee-ip 224.5.23.1 --vision-port 10020 --referee-port 10003" + network_mode: "host" # Workaround to connect from interface on host to AI websocket, please fix + expose: + - 1-65535:1-65535 # For zeromq ports + - 10006:10006 # Vision port vision + - 10020:10020 # Vision port simulator + - 10003:10003 # Referee port + environment: + - LD_LIBRARY_PATH=/home/roboteamtwente/lib/ + volumes: + - ../../build/release/:/home/roboteamtwente/ + + roboteam_robothub: + image: rtt-build-env:latest + container_name: RTT_roboteam_robothub + restart: always + working_dir: "/home/roboteamtwente/" + command: sh -c "./bin/roboteam_robothub" + network_mode: "host" # Workaround to connect from interface on host to AI websocket, please fix + expose: + - 1-65535:1-65535 # For zeromq ports + - 10301:10301 #Blue Control Port + - 30011:30011 #Blue Feedback Port + - 10302:10302 #Yellow Control Port + - 30012:30012 #Yellow Feedback Port + - 10300:10300 #Simulation Control Port + - 30013:30013 #Simulation Feedback Port + environment: + - LD_LIBRARY_PATH=/home/roboteamtwente/lib/ + volumes: + - ../../build/release/:/home/roboteamtwente/ + + roboteam_interface: + image: rtt-build-env:latest + container_name: RTT_roboteam_interface + restart: always + working_dir: "/home/roboteamtwente/" + command: sh -c "yarn serve --host 0.0.0.0" + ports: + - 8080:8080 + volumes: + - ../../roboteam_interface/:/home/roboteamtwente/ + + erforce_simulator: + image: rtt-build-env:latest + container_name: RTT_erforce_simulator + restart: always + working_dir: "/home/roboteamtwente/external/framework/build/bin/" + command: sh -c "./simulator-cli" + network_mode: "host" # Workaround to connect from interface on host to AI websocket, please fix + expose: + - 10301:10301 #Blue Control Port + - 30011:30011 #Blue Feedback Port + - 10302:10302 #Yellow Control Port + - 30012:30012 #Yellow Feedback Port + - 10300:10300 #Simulation Control Port + - 30013:30013 #Simulation Feedback Port + volumes: + - ../../:/home/roboteamtwente/ \ No newline at end of file diff --git a/external/framework b/external/framework new file mode 160000 index 000000000..0f5ffffa4 --- /dev/null +++ b/external/framework @@ -0,0 +1 @@ +Subproject commit 0f5ffffa4417be583357c923ee4217183ed5c260 diff --git a/install_UBUNTU_22_04.sh b/install_UBUNTU_22_04.sh deleted file mode 100755 index 59c814dd8..000000000 --- a/install_UBUNTU_22_04.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -echo Updating repositories -apt-get -y update -apt-get -y upgrade - -echo Installing required packaged dependencies -apt-get install -y cmake -apt-get install -y g++ -apt-get install -y qt5-default -apt-get install -y libqt5charts5-dev -apt-get install -y libzmq3-dev -apt-get install -y libeigen3-dev -apt-get install -y libgtest-dev -apt-get install -y libudev-dev - -echo Installing other useful packages -apt-get install -y clang -apt-get install -y clang-format -apt-get install -y ninja-build -apt-get install -y autoconf -apt-get install -y automake -apt-get install -y libtool -apt-get install -y libtbb-dev -apt-get install -y apt-utils -apt-get install -y libboost-all-dev -apt-get install -y curl -apt-get install -y make -apt-get install -y unzip -apt-get install -y qtdeclarative5-dev - -# The default protobuf package is too low of a version for us -echo Installing protobuf -git clone https://github.com/protocolbuffers/protobuf.git /opt/protobuf -cd /opt/protobuf -git checkout 3.19.x -git submodule update --init --recursive -./autogen.sh -./configure -make -j $(nproc) -make install -ldconfig From 406fc36d6df2a39fa03e75683288d60e46e166b1 Mon Sep 17 00:00:00 2001 From: Simone Tollardo Date: Wed, 4 Oct 2023 12:23:55 +0200 Subject: [PATCH 03/10] Add erforce autoref as submodule and compose service --- .gitignore | 1 + .gitmodules | 3 +++ build.sh | 7 +++++++ docker/README.md | 10 ++++++++-- docker/game/docker-compose.yml | 14 ++++++++++++++ docker/simulator/docker-compose.yml | 14 ++++++++++++++ external/autoref | 1 + 7 files changed, 48 insertions(+), 2 deletions(-) create mode 160000 external/autoref diff --git a/.gitignore b/.gitignore index bc7f3a271..74ca9d675 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .idea/ cmake-build-debug/ cmake-build-release/ +.cmake/ **/build .cache /.vscode diff --git a/.gitmodules b/.gitmodules index 16032327d..a2ccbd408 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "external/framework"] path = external/framework url = https://github.com/robotics-erlangen/framework.git +[submodule "external/autoref"] + path = external/autoref + url = https://github.com/robotics-erlangen/autoref.git diff --git a/build.sh b/build.sh index f31b2cfce..f844f0591 100755 --- a/build.sh +++ b/build.sh @@ -27,6 +27,13 @@ then echo "Building external/framework" mkdir -p build && pushd build cmake .. && make simulator-cli -j$(nproc) + popd + popd + pushd autoref + echo "Building external/autoref" + mkdir -p build && pushd build + cmake .. && make autoref-cli -j$(nproc) + popd popd popd echo "Done, exiting builder.." diff --git a/docker/README.md b/docker/README.md index c486fd24b..993403bbd 100644 --- a/docker/README.md +++ b/docker/README.md @@ -7,7 +7,8 @@ For a simulation tournament (2022/04), every team had to put their program in a ## Structure The description of the environment is located in the Dockerfile inside the `docker` folder. The file is divided in two targets: "development" and "release". -Release target is only intended as a GitHub Action target, its purpose is to create the Docker image containing runnable binaries that can be pushed into a Registry. If you really want to build it locally you can do it by first building the development target, then compile sources with it and then build the release target. Development target is intended as a normal usage target. +Release target is only intended as a GitHub Action target, its purpose is to create the Docker image containing runnable binaries that can be pushed into a Registry. If you really want to build it locally you can do it by first building the development target, then compile sources with it and then build the release target. Note that release target contains only RoboTeamTwente binaries and not external ones like erforce simulator or erforce autoref. +Development target is instead intended as a normal usage target. Inside `docker` folder there are three subdirectories: `builder` `game` and `simulator`. Every folder contains a convenient docker compose file: @@ -24,6 +25,12 @@ echo ROBOTEAM_REPO=$(pwd)/ >> ~/.bashrc source ~/.bashrc ``` +Init submodules: +``` +cd $ROBOTEAM_REPO +git submodule update --init --recursive +``` + Every subproject is meant to be executed as a service using its own container from a docker-compose. Every RTT subproject (service) runs in its own 'rtt-build-env' container, this way that all dependencies and requirements are satisfied. Subproject containers start their own software from `build/release/bin` folder mounted as a volume. @@ -34,7 +41,6 @@ Subproject containers start their own software from `build/release/bin` folder m 3) Spin-up "simulator"/"game" compose 4) (Game-only) Download, install and run ssl-vision 4) Download and run ssl-game-controller (https://github.com/RoboCup-SSL/ssl-game-controller/releases) -5) (opt.) Download, install and run an autoref (e.g. https://github.com/robotics-erlangen/autoref) As simple as that. diff --git a/docker/game/docker-compose.yml b/docker/game/docker-compose.yml index 833ae37b8..b252c4a5a 100644 --- a/docker/game/docker-compose.yml +++ b/docker/game/docker-compose.yml @@ -87,6 +87,20 @@ services: volumes: - ../../roboteam_interface/:/home/roboteamtwente/ + erforce_autoref: + image: rtt-build-env:latest + container_name: RTT_erforce_autoref + restart: always + working_dir: "/home/roboteamtwente/external/autoref/build/bin/" + command: sh -c "./autoref-cli --vision-port 10006 --tracker-port 10010 --gc-port 10003" + network_mode: "host" # Workaround to connect from interface on host to AI websocket, please fix + expose: + - 10006:10006 #Vision port + - 10003:10003 #Ref port + - 10010:10010 #Tracker port + volumes: + - ../../:/home/roboteamtwente/ + # ssl_vision: # image: rtt-build-env:latest # container_name: RTT_ssl_vision diff --git a/docker/simulator/docker-compose.yml b/docker/simulator/docker-compose.yml index 25044a612..187602bac 100644 --- a/docker/simulator/docker-compose.yml +++ b/docker/simulator/docker-compose.yml @@ -87,6 +87,20 @@ services: volumes: - ../../roboteam_interface/:/home/roboteamtwente/ + erforce_autoref: + image: rtt-build-env:latest + container_name: RTT_erforce_autoref + restart: always + working_dir: "/home/roboteamtwente/external/autoref/build/bin/" + command: sh -c "./autoref-cli --vision-port 10020 --tracker-port 10010 --gc-port 10003" + network_mode: "host" # Workaround to connect from interface on host to AI websocket, please fix + expose: + - 10020:10020 #Vision port simulator + - 10003:10003 #Ref port + - 10010:10010 #Tracker port + volumes: + - ../../:/home/roboteamtwente/ + erforce_simulator: image: rtt-build-env:latest container_name: RTT_erforce_simulator diff --git a/external/autoref b/external/autoref new file mode 160000 index 000000000..6f15f574e --- /dev/null +++ b/external/autoref @@ -0,0 +1 @@ +Subproject commit 6f15f574ea803984ba7169a40c618fad43143596 From 00423dc864eaadacd8f03811593bfd967049aea3 Mon Sep 17 00:00:00 2001 From: Simone Tollardo Date: Fri, 20 Oct 2023 13:07:01 +0200 Subject: [PATCH 04/10] PR 97 fix --- README.md | 31 ++--------------------------- docker/README.md | 10 ++++++---- docker/game/docker-compose.yml | 25 ++++++++--------------- docker/simulator/docker-compose.yml | 16 +++++++++++---- 4 files changed, 28 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 8dfc9fd12..6211534d1 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # RoboTeam ## Overview -This software is tested on Ubuntu 22.04 LTS, and the installation instructions are written with that distro/OS in mind. However, other distro's of Linux are also likely to be able to run this software, albeit with some modifications. - This repository contains the following projects: - `RoboTeam World`. It is responsible from receiving and combining all sources of information into one coherent world state, which can be used by `RoboTeam AI`. These sources include data from either a simulator or SSL-Vision, and feedback from our robots (WIP). Note: The executable is called `roboteam_observer`*. @@ -15,8 +13,8 @@ This repository contains the following projects: -## Dependencies -All dependencies are listed in `install_dependencies_ubuntu22-04.sh`. Simply run this file to install all of them. Additionally, it installs other useful packages. +## How to +Refer to `docker/README.md` for usage of our software. ## IDEs ### VSCode @@ -27,29 +25,6 @@ To install [CLion](https://www.jetbrains.com/clion/), you need a [student licens Make sure you have the dependencies installed. Within CLion, go to the CMakeLists.txt and click on it. CLion will generate a pop-up saying "project files not loaded" in blue in the top right corner. Clicking it will have CMake load the project. This means it generates instructions on how the files should be compiled in order to produce the executables specified in the CMakeLists.txt file. You can now compile the targets! -## Running a game -![alt text](readme_images/rtt_software_stack.png) - -To run a game, you will need to boot up `RoboTeam AI`, `RoboTeam World`, and `RoboTeam Robothub`. The executables are named `roboteam_ai`, `roboteam_observer`, and `roboteam_robothub` respectively. Next to that, either boot up a simulator or SSL-Vision. Want to run an entire match with autorefs and everything? Please have a look at this official (docker-compose)[https://github.com/RoboCup-SSL/ssl-game-controller/blob/master/docker-compose.yaml] file. It contains everything you need outside of our own software. - -## SSL Software / Simulators -* [`SSL Vision`](https://github.com/RoboCup-SSL/ssl-vision) -* [`SSL Game Controller`](https://github.com/RoboCup-SSL/ssl-game-controller) -* [`GrSim simulator`](https://github.com/RoboCup-SSL/grSim) -* [`ER-Force simulator`](https://github.com/robotics-erlangen/framework#simulator-cli) -* [`Other SSL software`](https://github.com/RoboCup-SSL) - -It is recommended to use the game controller to control the gamestates. You can do so by downloading the latest binary release of the [SSL-Game-Controller](https://github.com/RoboCup-SSL/ssl-game-controller) repo, and executing it. For example, when downloaded to the Downloads folder: - -```bash -~/Downloads/ssl-game-controller_v1.2.0_linux_amd64 -``` - -You might need to [chmod](https://www.howtoforge.com/tutorial/linux-chmod-command/) the file to make it executable. The AI client should now listen to the commands sent by the GameController. - -## Installation Ubuntu -All dependencies are listed in `install_dependencies_ubuntu22-04.sh`. Simply run the script to install all of these, and some useful other packages. - ### Code Style Formatting To be consistent in the code style, we use clang-format. You can use clang-format to automatically format your code during every commit and you can use clang-format in CLion to format all code files in a given folder. Format the code by running `format.sh` ## See also @@ -63,5 +38,3 @@ To enable Tracy - Compile Tracy Server and run - Information is in the tracy [docs](https://github.com/wolfpld/tracy) - Run AI - - diff --git a/docker/README.md b/docker/README.md index 993403bbd..0d785c34e 100644 --- a/docker/README.md +++ b/docker/README.md @@ -31,7 +31,9 @@ cd $ROBOTEAM_REPO git submodule update --init --recursive ``` -Every subproject is meant to be executed as a service using its own container from a docker-compose. +Then, install prerequisite: install Docker https://docs.docker.com/engine/install/, if you want you can add yourself to docker group in order to run Docker command without invoking root user https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user and finally install docker compose. + +Every subproject is meant to be executed as a service using its own container from a docker compose. Every RTT subproject (service) runs in its own 'rtt-build-env' container, this way that all dependencies and requirements are satisfied. Subproject containers start their own software from `build/release/bin` folder mounted as a volume. @@ -40,19 +42,19 @@ Subproject containers start their own software from `build/release/bin` folder m 2) Spin-up "builder" compose 3) Spin-up "simulator"/"game" compose 4) (Game-only) Download, install and run ssl-vision -4) Download and run ssl-game-controller (https://github.com/RoboCup-SSL/ssl-game-controller/releases) +5) You can now reach game controller UI on localhost:8081 and roboteam interface on localhost:8080, connect to primary_ai (port 12676) or secondary_ai (port 12677). As simple as that. 1. Whenever you want to build all RTT services (normal operation) you simply need to run: ``` cd $ROBOTEAM_REPO/docker/builder -docker-compose up +docker compose up ``` 2. Start services: ``` cd $ROBOTEAM_REPO/docker/ -docker-compose up <-d> +docker compose up <-d> ``` When you want to stop services: ``` diff --git a/docker/game/docker-compose.yml b/docker/game/docker-compose.yml index b252c4a5a..22c96cdfd 100644 --- a/docker/game/docker-compose.yml +++ b/docker/game/docker-compose.yml @@ -22,23 +22,6 @@ services: volumes: - ../../build/release/:/home/roboteamtwente/ - roboteam_secondary_ai: - image: rtt-build-env:latest - container_name: RTT_roboteam_secondary_ai - restart: always - working_dir: "/home/roboteamtwente/" - command: sh -c "./bin/roboteam_ai --secondary-ai --basestation" - network_mode: "host" # Workaround to connect from interface on host to AI websocket, please fix - expose: - - 1-65535:1-65535 # For zeromq ports - - 12677:12677 # Secondary AI Port - ports: - - 12677:12677 # Secondary AI Port - environment: - - LD_LIBRARY_PATH=/home/roboteamtwente/lib/ - volumes: - - ../../build/release/:/home/roboteamtwente/ - roboteam_observer: image: rtt-build-env:latest container_name: RTT_roboteam_observer @@ -101,6 +84,14 @@ services: volumes: - ../../:/home/roboteamtwente/ + ssl-game-controller: + image: robocupssl/ssl-game-controller:latest + container_name: RTT_ssl-game-controller + restart: always + network_mode: "host" # Workaround to connect from interface on host to AI websocket, please fix + ports: + - "8081:8081/tcp" # UI port + # ssl_vision: # image: rtt-build-env:latest # container_name: RTT_ssl_vision diff --git a/docker/simulator/docker-compose.yml b/docker/simulator/docker-compose.yml index 187602bac..5b57fac06 100644 --- a/docker/simulator/docker-compose.yml +++ b/docker/simulator/docker-compose.yml @@ -95,9 +95,9 @@ services: command: sh -c "./autoref-cli --vision-port 10020 --tracker-port 10010 --gc-port 10003" network_mode: "host" # Workaround to connect from interface on host to AI websocket, please fix expose: - - 10020:10020 #Vision port simulator - - 10003:10003 #Ref port - - 10010:10010 #Tracker port + - 10020:10020 # Vision port simulator + - 10003:10003 # Ref port + - 10010:10010 # Tracker port volumes: - ../../:/home/roboteamtwente/ @@ -116,4 +116,12 @@ services: - 10300:10300 #Simulation Control Port - 30013:30013 #Simulation Feedback Port volumes: - - ../../:/home/roboteamtwente/ \ No newline at end of file + - ../../:/home/roboteamtwente/ + + ssl-game-controller: + image: robocupssl/ssl-game-controller:latest + container_name: RTT_ssl-game-controller + restart: always + network_mode: "host" # Workaround to connect from interface on host to AI websocket, please fix + ports: + - "8081:8081/tcp" # UI port \ No newline at end of file From aba506261ed42c4ebe95c4eea346b12362aaff36 Mon Sep 17 00:00:00 2001 From: Simone Tollardo Date: Tue, 7 Nov 2023 10:57:58 +0100 Subject: [PATCH 05/10] Feature: add RTT autoref --- .gitmodules | 4 ++++ README.md | 2 -- build.sh | 5 +++++ docker/game/docker-compose.yml | 16 ++++++++++++++++ docker/simulator/docker-compose.yml | 18 +++++++++++++++++- roboteam_autoref | 1 + 6 files changed, 43 insertions(+), 3 deletions(-) create mode 160000 roboteam_autoref diff --git a/.gitmodules b/.gitmodules index a2ccbd408..820040ed7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,7 @@ [submodule "external/autoref"] path = external/autoref url = https://github.com/robotics-erlangen/autoref.git +[submodule "roboteam_autoref"] + path = roboteam_autoref + url = git@github.com:RoboTeamTwente/roboteam_autoref.git + branch = main diff --git a/README.md b/README.md index 6211534d1..4a4af676b 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,6 @@ This repository contains the following projects: \* `RoboTeam World` its executable is named `roboteam_observer`, since `RoboTeam AI` also contains a class named `World`, which caused confusion. - - ## How to Refer to `docker/README.md` for usage of our software. diff --git a/build.sh b/build.sh index f844f0591..217c83ede 100755 --- a/build.sh +++ b/build.sh @@ -7,10 +7,15 @@ then OK=1 fi +# Check if the script is being executed from inside container or explicitly +# asked to run it on host environment if [ -f /.dockerenv ] || [ "$OK" = "1" ]; then if [ "$0" == "./build.sh" ]; then + echo "Checking submodules" + git submodule update --init --recursive + echo "Done" #rm -rf build mkdir -p build pushd build diff --git a/docker/game/docker-compose.yml b/docker/game/docker-compose.yml index 22c96cdfd..7b1494950 100644 --- a/docker/game/docker-compose.yml +++ b/docker/game/docker-compose.yml @@ -70,6 +70,22 @@ services: volumes: - ../../roboteam_interface/:/home/roboteamtwente/ + roboteam_autoref: + image: gradle:8.4.0-jdk17 + container_name: RTT_roboteam_autoref + user: gradle # Do not build as root + restart: always + working_dir: "/home/roboteamtwente/" + command: sh -c "./gradlew run --args=\"-cli -active --world-ip=127.0.0.1 --world-port=5558 --gc-ip=127.0.0.1 --gc-port=10007\"" + network_mode: "host" # Workaround to connect from interface on host to AI websocket, please fix + expose: + - 10007:10007 # GC port + - 5558:5558 # World port + environment: + - GRADLE_USER_HOME=/home/roboteamtwente/.cache # Cache gradle dependencies + volumes: + - ../../roboteam_autoref/:/home/roboteamtwente/ + erforce_autoref: image: rtt-build-env:latest container_name: RTT_erforce_autoref diff --git a/docker/simulator/docker-compose.yml b/docker/simulator/docker-compose.yml index 5b57fac06..88297671b 100644 --- a/docker/simulator/docker-compose.yml +++ b/docker/simulator/docker-compose.yml @@ -87,6 +87,22 @@ services: volumes: - ../../roboteam_interface/:/home/roboteamtwente/ + roboteam_autoref: + image: gradle:8.4.0-jdk17 + container_name: RTT_roboteam_autoref + user: gradle # Do not build as root + restart: always + working_dir: "/home/roboteamtwente/" + command: sh -c "./gradlew run --args=\"-cli -active --world-ip=127.0.0.1 --world-port=5558 --gc-ip=127.0.0.1 --gc-port=10007\"" + network_mode: "host" # Workaround to connect from interface on host to AI websocket, please fix + expose: + - 10007:10007 # GC port + - 5558:5558 # World port + environment: + - GRADLE_USER_HOME=/home/roboteamtwente/.cache # Cache gradle dependencies + volumes: + - ../../roboteam_autoref/:/home/roboteamtwente/ + erforce_autoref: image: rtt-build-env:latest container_name: RTT_erforce_autoref @@ -96,7 +112,7 @@ services: network_mode: "host" # Workaround to connect from interface on host to AI websocket, please fix expose: - 10020:10020 # Vision port simulator - - 10003:10003 # Ref port + - 10003:10003 # GC port - 10010:10010 # Tracker port volumes: - ../../:/home/roboteamtwente/ diff --git a/roboteam_autoref b/roboteam_autoref new file mode 160000 index 000000000..3b336322e --- /dev/null +++ b/roboteam_autoref @@ -0,0 +1 @@ +Subproject commit 3b336322e42dd3087835bccea04a7f16fdf4c522 From f82f9dd7ccd7326a43b02042fda20183f4cf4612 Mon Sep 17 00:00:00 2001 From: Simone Tollardo Date: Tue, 7 Nov 2023 11:37:25 +0100 Subject: [PATCH 06/10] Fix: change RTT autoref submodule address to https in order to be cloned from docker env --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 820040ed7..83a62b8fb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,5 +6,5 @@ url = https://github.com/robotics-erlangen/autoref.git [submodule "roboteam_autoref"] path = roboteam_autoref - url = git@github.com:RoboTeamTwente/roboteam_autoref.git + url = https://github.com/RoboTeamTwente/roboteam_autoref.git branch = main From 01f032dadcf8df4db53901b0f8203e35b4987806 Mon Sep 17 00:00:00 2001 From: Simone Tollardo Date: Mon, 20 Nov 2023 12:14:02 +0100 Subject: [PATCH 07/10] Do not spam 'This secondary AI can not alter settings' by default when starting secondary AI --- roboteam_ai/src/utilities/IOManager.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/roboteam_ai/src/utilities/IOManager.cpp b/roboteam_ai/src/utilities/IOManager.cpp index 451fd04d4..4e384cbf1 100644 --- a/roboteam_ai/src/utilities/IOManager.cpp +++ b/roboteam_ai/src/utilities/IOManager.cpp @@ -64,7 +64,9 @@ void IOManager::handleState(const proto::State& stateMsg) { } else if (state.referee().blue().name() == ROBOTEAM_TWENTE) { GameSettings::setYellow(false); } - GameSettings::setLeft(!(state.referee().blue_team_on_positive_half() ^ GameSettings::isYellow())); + if (GameSettings::isPrimaryAI()) { + GameSettings::setLeft(!(state.referee().blue_team_on_positive_half() ^ GameSettings::isYellow())); + } if (!GameSettings::isLeft()) roboteam_utils::rotate(state.mutable_referee()); auto const& [_, data] = World::instance(); From e65d5de794eb50ce1cca39218e0cd32c7c691279 Mon Sep 17 00:00:00 2001 From: Simone Tollardo Date: Mon, 20 Nov 2023 13:24:06 +0100 Subject: [PATCH 08/10] Do not print help msg by default on roboteam observer --- roboteam_world/src/main.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/roboteam_world/src/main.cpp b/roboteam_world/src/main.cpp index c9822e61a..df59e2af6 100644 --- a/roboteam_world/src/main.cpp +++ b/roboteam_world/src/main.cpp @@ -2,27 +2,30 @@ #include "roboteam_utils/ArgParser.h" int main(int argc, char** argv) { - std::cout << "Usage: ./roboteam_observer --log --vision-ip --referee-ip --vision-port --referee-port " << std::endl; - std::cout << " log: log data to file" << std::endl; - std::cout << " vision-ip : ip to listen for vision. Defaults to 224.5.23.2" << std::endl; - std::cout << " referee-ip : ip to listen for referee. Defaults to 224.5.23.1" << std::endl; - std::cout << " vision-port : port to listen for vision. Defaults to 10006 (use 10020 for ER-Force simulator)" << std::endl; - std::cout << " referee-port : port to listen for referee. Defaults to 10003" << std::endl; + const std::vector args(argv, argv + argc); - std::cout << std::endl; + // Search for log flag --log + auto itLog = std::find(args.begin(), args.end(), std::string("--log")); + bool shouldLog = itLog != args.end(); + + std::optional val; std::string visionip = "224.5.23.2"; std::string refereeip = "224.5.23.1"; std::string visionport_str = "10006"; std::string refereeport_str = "10003"; - const std::vector args(argv, argv + argc); + if (rtt::findFlagValue(args, "--help", true) || rtt::findFlagValue(args, "-h", true)) { + std::cout << "Usage: ./roboteam_observer --log --vision-ip --referee-ip --vision-port --referee-port " << std::endl; + std::cout << " log: log data to file" << std::endl; + std::cout << " vision-ip : ip to listen for vision. Defaults to 224.5.23.2" << std::endl; + std::cout << " referee-ip : ip to listen for referee. Defaults to 224.5.23.1" << std::endl; + std::cout << " vision-port : port to listen for vision. Defaults to 10006 (use 10020 for ER-Force simulator)" << std::endl; + std::cout << " referee-port : port to listen for referee. Defaults to 10003" << std::endl; + std::cout << "Use -h or --help to print this help message" << std::endl; - // Search for log flag --log - auto itLog = std::find(args.begin(), args.end(), std::string("--log")); - bool shouldLog = itLog != args.end(); - - std::optional val; + std::cout << std::endl; + } val = rtt::findFlagValue(args, "--vision-ip"); if (val) { From 42c4083233a63f89ae66972540d589bcd1ddcfc2 Mon Sep 17 00:00:00 2001 From: Simone Tollardo Date: Mon, 20 Nov 2023 20:40:33 +0100 Subject: [PATCH 09/10] Overwrite robothub log messages instead of appending them --- roboteam_robothub/src/RobotHubStatistics.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/roboteam_robothub/src/RobotHubStatistics.cpp b/roboteam_robothub/src/RobotHubStatistics.cpp index 340f41763..252c86ffb 100644 --- a/roboteam_robothub/src/RobotHubStatistics.cpp +++ b/roboteam_robothub/src/RobotHubStatistics.cpp @@ -49,6 +49,9 @@ void RobotHubStatistics::print() const { std::stringstream ss; + // Clear and flush + ss << "\x1B[2J\x1B[H" << std::flush; + ss << " ┏━━━━━━━━━━━━━━━━━━━┓ " << std::endl << "┏━━━━━━━━━━━━━━━━━━━━━━━━━┫ Roboteam RobotHub ┣━━━┳━━━━━━━━━━━━━━━━━━━━━━┓" << std::endl << "┃ ┗━━━━━━━━━━━━━━━━━━━┛ ┃ ┃" << std::endl From 34a516830252097144b788dad7984eb336f89295 Mon Sep 17 00:00:00 2001 From: Simone Tollardo Date: Mon, 20 Nov 2023 22:02:09 +0100 Subject: [PATCH 10/10] Feature: catch errors on 'build.sh' --- build.sh | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/build.sh b/build.sh index 217c83ede..3adca3ecf 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,19 @@ #! /bin/bash -set -e +# Exit on errors +# Note: do not concat commands with && otheriwise won't be catched +set -eo pipefail + +GREEN='\033[0;32m' +RED='\033[0;31m' +ORANGE='\033[0;33m' +RESET='\033[0m' + +error() { + echo -e "${RED}Fatal error on line $1${RESET}" >&2 +} + +trap 'error $LINENO' ERR if [ "$1" == "-y" ]; then @@ -13,40 +26,45 @@ if [ -f /.dockerenv ] || [ "$OK" = "1" ]; then if [ "$0" == "./build.sh" ]; then - echo "Checking submodules" + echo -e "${GREEN}Checking submodules${RESET}" git submodule update --init --recursive echo "Done" #rm -rf build mkdir -p build pushd build - echo "Building RoboTeamTwente software" - cmake .. -DCMAKE_BUILD_TYPE=Release && make -j$(nproc) roboteam_observer roboteam_ai roboteam_robothub + echo -e "${GREEN}Building RoboTeamTwente software${RESET}" + cmake .. -DCMAKE_BUILD_TYPE=Release + make -j$(nproc) roboteam_observer roboteam_ai roboteam_robothub popd - echo "Installing interface" + echo -e "${GREEN}Installing interface${RESET}" pushd roboteam_interface yarn install popd pushd external - echo "Building external" + echo -e "${GREEN}Building external${RESET}" pushd framework - echo "Building external/framework" - mkdir -p build && pushd build - cmake .. && make simulator-cli -j$(nproc) + echo -e "${GREEN}Building external/framework${RESET}" + mkdir -p build + pushd build + cmake .. + make simulator-cli -j$(nproc) popd popd pushd autoref - echo "Building external/autoref" - mkdir -p build && pushd build - cmake .. && make autoref-cli -j$(nproc) + echo -e "${GREEN}Building external/autoref${RESET}" + mkdir -p build + pushd build + cmake .. + make autoref-cli -j$(nproc) popd popd popd - echo "Done, exiting builder.." + echo -e "${GREEN}Done, exiting builder..${RESET}" else - echo "E: The script must be called from the root folder" + echo -e "${RED}E: The script must be called from the root folder${RESET}" exit 1 fi else - echo "W: If you really want to build outside the container call the script with -y argument." + echo -e "${ORANGE}W: If you really want to build outside the container call the script with -y argument.${RESET}" exit 1 fi