Skip to content

Commit

Permalink
Merge pull request #10 from KIT-MRT/gui
Browse files Browse the repository at this point in the history
Add WebApp GUI
  • Loading branch information
orzechow authored Nov 6, 2024
2 parents 393f982 + 8ed4e40 commit a923d0a
Show file tree
Hide file tree
Showing 78 changed files with 38,964 additions and 16 deletions.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ project(arbitration_graphs
)

# Select project features
set(BUILD_GUI "TRUE" CACHE STRING "Compile the project with the WebApp GUI")
set(BUILD_TESTS "FALSE" CACHE STRING "Compile the project with all unit tests")


Expand Down Expand Up @@ -95,6 +96,16 @@ configure_package_config_file(
)


#############
## GUI ##
#############

if(BUILD_GUI)
message("Building with WebApp GUI")
add_subdirectory(gui)
endif()


#############
## Testing ##
#############
Expand Down
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ RUN apt-get update && \
libyaml-cpp-dev && \
apt-get clean

# Install Crow dependencies
RUN apt-get update && \
apt-get install -y \
libasio-dev \
unzip \
wget &&\
apt-get clean

# Install Crow (C++ REST/WebSocket server)
RUN cd /tmp && \
wget https://github.com/CrowCpp/Crow/releases/download/v1.2.0/Crow-1.2.0.zip && \
unzip Crow-*.zip -d /tmp && \
cp -r /tmp/Crow-*/* /usr/local && \
rm -r Crow-*

# Install util_caching
RUN git clone https://github.com/KIT-MRT/util_caching.git /tmp/util_caching && \
mkdir /tmp/util_caching/build && \
Expand All @@ -38,6 +53,7 @@ FROM base AS install
# Install arbitration_graphs
COPY CMakeLists.txt /tmp/arbitration_graphs/
COPY cmake /tmp/arbitration_graphs/cmake
COPY gui /tmp/arbitration_graphs/gui
COPY include /tmp/arbitration_graphs/include
COPY test /tmp/arbitration_graphs/test
COPY version /tmp/arbitration_graphs/version
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ cd arbitration_graphs/demo
docker compose up
```

Open the GUI with your favorite browser:
http://0.0.0.0:8080

### Explanation

You will see the *Pacman Agent* arbitrator selecting between five behavior options (by priority).
Expand All @@ -63,7 +66,7 @@ In this scene,
</p>


We will shortly add an [arbitration graph GUI](https://github.com/KIT-MRT/arbitration_graphs/pull/10) and a [tutorial](https://github.com/KIT-MRT/arbitration_graphs/pull/51) based on this demo – stay tuned!
We will shortly add a [tutorial](https://github.com/KIT-MRT/arbitration_graphs/pull/51) based on this demo – stay tuned!


## Installation
Expand All @@ -90,9 +93,10 @@ find_package(arbitration_graphs REQUIRED)

First make sure all dependencies are installed:
- [glog](https://github.com/google/glog)
- [Googletest](https://github.com/google/googletest) (only if you want to build unit tests)
- [Googletest](https://github.com/google/googletest) (optional, if you want to build unit tests)
- [yaml-cpp](https://github.com/jbeder/yaml-cpp)
- [util_caching](https://github.com/KIT-MRT/util_caching)
- [Crow](https://crowcpp.org) (optional, needed for GUI only)

See also the [`Dockerfile`](./Dockerfile) for how to install these packages under Debian or Ubuntu.

Expand All @@ -113,6 +117,8 @@ cmake --build .
sudo cmake --install .
```

In order to skip compiling the GUI, use `cmake -DBUILD_GUI=false ..` instead.


## Development

Expand Down
5 changes: 3 additions & 2 deletions demo/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
cmake \
libsdl2-dev
libsdl2-dev && \
apt-get clean

# Build and install EnTT-Pacman
RUN git clone https://github.com/KIT-MRT/EnTT-Pacman.git --branch arbitration_graphs_demo /tmp/EnTT-Pacman && \
cd /tmp/EnTT-Pacman/build && \
cmake -DCMAKE_BUILD_TYPE=Release .. && \
cmake --build . && \
cmake --build . -j8 && \
cmake --install . && \
rm -rf /tmp/EnTT-Pacman

Expand Down
6 changes: 5 additions & 1 deletion demo/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ services:
- VERSION=$VERSION
target: tutorial
env_file: .env
ports:
- "8080:8080"
volumes:
- .:/home/blinky/demo
- $HOME/.Xauthority:/home/blinky/.Xauthority
Expand All @@ -15,7 +17,7 @@ services:
- DISPLAY=$DISPLAY
#
# This makes sure `docker compose up` only runs the demo service
# Use `docker compose run --rm tutorial` to run the tutorial
# Use `docker compose run --rm --service-ports tutorial` to run the tutorial
profiles: ["tutorial"]

demo:
Expand All @@ -26,6 +28,8 @@ services:
- VERSION=$VERSION
target: demo
env_file: .env
ports:
- "8080:8080"
volumes:
- $HOME/.Xauthority:/home/blinky/.Xauthority
- /tmp/.X11-unix:/tmp/.X11-unix
Expand Down
2 changes: 1 addition & 1 deletion demo/include/demo/avoid_ghost_behavior.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AvoidGhostBehavior : public arbitration_graphs::Behavior<Command> {

AvoidGhostBehavior(EnvironmentModel::Ptr environmentModel,
const Parameters& parameters,
const std::string& name = "AvoidGhostBehavior")
const std::string& name = "AvoidGhost")
: Behavior(name), environmentModel_{std::move(environmentModel)}, parameters_{parameters} {
}

Expand Down
2 changes: 1 addition & 1 deletion demo/include/demo/change_dot_cluster_behavior.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ChangeDotClusterBehavior : public arbitration_graphs::Behavior<Command> {
using Clusters = utils::DotClusterFinder::Clusters;

explicit ChangeDotClusterBehavior(EnvironmentModel::Ptr environmentModel,
const std::string& name = "ChangeDotClusterBehavior")
const std::string& name = "ChangeDotCluster")
: Behavior(name), environmentModel_{std::move(environmentModel)} {
}

Expand Down
2 changes: 1 addition & 1 deletion demo/include/demo/chase_ghost_behavior.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ChaseGhostBehavior : public arbitration_graphs::Behavior<Command> {

ChaseGhostBehavior(EnvironmentModel::Ptr environmentModel,
const Parameters& parameters,
const std::string& name = "ChaseGhostBehavior")
const std::string& name = "ChaseGhost")
: Behavior(name), environmentModel_{std::move(environmentModel)}, parameters_{parameters} {
}

Expand Down
3 changes: 1 addition & 2 deletions demo/include/demo/eat_closest_dot_behavior.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class EatClosestDotBehavior : public arbitration_graphs::Behavior<Command> {
using Ptr = std::shared_ptr<EatClosestDotBehavior>;
using ConstPtr = std::shared_ptr<const EatClosestDotBehavior>;

explicit EatClosestDotBehavior(EnvironmentModel::Ptr environmentModel,
const std::string& name = "EatClosestDotBehavior")
explicit EatClosestDotBehavior(EnvironmentModel::Ptr environmentModel, const std::string& name = "EatClosestDot")
: Behavior(name), environmentModel_{std::move(environmentModel)} {
}

Expand Down
8 changes: 8 additions & 0 deletions demo/include/demo/pacman_agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ class PacmanAgent {
to_stream(stringStream, time);
return stringStream.str();
}
std::string yamlString(const Time& time) const {
YAML::Node node;
node["type"] = "PacmanArbitrator";
node["arbitration"] = rootArbitrator_->toYaml(time);
std::stringstream yamlString;
yamlString << node;
return yamlString.str();
}

private:
EnvironmentModel::Ptr environmentModel_;
Expand Down
3 changes: 1 addition & 2 deletions demo/include/demo/stay_in_place_behavior.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class StayInPlaceBehavior : public arbitration_graphs::Behavior<Command> {
using Ptr = std::shared_ptr<StayInPlaceBehavior>;
using ConstPtr = std::shared_ptr<const StayInPlaceBehavior>;

explicit StayInPlaceBehavior(EnvironmentModel::Ptr environmentModel,
const std::string& name = "StayInPlaceBehavior")
explicit StayInPlaceBehavior(EnvironmentModel::Ptr environmentModel, const std::string& name = "StayInPlace")
: Behavior(name), environmentModel_{std::move(environmentModel)} {
}

Expand Down
13 changes: 11 additions & 2 deletions demo/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
#include <exception>
#include <iostream>
#include <thread>

#include <arbitration_graphs/gui/web_server.hpp>

#include "demo/pacman_agent.hpp"
#include "demo/types.hpp"
#include "utils/pacman_wrapper.hpp"

using namespace demo;
using namespace utils;
using namespace arbitration_graphs;

int main() {
try {
PacmanWrapper demo;
PacmanAgent agent(demo.game());

gui::WebServer server(8080, true);

while (!demo.quit()) {
agent.updateEnvironmentModel(demo.game());

Command command = agent.getCommand(Clock::now());
std::cout << agent.to_str(Clock::now()) << '\n';
const Time time = Clock::now();

Command command = agent.getCommand(time);

server.broadcast(agent.yamlString(time));

demo.progressGame(command, agent.environmentModel());
}
Expand Down
14 changes: 13 additions & 1 deletion demo/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,21 @@ if(GTEST_FOUND)

add_executable(${TEST_TARGET_NAME} ${_test})

target_include_directories(${TEST_TARGET_NAME} PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
${SDL2_INCLUDE_DIR}
)

target_link_libraries(${TEST_TARGET_NAME} PUBLIC
${GTEST_BOTH_LIBRARIES} pthread
${GTEST_BOTH_LIBRARIES}
pthread
${PROJECT_NAME}
arbitration_graphs
EnTT_Pacman
util_caching
${SDL2_LIBRARY}
${YAML_CPP_LIBRARIES}
)

add_test(NAME ${TEST_TARGET_NAME}
Expand Down
69 changes: 69 additions & 0 deletions gui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Call this from the top-level CMakeLists.txt

cmake_minimum_required(VERSION 3.22)


################
## Crow setup ##
################

# Pass install data directory to the Crow web server,
# as the Web App files will be located there

include(GNUInstallDirs)

set(CMAKE_CROW_STATIC_DIRECTORY ${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME})
message("Install directory for WebApp GUI: CROW_STATIC_DIRECTORY=${CMAKE_CROW_STATIC_DIRECTORY}")
configure_file (
"${PROJECT_SOURCE_DIR}/gui/include/arbitration_graphs/gui/crow_config.hpp.in"
"${PROJECT_BINARY_DIR}/include/arbitration_graphs/gui/crow_config.hpp"
)


###################
## Find packages ##
###################

find_package(Crow REQUIRED)


###########
## Build ##
###########

# Declare a cpp library
add_library(${PROJECT_NAME}_gui INTERFACE
include/arbitration_graphs/gui/web_server.hpp
)
target_include_directories(${PROJECT_NAME}_gui INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/gui/include/${PROJECT_NAME}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include/${PROJECT_NAME}/gui>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
)
target_link_libraries(${PROJECT_NAME}_gui INTERFACE
Crow::Crow
)


#############
## Install ##
#############

set(INSTALL_TARGETS ${INSTALL_TARGETS} ${PROJECT_NAME}_gui PARENT_SCOPE)
install(DIRECTORY htmlroot/ DESTINATION ${CMAKE_CROW_STATIC_DIRECTORY})
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include
PATTERN "*.in" EXCLUDE
)
install(DIRECTORY ${CMAKE_BINARY_DIR}/include/ DESTINATION include)


#############
## Testing ##
#############

# Testing only available if this is the main project
# Emergency override ARBITRATION_GRAPHS_GUI_CMAKE_BUILD_TESTING provided as well
if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR ARBITRATION_GRAPHS_GUI_CMAKE_BUILD_TESTING)
AND BUILD_TESTS)
add_subdirectory(test)
endif()
1 change: 1 addition & 0 deletions gui/assets/bolt-solid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions gui/assets/icon_cost.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions gui/assets/icon_delayed.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions gui/assets/icon_merging.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions gui/assets/icon_priority.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions gui/assets/icon_random.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions gui/assets/icon_reboot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions gui/assets/icon_sequence.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a923d0a

Please sign in to comment.