diff --git a/client_s2/docs/.gitignore b/client_s2/docs/.gitignore new file mode 100644 index 0000000..d28b948 --- /dev/null +++ b/client_s2/docs/.gitignore @@ -0,0 +1,3 @@ +build +logs.db +!lib \ No newline at end of file diff --git a/client_s2/docs/Makefile b/client_s2/docs/Makefile new file mode 100644 index 0000000..d0c3cbf --- /dev/null +++ b/client_s2/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = source +BUILDDIR = build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/client_s2/docs/make.bat b/client_s2/docs/make.bat new file mode 100644 index 0000000..6247f7e --- /dev/null +++ b/client_s2/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=source +set BUILDDIR=build + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/client_s2/docs/source/_static/.gitkeep b/client_s2/docs/source/_static/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/client_s2/docs/source/conf.py b/client_s2/docs/source/conf.py new file mode 100644 index 0000000..7e9fc73 --- /dev/null +++ b/client_s2/docs/source/conf.py @@ -0,0 +1,63 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +import os +import sys + +sys.path.insert(0, os.path.abspath('../..')) +sys.setrecursionlimit(1500) +os.environ["EXTENSIVE_LOGGING"] = "False" + +# -- Project information ----------------------------------------------------- + +project = 'CompLib' +copyright = '2022, Verein zur Förderung von Wissenschaft und Technik an Schulen (F-WuTS)' +author = 'robo4you' + +# The full version, including alpha/beta/rc tags +release = '0.2.3' + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx_rtd_theme' +] + +autodoc_mock_imports = ["smbus", "compLib.PCA9685", "RPi", + "pigpio", "flask", "apt", "influxdb_client"] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = [] + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'sphinx_rtd_theme' + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + + +language = "de" diff --git a/client_s2/docs/source/images/compair-logo-white.svg b/client_s2/docs/source/images/compair-logo-white.svg new file mode 100644 index 0000000..8fb8da1 --- /dev/null +++ b/client_s2/docs/source/images/compair-logo-white.svg @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + diff --git a/client_s2/docs/source/index.rst b/client_s2/docs/source/index.rst new file mode 100644 index 0000000..b2f4022 --- /dev/null +++ b/client_s2/docs/source/index.rst @@ -0,0 +1,18 @@ +.. image:: images/compair-logo-white.svg + +Dokumentation des Roboters +########################## + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + +Contents +********* + +.. toctree:: + :maxdepth: 5 + :glob: + + other/usage + lib/index.rst diff --git a/client_s2/docs/source/lib/classes/Motor.rst b/client_s2/docs/source/lib/classes/Motor.rst new file mode 100644 index 0000000..8c2339f --- /dev/null +++ b/client_s2/docs/source/lib/classes/Motor.rst @@ -0,0 +1,47 @@ +.. _lib_motor: + +Motoren +******** + +Dokumentation der Klasse +======================== + +.. autoclass:: compLib.Motor.Motor + :members: + +Genauere Informationen +====================== + +Power vs Speed +-------------- +Zur ansteuerung der Motoren kann entweder ``Motor.power(...)`` oder ``Motor.speed(...)`` verwendet werden. +Der Unterschied der 2 Funktionen liegt dabei in der Einheit des 2. Parameters. Bei ``Motor.power()`` wird dabei ein Wert zwischen -100% und 100% der maximalen Geschwindigkeit angegeben. +Im Gegensatz dazu erlaubt einem ``Motor.speed()`` eine Geschwindigkeit in Umdrehungen pro Minute. + +Normal vs Multiple +------------------ +Der Aufruf der funktionen kann entweder über ``Motor.power(port, percent)`` oder ``Motor.power((port, percent), (port, percent), ..)`` erfolgen. +Der zweite Aufruf ermöglicht dem Entwickler dabei beide Motoren in einem Aufruf anzusteuern und bringt einen kleinen Vorteil in der Leistungsfähigkeit der Software. + + +Beispiele +========= + +Vorwärts fahren +------------- + +Mit folgenden Programm drehen sich beide Motoren mit 50% ihrer maximalen Geschwindigkeit. +Dabei ist zu beachten, dass ein Motor in die entgegengesetzte Richtung zum aneren Motor gedreht werden muss, da diese spiegelverkehrt montiert sind. + +Zusätzlich ist ein ``time.sleep(5)`` notwendig, welches das Programm für 5 Sekunden pausiert. Diese Pause wird benötigt, da der Roboter automatisch alle Motoren beim Ende des Progammes deaktiviert. + +.. code-block:: python + + from compLib.Motor import Motor + import time + + Motor.power(0, -50) + Motor.power(3, 50) + + time.sleep(5) + diff --git a/client_s2/docs/source/lib/classes/images/chessboard.jpg b/client_s2/docs/source/lib/classes/images/chessboard.jpg new file mode 100644 index 0000000..53ffa83 Binary files /dev/null and b/client_s2/docs/source/lib/classes/images/chessboard.jpg differ diff --git a/client_s2/docs/source/lib/classes/images/chessboard_detected.jpg b/client_s2/docs/source/lib/classes/images/chessboard_detected.jpg new file mode 100644 index 0000000..4f64fb6 Binary files /dev/null and b/client_s2/docs/source/lib/classes/images/chessboard_detected.jpg differ diff --git a/client_s2/docs/source/lib/classes/images/opencv_http_stream.png b/client_s2/docs/source/lib/classes/images/opencv_http_stream.png new file mode 100644 index 0000000..8fc6853 Binary files /dev/null and b/client_s2/docs/source/lib/classes/images/opencv_http_stream.png differ diff --git a/client_s2/docs/source/lib/classes/images/opencv_processed.png b/client_s2/docs/source/lib/classes/images/opencv_processed.png new file mode 100644 index 0000000..27b59c7 Binary files /dev/null and b/client_s2/docs/source/lib/classes/images/opencv_processed.png differ diff --git a/client_s2/docs/source/lib/index.rst b/client_s2/docs/source/lib/index.rst new file mode 100644 index 0000000..5a96950 --- /dev/null +++ b/client_s2/docs/source/lib/index.rst @@ -0,0 +1,8 @@ +compLib +####### + +.. toctree:: + :maxdepth: 5 + :glob: + + classes/* diff --git a/client_s2/docs/source/other/usage.rst b/client_s2/docs/source/other/usage.rst new file mode 100644 index 0000000..0296e59 --- /dev/null +++ b/client_s2/docs/source/other/usage.rst @@ -0,0 +1,32 @@ +.. _other_usage: + +Beispiele +######### + +Vorwärts und rückwärts fahren +***************************** + +.. code-block:: python + + import time + from compLib.Motor import * + + def forward(): + Motor.power(1, -30); + Motor.power(2, 30); + + + def backward(): + Motor.power(1, 30); + Motor.power(2, -30); + + def main(): + print("hallo ich bin ein roboter beep buup") + + forward() + time.sleep(1) + backward() + time.sleep(1) + + if __name__ == '__main__': + main() \ No newline at end of file diff --git a/client_s2/sphinx_to_github.sh b/client_s2/sphinx_to_github.sh new file mode 100755 index 0000000..b4f51cb --- /dev/null +++ b/client_s2/sphinx_to_github.sh @@ -0,0 +1,23 @@ +export BUILDING_DOCS=true +cd docs || exit +rm -rf build +rm -rf gh-pages + +make html + +git clone git@github.com:F-WuTS/compLIB.git gh-pages + +cd gh-pages || exit +git checkout gh-pages + +cp -r ../build/html/* . + +git add . +git commit -a -m "Update documentation" +git push origin gh-pages + +cd .. +rm -rf gh-pages + +cd .. +export BUILDING_DOCS=false \ No newline at end of file diff --git a/server_v2/.idea/other.xml b/server_v2/.idea/other.xml deleted file mode 100644 index 6db1952..0000000 --- a/server_v2/.idea/other.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/server_v2/CMakeLists.txt b/server_v2/CMakeLists.txt index 3c4accc..3f9b80a 100755 --- a/server_v2/CMakeLists.txt +++ b/server_v2/CMakeLists.txt @@ -56,7 +56,9 @@ set(SRC_FILES src/communication/UnixSocketServer.cpp src/communication/TCPSocketServer.cpp src/GoToController.cpp - src/HealthChecker.cpp) + src/HealthChecker.cpp + src/Display.cpp + src/IPWritingService.cpp) set(HDR_FILES include/spi.hpp @@ -77,7 +79,9 @@ set(HDR_FILES include/communication/UnixSocketServer.hpp include/communication/TCPSocketServer.hpp include/GoToController.hpp - include/HealthChecker.hpp) + include/HealthChecker.hpp + include/Display.hpp + include/IPWritingService.hpp) include_directories(third_party/asio) diff --git a/server_v2/include/Display.hpp b/server_v2/include/Display.hpp new file mode 100644 index 0000000..bb40622 --- /dev/null +++ b/server_v2/include/Display.hpp @@ -0,0 +1,16 @@ +#ifndef COMPLIB_SERVER_DISPLAY_HPP +#define COMPLIB_SERVER_DISPLAY_HPP + +#include +#include + +class Display { +public: + static void write(uint8_t line, std::string text); + +private: + + Display() = default; +}; + +#endif //COMPLIB_SERVER_DISPLAY_HPP diff --git a/server_v2/include/IPWritingService.hpp b/server_v2/include/IPWritingService.hpp new file mode 100644 index 0000000..0978710 --- /dev/null +++ b/server_v2/include/IPWritingService.hpp @@ -0,0 +1,16 @@ +#ifndef COMPLIB_SERVER_IPWRITINGSERVICE_HPP +#define COMPLIB_SERVER_IPWRITINGSERVICE_HPP + +#include + +class IPWritingService { +public: + IPWritingService(); + +private: + [[noreturn]] void writing_loop(); + + std::thread writing_thread; +}; + +#endif //COMPLIB_SERVER_IPWRITINGSERVICE_HPP diff --git a/server_v2/src/Display.cpp b/server_v2/src/Display.cpp new file mode 100644 index 0000000..1aea17d --- /dev/null +++ b/server_v2/src/Display.cpp @@ -0,0 +1,7 @@ +#include "include/Display.hpp" +#include "include/spi.hpp" + +void Display::write(uint8_t line, std::string text) { + text.resize(16); + Spi::getInstance().write_array(Spi::DISPLAY_LINE_1_C0 + line * 16, 16, reinterpret_cast(text.c_str())); +} diff --git a/server_v2/src/IPWritingService.cpp b/server_v2/src/IPWritingService.cpp new file mode 100644 index 0000000..045d868 --- /dev/null +++ b/server_v2/src/IPWritingService.cpp @@ -0,0 +1,17 @@ +#include "include/IPWritingService.hpp" +#include "include/networkUtils.hpp" +#include "include/Display.hpp" + +IPWritingService::IPWritingService() { + writing_thread = std::thread(&IPWritingService::writing_loop, this); + writing_thread.detach(); +} + +void IPWritingService::writing_loop() { + while (true) { + auto host_and_ip = networkUtils::get_current_host_and_ip(); + Display::write(2, std::get<0>(host_and_ip)); + Display::write(3, std::get<1>(host_and_ip)); + std::this_thread::sleep_for(std::chrono::seconds(5)); + } +} diff --git a/server_v2/src/main.cpp b/server_v2/src/main.cpp index 0fe8bf9..07294d1 100644 --- a/server_v2/src/main.cpp +++ b/server_v2/src/main.cpp @@ -10,6 +10,7 @@ #include "include/GoToController.hpp" #include "include/Encoders.hpp" #include "include/networkUtils.hpp" +#include "include/IPWritingService.hpp" #ifdef IS_RASPI @@ -27,6 +28,7 @@ int main(int argc, char *argv[]) { UnixSocketServer unixSocketServer; TCPSocketServer tcpSocketServer; + IPWritingService ipWritingService; HealthChecker::getInstance(); #ifdef IS_RASPI