From edfa25fcd8edad43998f50a2144d30a6f966c1c8 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 26 May 2022 21:52:30 +0200 Subject: fix configuration on windows --- .vscode/c_cpp_properties.json | 21 +++++++++++++++++++ .vscode/tasks.json | 43 +++++++++++++++++++++++++++------------ client/makefile | 2 +- robot/makefile | 6 +----- scripts/install-mingw-packages.sh | 2 +- scripts/install-sdk.sh | 2 ++ scripts/patch-may-26.sh | 4 ++++ shared/consts.h | 5 +++++ shared/makefile | 13 ++++++++++++ 9 files changed, 78 insertions(+), 20 deletions(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 scripts/patch-may-26.sh diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..0415e98 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,21 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**", + "C:/msys64/mingw64/avr/include" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "compilerPath": "C:\\msys64\\mingw64\\bin\\gcc.exe", + "cStandard": "gnu17", + "cppStandard": "gnu++17", + "intelliSenseMode": "windows-gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 251c67d..52ccd17 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,8 +1,12 @@ { "version": "2.0.0", - "command": "C:/msys64/usr/bin/sh.exe", - "options": { "cwd": "${workspaceFolder}" }, - "args": [ "-c" ], + "options": { + "cwd": "${workspaceFolder}", + "shell": { + "executable": "C:/msys64/msys2_shell.cmd", + "args": [ "-defterm", "-no-start", "-mingw64", "-shell", "sh", "-here", "-c" ], + } + }, "tasks": [ { "label": "build client", @@ -10,8 +14,9 @@ "isDefault": false, "kind": "build" }, - "args": [ "make", "-C", "client" ], - "command": "", + "command": "make", + "args": [ "" ], + "options": { "cwd": "${workspaceFolder}/client" }, "type": "shell" }, { @@ -20,8 +25,9 @@ "isDefault": false, "kind": "build" }, - "args": [ "make", "-C", "robot" ], - "command": "", + "options": { "cwd": "${workspaceFolder}/robot" }, + "command": "make", + "args": [ "" ], "type": "shell" }, { @@ -30,8 +36,9 @@ "isDefault": false, "kind": "test" }, - "args": [ "make", "flash", "-C", "robot" ], - "command": "", + "options": { "cwd": "${workspaceFolder}/robot" }, + "command": "make flash", + "args": [ "" ], "type": "shell" }, { @@ -40,8 +47,8 @@ "isDefault": false, "kind": "none" }, - "args": [ "make", "clean" ], - "command": "", + "command": "make clean", + "args": [ "" ], "type": "shell" }, { @@ -50,8 +57,18 @@ "isDefault": false, "kind": "none" }, - "args": [ "make", "format" ], - "command": "", + "command": "make format", + "args": [ "" ], + "type": "shell" + }, + { + "label": "generate compilation db (needed for autocomplete)", + "group": { + "isDefault": false, + "kind": "build" + }, + "command": "make compile_commands", + "args": [ "" ], "type": "shell" }, ] diff --git a/client/makefile b/client/makefile index 4cca15a..f79dd11 100644 --- a/client/makefile +++ b/client/makefile @@ -25,5 +25,5 @@ format: clang-tidy --fix-errors $(SOURCES) $(HEADERS) compile_commands: clean - bear -- make + compiledb make diff --git a/robot/makefile b/robot/makefile index 4039ae3..85ed2e3 100644 --- a/robot/makefile +++ b/robot/makefile @@ -30,10 +30,6 @@ AVRDUDE=avrdude CC=$(PREFIX)gcc OBJ2HEX=$(PREFIX)objcopy -# debug build info string -BUILD_STR=$(shell git update-index -q --refresh; git describe --tags --dirty='*' --broken='x' | cut -c1-20) -CFLAGS += -DW2_BUILD_STR=\"$(BUILD_STR)\" - clean:: rm -f *.o out.hex a.out @@ -57,4 +53,4 @@ format: clang-tidy --fix-errors $(SOURCES) $(HEADERS) compile_commands: clean - bear -- make + compiledb make diff --git a/scripts/install-mingw-packages.sh b/scripts/install-mingw-packages.sh index c847e4e..fd82909 100644 --- a/scripts/install-mingw-packages.sh +++ b/scripts/install-mingw-packages.sh @@ -1,2 +1,2 @@ #!/bin/sh -pacman --noconfirm -Sy make git unzip mingw-w64-x86_64-avr-toolchain mingw-w64-x86_64-toolchain mingw-w64-clang-x86_64-clang mingw-w64-x86_64-avrdude +pacman --noconfirm -Sy make git unzip mingw-w64-x86_64-avr-toolchain mingw-w64-x86_64-toolchain mingw-w64-clang-x86_64-clang mingw-w64-x86_64-avrdude python3 python3-pip diff --git a/scripts/install-sdk.sh b/scripts/install-sdk.sh index 4773186..0cc651a 100755 --- a/scripts/install-sdk.sh +++ b/scripts/install-sdk.sh @@ -36,3 +36,5 @@ fi cd .. rm -rf temp + +pip3 install compiledb diff --git a/scripts/patch-may-26.sh b/scripts/patch-may-26.sh new file mode 100644 index 0000000..d5b41c7 --- /dev/null +++ b/scripts/patch-may-26.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +pacman --noconfirm -Sy python3 python3-pip +pip3 install compiledb diff --git a/shared/consts.h b/shared/consts.h index c65e50f..70ab5b2 100644 --- a/shared/consts.h +++ b/shared/consts.h @@ -5,6 +5,11 @@ #define W2_BUILD_STR ("????????") #endif +#if !defined W2_HOST_WIN32 && !defined W2_HOST_LINUX +#define W2_HOST_UNKNOWN +#warning "host operating system unknown" +#endif + /** max logic module execution time in milliseconds */ #define W2_MAX_MODULE_CYCLE_MS (20) /** serial baud rate (bit/s) */ diff --git a/shared/makefile b/shared/makefile index cfdf8ac..7f0ceb9 100644 --- a/shared/makefile +++ b/shared/makefile @@ -1,5 +1,18 @@ SOURCES += $(wildcard ../shared/*.c) HEADERS += $(wildcard ../shared/*.h) +# debug build info string +BUILD_STR=$(shell git update-index -q --refresh; git describe --tags --dirty='*' --broken='x' | cut -c1-20) +CFLAGS += -DW2_BUILD_STR=\"$(BUILD_STR)\" + +# os info +OS=$(strip $(shell uname -o)) +ifeq ($(OS),GNU/Linux) +CFLAGS += -DW2_HOST_LINUX +endif +ifeq ($(OS),Msys) +CFLAGS += -DW2_HOST_WIN32 +endif + clean:: rm -f ../shared/*.o -- cgit v1.2.3 From 3fd5d966f3b0cabd9f6931bc1ca416408f9e101c Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 26 May 2022 22:16:55 +0200 Subject: compile sim on windows without errors --- robot/makefile | 11 ++++++----- robot/sim.c | 35 ++++++++++++++++++++++++++++++++--- robot/sim.h | 13 +++++++++++++ shared/makefile | 9 --------- shared/os.mk | 12 ++++++++++++ 5 files changed, 63 insertions(+), 17 deletions(-) create mode 100644 shared/os.mk diff --git a/robot/makefile b/robot/makefile index 85ed2e3..a913bd7 100644 --- a/robot/makefile +++ b/robot/makefile @@ -6,18 +6,19 @@ MCU ?= atmega168 AVRDUDE_DEVICE ?= m168 PORT ?= /dev/ttyACM0 +SIM = true CFLAGS=-g -Wall $(DEVICE_SPECIFIC_CFLAGS) -Os LDFLAGS=-Wl,-gc-sections -Wl,-relax -all: $(if $(SIM), a.out, out.hex) +include ../shared/os.mk +all: $(if $(SIM), $(TARGET), out.hex) SOURCES := $(filter-out sim.c, $(wildcard *.c)) HEADERS := $(filter-out sim.h, $(wildcard *.h)) include ../shared/makefile # simulation -# SIM = true CFLAGS += $(if $(SIM), -DW2_SIM, -mcall-prologues -mmcu=$(MCU)) LDFLAGS += $(if $(SIM), , -lpololu_$(DEVICE)) PREFIX := $(if $(SIM), , avr-) @@ -31,15 +32,15 @@ CC=$(PREFIX)gcc OBJ2HEX=$(PREFIX)objcopy clean:: - rm -f *.o out.hex a.out + rm -f *.o out.hex $(TARGET) -a.out: $(OBJECTS) +$(TARGET): $(OBJECTS) $(CC) $(OBJECTS) $(CFLAGS) $(LDFLAGS) .o: $(CC) -c $(CFLAGS) $< -out.hex: a.out +out.hex: $(TARGET) $(OBJ2HEX) -R .eeprom -O ihex $< $@ $(info build $(BUILD_STR) complete) diff --git a/robot/sim.c b/robot/sim.c index 0f1c7e6..ba9aa4a 100644 --- a/robot/sim.c +++ b/robot/sim.c @@ -2,16 +2,31 @@ #include #include #include -#include #include +#ifdef W2_HOST_LINUX +#include +#endif + +#ifdef W2_HOST_WIN32 +// garbage os compatibility +#include +#include +#define STDIN_FILENO 0 +#endif + #include "sim.h" #include "../shared/consts.h" #include "../shared/protocol.h" #include "sercomm.h" #include "errcatch.h" +#ifdef W2_HOST_LINUX struct timespec reference_time; // NOLINT +#endif +#ifdef W2_HOST_WIN32 +DWORD reference_time; // NOLINT +#endif bool g_w2_sim_headless = false; static const char* const W2_CMD_NAMES[] = { @@ -38,15 +53,20 @@ static const char* const W2_CMD_DIRECTIONS[] = { void time_reset() { simprintfunc("time_reset", ""); +#ifdef W2_HOST_LINUX clock_gettime(CLOCK_MONOTONIC, &reference_time); +#endif } unsigned long get_ms() { simprintfunc("get_ms", ""); +#ifdef W2_HOST_LINUX struct timespec elapsed; clock_gettime(CLOCK_MONOTONIC, &elapsed); return ((elapsed.tv_sec * 1000) + (elapsed.tv_nsec / 1000000)) - ((reference_time.tv_sec * 1000) + (reference_time.tv_nsec / 1000000)); +#endif + return 0; } void red_led(unsigned char on) { @@ -85,7 +105,7 @@ void serial_send(char* message, unsigned int length) { } void serial_receive_ring(char* buffer, unsigned char size) { - simprintfunc("serial_receive_ring", "0x%016lx, %u", (unsigned long) buffer, size); + simprintfunc("serial_receive_ring", "0x%016llx, %u", (uint64_t) buffer, size); } unsigned char serial_get_received_bytes() { @@ -98,12 +118,21 @@ void w2_sim_setup(int argc, char **argv) { g_w2_sim_headless = true; // disable echo and enable raw mode +#ifdef W2_HOST_LINUX struct termios term; tcgetattr(STDIN_FILENO, &term); term.c_lflag &= ~(ECHO | ICANON); term.c_cc[VTIME] = 0; term.c_cc[VMIN] = 0; tcsetattr(STDIN_FILENO, 0, &term); +#endif +#ifdef W2_HOST_WIN32 + DWORD mode; + HANDLE console = GetStdHandle(STD_INPUT_HANDLE); + + GetConsoleMode(console, &mode); + SetConsoleMode(console, mode & ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT)); +#endif // debug error // w2_errcatch_throw(W2_E_WARN_BATTERY_LOW); @@ -141,7 +170,7 @@ unsigned char get_single_debounced_button_press(unsigned char buttons) { } void qtr_read(unsigned int* sensor_values, unsigned char read_mode) { - simprintfunc("qtr_read", "0x%016lx, %s", (uint64_t) sensor_values, read_mode == QTR_EMITTERS_ON ? "QTR_EMITTERS_ON" : "???"); + simprintfunc("qtr_read", "0x%016llx, %s", (uint64_t) sensor_values, read_mode == QTR_EMITTERS_ON ? "QTR_EMITTERS_ON" : "???"); sensor_values[0] = 0; sensor_values[1] = 0; sensor_values[2] = 0; diff --git a/robot/sim.h b/robot/sim.h index ab1cd77..08c1d8a 100644 --- a/robot/sim.h +++ b/robot/sim.h @@ -22,6 +22,7 @@ extern bool g_w2_sim_headless; #define DBG_BYTES_PER_LINE 16 // debug colors +#ifdef W2_HOST_LINUX #define COL_BLK "\e[0;30m" #define COL_RED "\e[0;31m" #define COL_GRN "\e[0;32m" @@ -31,6 +32,18 @@ extern bool g_w2_sim_headless; #define COL_CYN "\e[0;36m" #define COL_WHT "\e[0;37m" #define COL_RST "\e[0m" +#endif +#ifdef W2_HOST_WIN32 +#define COL_BLK "" +#define COL_RED "" +#define COL_GRN "" +#define COL_YEL "" +#define COL_BLU "" +#define COL_MAG "" +#define COL_CYN "" +#define COL_WHT "" +#define COL_RST "" +#endif // debug stdout print macros #define simprintf(message, ...) if (!g_w2_sim_headless) printf(COL_RED "[SIM] " COL_RST message, ##__VA_ARGS__) diff --git a/shared/makefile b/shared/makefile index 7f0ceb9..e5a6ff6 100644 --- a/shared/makefile +++ b/shared/makefile @@ -5,14 +5,5 @@ HEADERS += $(wildcard ../shared/*.h) BUILD_STR=$(shell git update-index -q --refresh; git describe --tags --dirty='*' --broken='x' | cut -c1-20) CFLAGS += -DW2_BUILD_STR=\"$(BUILD_STR)\" -# os info -OS=$(strip $(shell uname -o)) -ifeq ($(OS),GNU/Linux) -CFLAGS += -DW2_HOST_LINUX -endif -ifeq ($(OS),Msys) -CFLAGS += -DW2_HOST_WIN32 -endif - clean:: rm -f ../shared/*.o diff --git a/shared/os.mk b/shared/os.mk new file mode 100644 index 0000000..e4ede42 --- /dev/null +++ b/shared/os.mk @@ -0,0 +1,12 @@ +# os info +OS=$(strip $(shell uname -o)) +ifeq ($(OS),GNU/Linux) +CFLAGS += -DW2_HOST_LINUX +LINUX := true +TARGET := a.out +endif +ifeq ($(OS),Msys) +CFLAGS += -DW2_HOST_WIN32 +WIN32 := true +TARGET := a.exe +endif \ No newline at end of file -- cgit v1.2.3 From b6460d729aa683643e7ad83a9921f335f0fdba93 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 26 May 2022 22:17:19 +0200 Subject: disable sim on master branch --- robot/makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/robot/makefile b/robot/makefile index a913bd7..f65552a 100644 --- a/robot/makefile +++ b/robot/makefile @@ -6,7 +6,7 @@ MCU ?= atmega168 AVRDUDE_DEVICE ?= m168 PORT ?= /dev/ttyACM0 -SIM = true +# SIM = true CFLAGS=-g -Wall $(DEVICE_SPECIFIC_CFLAGS) -Os LDFLAGS=-Wl,-gc-sections -Wl,-relax -- cgit v1.2.3 From bfa494588da0def96c42577e284c6d8990eb31f2 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 26 May 2022 22:46:17 +0200 Subject: add doxygen --- .gitignore | 1 + Doxyfile | 21 +++++++++++++++++++++ makefile | 5 ++++- robot/errcatch.h | 2 ++ robot/hypervisor.h | 2 ++ robot/io.h | 6 ++++-- robot/main.h | 2 ++ robot/mode_chrg.h | 2 ++ robot/mode_dirc.h | 2 ++ robot/mode_grid.h | 2 ++ robot/mode_halt.h | 2 ++ robot/mode_lcal.h | 2 ++ robot/mode_maze.h | 2 ++ robot/mode_scal.h | 2 ++ robot/mode_spin.h | 2 ++ robot/modes.h | 2 ++ robot/orangutan_shim.h | 2 ++ robot/sercomm.h | 2 ++ robot/setup.h | 2 ++ robot/sim.h | 2 ++ shared/bin.h | 3 +++ shared/consts.h | 4 +++- shared/errors.h | 2 ++ shared/protocol.h | 2 ++ shared/semver.h | 2 ++ shared/serial_parse.h | 2 ++ shared/util.h | 2 ++ 27 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 Doxyfile diff --git a/.gitignore b/.gitignore index d493881..74f4594 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ client/main .cache *.log scripts/InstallationLog.txt +docs/ diff --git a/Doxyfile b/Doxyfile new file mode 100644 index 0000000..8c225e9 --- /dev/null +++ b/Doxyfile @@ -0,0 +1,21 @@ +DOXYFILE_ENCODING = UTF-8 +PROJECT_NAME = "wall-e2" +# PROJECT_NUMBER = +PROJECT_BRIEF = Project RobotRun software +OUTPUT_DIRECTORY = docs/ +CREATE_SUBDIRS = NO +ALLOW_UNICODE_NAMES = NO +OUTPUT_LANGUAGE = English +TAB_SIZE = 4 +FILE_PATTERNS = *.c \ + *.h \ + *.md +RECURSIVE = YES +USE_MDFILE_AS_MAINPAGE = ./readme.md +SOURCE_BROWSER = YES +INLINE_SOURCES = YES +STRIP_CODE_COMMENTS = NO +REFERENCED_BY_RELATION = YES +REFERENCES_RELATION = YES +CALL_GRAPH = YES +# INPUT = robot/ diff --git a/makefile b/makefile index 7795106..832bde9 100644 --- a/makefile +++ b/makefile @@ -5,4 +5,7 @@ all clean format compile_commands: $(SUBDIRS) FORCE $(SUBDIRS): FORCE $(MAKE) -C $@ $(MAKECMDGOALS) -FORCE: \ No newline at end of file +FORCE: + +docs: + doxygen diff --git a/robot/errcatch.h b/robot/errcatch.h index 836da1b..add4ece 100644 --- a/robot/errcatch.h +++ b/robot/errcatch.h @@ -1,5 +1,7 @@ #pragma once +/** @file errcatch.h */ + #include #include "../shared/consts.h" diff --git a/robot/hypervisor.h b/robot/hypervisor.h index 5008c8f..b5dc0ab 100644 --- a/robot/hypervisor.h +++ b/robot/hypervisor.h @@ -1,5 +1,7 @@ #pragma once +/** @file hypervisor.h */ + #include extern uint64_t g_w2_hypervisor_cycles; diff --git a/robot/io.h b/robot/io.h index 3d91799..be0e9b9 100644 --- a/robot/io.h +++ b/robot/io.h @@ -1,9 +1,11 @@ #pragma once +/** @file io.h */ + #include "../shared/protocol.h" -/** i/o module main */ +/** @brief i/o module main */ void w2_io_main(); -/** global struct containing all i/o */ +/** @brief global struct containing all i/o */ extern w2_s_io_all g_w2_io; diff --git a/robot/main.h b/robot/main.h index 5b0a1b2..58f849b 100644 --- a/robot/main.h +++ b/robot/main.h @@ -1,4 +1,6 @@ #pragma once +/** @file main.h */ + /** program entrypoint */ int main(); diff --git a/robot/mode_chrg.h b/robot/mode_chrg.h index d9b5cc0..a870e58 100644 --- a/robot/mode_chrg.h +++ b/robot/mode_chrg.h @@ -1,5 +1,7 @@ #pragma once +/** @file mode_chrg.h */ + /** * charge station mode * diff --git a/robot/mode_dirc.h b/robot/mode_dirc.h index 5b9bbf4..12c967a 100644 --- a/robot/mode_dirc.h +++ b/robot/mode_dirc.h @@ -1,5 +1,7 @@ #pragma once +/** @file mode_dirc.h */ + #include extern int16_t g_w2_mode_dirc_motor_l; diff --git a/robot/mode_grid.h b/robot/mode_grid.h index fcf9100..55093ad 100644 --- a/robot/mode_grid.h +++ b/robot/mode_grid.h @@ -1,5 +1,7 @@ #pragma once +/** @file mode_grid.h */ + /** * warehouse mode * diff --git a/robot/mode_halt.h b/robot/mode_halt.h index d92905e..b5ac11f 100644 --- a/robot/mode_halt.h +++ b/robot/mode_halt.h @@ -1,5 +1,7 @@ #pragma once +/** @file mode_halt.h */ + /** * halt (emergency) mode * diff --git a/robot/mode_lcal.h b/robot/mode_lcal.h index dd373f0..5a43701 100644 --- a/robot/mode_lcal.h +++ b/robot/mode_lcal.h @@ -1,5 +1,7 @@ #pragma once +/** @file mode_lcal.h */ + /** * calibration mode * diff --git a/robot/mode_maze.h b/robot/mode_maze.h index 9fbeb8c..e7490b9 100644 --- a/robot/mode_maze.h +++ b/robot/mode_maze.h @@ -1,5 +1,7 @@ #pragma once +/** @file mode_maze.h */ + /** * maze mode * diff --git a/robot/mode_scal.h b/robot/mode_scal.h index 4f1f04d..c427d4b 100644 --- a/robot/mode_scal.h +++ b/robot/mode_scal.h @@ -1,5 +1,7 @@ #pragma once +/** @file mode_scal.h */ + /** * sensor calibration mode * diff --git a/robot/mode_spin.h b/robot/mode_spin.h index 926137e..1f721dc 100644 --- a/robot/mode_spin.h +++ b/robot/mode_spin.h @@ -1,5 +1,7 @@ #pragma once +/** @file mode_spin.h */ + /** * wet floor simulation * diff --git a/robot/modes.h b/robot/modes.h index 3423a0f..122be4a 100644 --- a/robot/modes.h +++ b/robot/modes.h @@ -1,5 +1,7 @@ #pragma once +/** @file modes.h */ + #include "../shared/consts.h" #include "mode_chrg.h" diff --git a/robot/orangutan_shim.h b/robot/orangutan_shim.h index 10420bd..cbb0995 100644 --- a/robot/orangutan_shim.h +++ b/robot/orangutan_shim.h @@ -1,5 +1,7 @@ #pragma once +/** @file orangutan_shim.h */ + #ifdef W2_SIM #include "sim.h" #else diff --git a/robot/sercomm.h b/robot/sercomm.h index b1f69c7..13625c0 100644 --- a/robot/sercomm.h +++ b/robot/sercomm.h @@ -1,5 +1,7 @@ #pragma once +/** @file sercomm.h */ + #include "../shared/bin.h" #include "../shared/consts.h" #include "../shared/protocol.h" diff --git a/robot/setup.h b/robot/setup.h index 17ac78d..450e102 100644 --- a/robot/setup.h +++ b/robot/setup.h @@ -1,5 +1,7 @@ #pragma once +/** @file setup.h */ + /** * runs once at startup, plays beep when setup finishes * diff --git a/robot/sim.h b/robot/sim.h index 08c1d8a..76b57f8 100644 --- a/robot/sim.h +++ b/robot/sim.h @@ -1,5 +1,7 @@ #pragma once +/** @file sim.h */ + #include #include #include diff --git a/shared/bin.h b/shared/bin.h index af3a249..48485c8 100644 --- a/shared/bin.h +++ b/shared/bin.h @@ -1,4 +1,7 @@ #pragma once + +/** @file bin.h */ + /** * helper file for binary data * diff --git a/shared/consts.h b/shared/consts.h index 70ab5b2..50b16b9 100644 --- a/shared/consts.h +++ b/shared/consts.h @@ -1,5 +1,7 @@ #pragma once +/** @file consts.h */ + #ifndef W2_BUILD_STR // is defined by CFLAGS += -DW2_BUILD_STR in makefile #define W2_BUILD_STR ("????????") @@ -30,4 +32,4 @@ /** battery voltage sensor pinout */ #define W2_BATTERY_PIN 6 /** side-facing distance sensor pinout */ -#define W2_SIDE_SENSOR_PIN 7 \ No newline at end of file +#define W2_SIDE_SENSOR_PIN 7 diff --git a/shared/errors.h b/shared/errors.h index ac8e95f..4c9f7c8 100644 --- a/shared/errors.h +++ b/shared/errors.h @@ -1,5 +1,7 @@ #pragma once +/** @file errors.h */ + #include #define W2_E_TYPE_MASK (0b11 << 6) diff --git a/shared/protocol.h b/shared/protocol.h index 7aa5e9f..05cde03 100644 --- a/shared/protocol.h +++ b/shared/protocol.h @@ -1,5 +1,7 @@ #pragma once +/** @file protocol.h */ + #include #include diff --git a/shared/semver.h b/shared/semver.h index a99ae61..6a1da79 100644 --- a/shared/semver.h +++ b/shared/semver.h @@ -1,5 +1,7 @@ #pragma once +/** @file semver.h */ + #include typedef struct { diff --git a/shared/serial_parse.h b/shared/serial_parse.h index a1c8fb9..03c420f 100644 --- a/shared/serial_parse.h +++ b/shared/serial_parse.h @@ -1,5 +1,7 @@ #pragma once +/** @file serial_parse.h */ + #include #include "protocol.h" diff --git a/shared/util.h b/shared/util.h index 9e4d8ac..465e043 100644 --- a/shared/util.h +++ b/shared/util.h @@ -1,5 +1,7 @@ #pragma once +/** @file util.h */ + #define W2_MIN(a, b) (((a) < (b)) ? (a) : (b)) #define W2_MAX(a, b) (((a) > (b)) ? (a) : (b)) #define W2_RANGE(min, val, max) W2_MIN(max, W2_MAX(val, min)) -- cgit v1.2.3 From 3bbe41a04b6053a3a3a902384850cfcbd38b0686 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 27 May 2022 11:40:05 +0200 Subject: move things around and add todo's to robot readme --- robot/io.h | 2 +- robot/readme.md | 20 ++++++++++--------- shared/bool.h | 9 +++++++++ shared/io.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ shared/protocol.h | 56 ++-------------------------------------------------- 5 files changed, 82 insertions(+), 64 deletions(-) create mode 100644 shared/bool.h create mode 100644 shared/io.h diff --git a/robot/io.h b/robot/io.h index be0e9b9..64ce293 100644 --- a/robot/io.h +++ b/robot/io.h @@ -2,7 +2,7 @@ /** @file io.h */ -#include "../shared/protocol.h" +#include "../shared/io.h" /** @brief i/o module main */ void w2_io_main(); diff --git a/robot/readme.md b/robot/readme.md index b27c06f..25e730f 100644 --- a/robot/readme.md +++ b/robot/readme.md @@ -72,15 +72,15 @@ what they're supposed to do: this list will probably get updated from time to time: -- modules shouldn't create any global state variables, they should use `static` - variables instead. -- modules are run cyclically, so they shouldn't take more than +- logic modules shouldn't create any global state variables if possible, they + should use `static` variables instead +- logic modules are run cyclically, so they shouldn't take more than `W2_MAX_MODULE_CYCLE_MS` to execute (this is an arbitrary number, and may be - changed). + changed) - documentation comments should follow the [javadoc-style doxygen format](https://wiki.scilab.org/Doxygen%20documentation%20Examples) and be - placed in header (.h) files if possible. this only applies to public members - (e.g. no local variables or module-internal code). + placed in header (.h) files. this only applies to public members (e.g. no + local variables or module-internal code) - code style is mostly handled by `clang-format` and `clang-tidy`, but you should still follow these naming conventions (`` indicate placeholders): @@ -93,15 +93,15 @@ this list will probably get updated from time to time: |enum|`w2_e_`|`w2_e_errorcodes`; `w2_e_serial_commands`| this again only applies to public members. local variables should still have - short descriptive names, but shouldn't be prefixed with `w2_*`. + short descriptive names, but shouldn't be prefixed with `w2_*` - arbitrary numbers should be aliased to `#define` statements or `enum`s if - part of a series. + part of a series - general constants should be placed in `consts.h` - don't import `` directly, instead use `"orangutan_shim.h"` to keep code compatible with the simulator - don't use ``, instead use `"../shared/protocol.h"`. this makes sure that `bool` values are equal to `uint8_t`. they're functionally - identical. + identical ## todo @@ -119,6 +119,8 @@ global todo: placing the robot and pressing a button (maybe make this a seperate mode) - [ ] create labeled timer functions like nodejs `console.time()` and `console.timeEnd()` (use for serial read timeout constraint) +- [ ] `serial_parse` doesn't properly handle escaped `0xff` bytes in listen + mode ### hypervisor diff --git a/shared/bool.h b/shared/bool.h new file mode 100644 index 0000000..9ea97f7 --- /dev/null +++ b/shared/bool.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +/** @file bool.h */ + +typedef uint8_t bool; +#define false 0 /* NOLINT */ +#define true 1 /* NOLINT */ diff --git a/shared/io.h b/shared/io.h new file mode 100644 index 0000000..584ad1e --- /dev/null +++ b/shared/io.h @@ -0,0 +1,59 @@ +#pragma once + +#include + +#include "bool.h" + +#pragma pack(push, 1) + +/** momentary button input struct */ +typedef struct { + bool pressed; +} w2_s_i_push; + +/** qtr contrast sensor input struct */ +typedef struct { + uint16_t range; +} w2_s_i_contrast; + +/** distance sensor input struct */ +typedef struct { + uint16_t detection; +} w2_s_i_distance; + +/** battery input struct */ +typedef struct { + uint16_t charge_level; +} w2_s_i_battery; + +/** motor output struct */ +typedef struct { + int16_t speed; +} w2_s_o_motor; + +/** underside led output struct */ +typedef struct { + bool on; +} w2_s_o_led; + +/** lcd output struct */ +typedef struct { + char text[16]; +} w2_s_o_display; + +/** struct containing all i/o */ +typedef struct { + w2_s_i_push button[5]; + w2_s_i_contrast qtr[5]; + w2_s_i_distance front_distance; + w2_s_i_distance side_distance; + w2_s_i_battery battery; + + w2_s_o_motor motor_left; + w2_s_o_motor motor_right; + w2_s_o_led led_red; + w2_s_o_led led_green; + w2_s_o_display lcd; +} w2_s_io_all; + +#pragma pack(pop) diff --git a/shared/protocol.h b/shared/protocol.h index 05cde03..2e1e4ea 100644 --- a/shared/protocol.h +++ b/shared/protocol.h @@ -6,11 +6,9 @@ #include #include "bin.h" +#include "bool.h" #include "consts.h" - -typedef uint8_t bool; -#define false 0 /* NOLINT */ -#define true 1 /* NOLINT */ +#include "io.h" #define W2_SERIAL_START_BYTE 0xff @@ -54,56 +52,6 @@ typedef enum { #pragma pack(push, 1) -/** momentary button input struct */ -typedef struct { - bool pressed; -} w2_s_i_push; - -/** qtr contrast sensor input struct */ -typedef struct { - uint16_t range; -} w2_s_i_contrast; - -/** distance sensor input struct */ -typedef struct { - uint16_t detection; -} w2_s_i_distance; - -/** battery input struct */ -typedef struct { - uint16_t charge_level; -} w2_s_i_battery; - -/** motor output struct */ -typedef struct { - int16_t speed; -} w2_s_o_motor; - -/** underside led output struct */ -typedef struct { - bool on; -} w2_s_o_led; - -/** lcd output struct */ -typedef struct { - char text[16]; -} w2_s_o_display; - -/** struct containing all i/o */ -typedef struct { - w2_s_i_push button[5]; - w2_s_i_contrast qtr[5]; - w2_s_i_distance front_distance; - w2_s_i_distance side_distance; - w2_s_i_battery battery; - - w2_s_o_motor motor_left; - w2_s_o_motor motor_right; - w2_s_o_led led_red; - w2_s_o_led led_green; - w2_s_o_display lcd; -} w2_s_io_all; - typedef struct { uint8_t opcode; uint8_t id; -- cgit v1.2.3 From 05318790dcbd6714a2adb3532e902a56a6638ca0 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 27 May 2022 12:16:53 +0200 Subject: edit robot readme --- robot/readme.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/robot/readme.md b/robot/readme.md index 25e730f..0c8f626 100644 --- a/robot/readme.md +++ b/robot/readme.md @@ -39,10 +39,15 @@ organizational and form more of a software 'skeleton', while the 'maze' and ┌────────┴───────┐┌─────────┴────────┐┌────────┴─────────┐┌─────┴──────┐ │ Error handling ││ I/O Read & Write ││ PC communication ││ Mode logic │ └────────────────┘└──────────────────┘└──────────────────┘└─────┬──────┘ - ┌──────────┬──────────────┬───────────────┤ - ┌───┴──┐┌──────┴────┐┌────────┴───────┐┌──────┴──────┐ - *modes* -> │ Maze ││ Warehouse ││ Emergency stop ││ Calibration │ - └──────┘└───────────┘└────────────────┘└─────────────┘ + │ + Maze ─┤ + Warehouse ─┤ + Emergency stop ─┤ + *modes* -> Line finding ─┤ + Charge station ─┤ + Direct control ─┤ + Wet floor ─┤ + Sensor calibration ─┘ ``` this diagram roughly describes how different parts of the robot software are @@ -64,7 +69,7 @@ what they're supposed to do: |emergency stop |`mode_halt `|may 31|Fiona| stops all execution until emergency mode is reset by software or user| |line finding |`mode_lcal `|may 31|Fiona| find line by turning on own axis if lost| |charge station |`mode_chrg `|may 31|Fiona| go to the charging station transition in the grid, and continue until a black circle is found| -|direct control |`mode_dirc `|may 31|Loek| respond to [DIRC](../protocol.md#DIRC) commands| +|direct control |`mode_dirc `|done|Loek| respond to [DIRC](../protocol.md#DIRC) commands| |wet floor |`mode_spin `|may 31|Fiona| spin uncontrollably (simulating wet floor??)| |sensor calibration|`mode_scal `|may 31|Jorn & Abdullaahi| calibrate underside uv sensors| -- cgit v1.2.3 From 4c4d045329c4a149bae0b53952c39c14243e1870 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 27 May 2022 12:53:42 +0200 Subject: throw error on noisy serial channel --- robot/- | 0 robot/hypervisor.c | 21 +++++++++++++++------ robot/hypervisor.h | 8 ++++++++ robot/readme.md | 2 +- robot/sercomm.c | 21 +++++++++++++++++++++ robot/sim.c | 4 ++-- robot/sim.h | 6 ++++++ shared/consts.h | 15 +++++++++------ shared/errors.h | 2 -- shared/protocol.c | 19 ------------------- 10 files changed, 62 insertions(+), 36 deletions(-) create mode 100644 robot/- diff --git a/robot/- b/robot/- new file mode 100644 index 0000000..e69de29 diff --git a/robot/hypervisor.c b/robot/hypervisor.c index 0baa406..1fd3ac2 100644 --- a/robot/hypervisor.c +++ b/robot/hypervisor.c @@ -6,12 +6,13 @@ #include "orangutan_shim.h" #include "sercomm.h" -uint64_t g_w2_hypervisor_cycles = 0; -uint64_t g_w2_hypervisor_uptime_ms = 0; -unsigned long g_w2_hypervisor_ema_sercomm_ms = 0; -unsigned long g_w2_hypervisor_ema_errcatch_ms = 0; -unsigned long g_w2_hypervisor_ema_io_ms = 0; -unsigned long g_w2_hypervisor_ema_mode_ms = 0; +uint64_t g_w2_hypervisor_cycles = 0; +uint64_t g_w2_hypervisor_uptime_ms = 0; +unsigned long g_w2_hypervisor_ema_sercomm_ms = 0; +unsigned long g_w2_hypervisor_ema_errcatch_ms = 0; +unsigned long g_w2_hypervisor_ema_io_ms = 0; +unsigned long g_w2_hypervisor_ema_mode_ms = 0; +uint64_t g_w2_hypervisor_timers[W2_HYPERVISOR_TIMER_COUNT] = {0}; void w2_hypervisor_main() { #ifdef W2_SIM @@ -51,3 +52,11 @@ void w2_hypervisor_main() { g_w2_hypervisor_cycles++; } + +void w2_hypervisor_time_start(uint8_t label) { + g_w2_hypervisor_timers[label] = g_w2_hypervisor_uptime_ms; +} + +uint64_t w2_hypervisor_time_end(uint8_t label) { + return g_w2_hypervisor_uptime_ms - g_w2_hypervisor_timers[label]; +} diff --git a/robot/hypervisor.h b/robot/hypervisor.h index b5dc0ab..589d324 100644 --- a/robot/hypervisor.h +++ b/robot/hypervisor.h @@ -4,6 +4,9 @@ #include +/** amount of parallel timers */ +#define W2_HYPERVISOR_TIMER_COUNT (1) + extern uint64_t g_w2_hypervisor_cycles; extern uint64_t g_w2_hypervisor_uptime_ms; @@ -18,3 +21,8 @@ extern unsigned long g_w2_hypervisor_ema_mode_ms; * stores global variables and controls when other modules run */ void w2_hypervisor_main(); + +/** start timer with label `label` */ +void w2_hypervisor_time_start(uint8_t label); +/** stop timer with label `label` */ +uint64_t w2_hypervisor_time_end(uint8_t label); diff --git a/robot/readme.md b/robot/readme.md index 0c8f626..168be02 100644 --- a/robot/readme.md +++ b/robot/readme.md @@ -43,7 +43,7 @@ organizational and form more of a software 'skeleton', while the 'maze' and Maze ─┤ Warehouse ─┤ Emergency stop ─┤ - *modes* -> Line finding ─┤ + *logic modes* -> Line finding ─┤ Charge station ─┤ Direct control ─┤ Wet floor ─┤ diff --git a/robot/sercomm.c b/robot/sercomm.c index 2736030..83d6419 100644 --- a/robot/sercomm.c +++ b/robot/sercomm.c @@ -3,6 +3,7 @@ #include "../shared/bin.h" #include "../shared/serial_parse.h" +#include "errcatch.h" #include "hypervisor.h" #include "io.h" #include "mode_dirc.h" @@ -51,6 +52,26 @@ void w2_sercomm_append_msg(w2_s_bin *data) { g_w2_sercomm_index = next_index; } +void w2_cmd_handler(uint8_t data[W2_SERIAL_READ_BUFFER_SIZE], uint8_t data_length) { + w2_s_bin *copy = w2_bin_s_alloc(data_length, data); + void (*handler)(w2_s_bin *) = g_w2_cmd_handlers[data[0]]; + + if (handler == NULL) { +#ifdef W2_SIM + // TODO throw warning + simwarn("unknown serial message with code 0x%02x\n", data[0]); +#endif + w2_errcatch_throw(W2_E_WARN_SERIAL_NOISY); + } else { +#ifdef W2_SIM + w2_sim_print_serial(copy); +#endif + handler(copy); + } + + free(copy); +} + void w2_cmd_ping_rx(w2_s_bin *data) { w2_s_cmd_ping_rx *message = malloc(w2_cmd_sizeof(data->data, data->bytes)); memcpy(message, data->data, data->bytes); diff --git a/robot/sim.c b/robot/sim.c index ba9aa4a..4efdc4d 100644 --- a/robot/sim.c +++ b/robot/sim.c @@ -105,7 +105,7 @@ void serial_send(char* message, unsigned int length) { } void serial_receive_ring(char* buffer, unsigned char size) { - simprintfunc("serial_receive_ring", "0x%016llx, %u", (uint64_t) buffer, size); + simprintfunc("serial_receive_ring", PTR_FMT ", %u", (uint64_t) buffer, size); } unsigned char serial_get_received_bytes() { @@ -170,7 +170,7 @@ unsigned char get_single_debounced_button_press(unsigned char buttons) { } void qtr_read(unsigned int* sensor_values, unsigned char read_mode) { - simprintfunc("qtr_read", "0x%016llx, %s", (uint64_t) sensor_values, read_mode == QTR_EMITTERS_ON ? "QTR_EMITTERS_ON" : "???"); + simprintfunc("qtr_read", PTR_FMT ", %s", (uint64_t) sensor_values, read_mode == QTR_EMITTERS_ON ? "QTR_EMITTERS_ON" : "???"); sensor_values[0] = 0; sensor_values[1] = 0; sensor_values[2] = 0; diff --git a/robot/sim.h b/robot/sim.h index 76b57f8..aa587cd 100644 --- a/robot/sim.h +++ b/robot/sim.h @@ -54,6 +54,12 @@ extern bool g_w2_sim_headless; COL_CYN name COL_RST "(" COL_YEL fmt COL_RST ")\n", ##__VA_ARGS__); } #define simwarn(message, ...) if (DBG_ENABLE_SIMWARN) { simprintf(COL_YEL "[WARN] " COL_RST message, ##__VA_ARGS__); } #define siminfo(message, ...) if (DBG_ENABLE_SIMINFO) { simprintf(COL_MAG "[INFO] " COL_RST message, ##__VA_ARGS__); } +#ifdef W2_HOST_LINUX +#define PTR_FMT "0x%016lx" +#endif +#ifdef W2_HOST_WIN32 +#define PTR_FMT "0x%016llx" +#endif #define BUTTON_A 0 #define BUTTON_B 1 diff --git a/shared/consts.h b/shared/consts.h index 50b16b9..cdd96b3 100644 --- a/shared/consts.h +++ b/shared/consts.h @@ -12,21 +12,24 @@ #warning "host operating system unknown" #endif -/** max logic module execution time in milliseconds */ -#define W2_MAX_MODULE_CYCLE_MS (20) /** serial baud rate (bit/s) */ #define W2_SERIAL_BAUD (9600) +/** size of input (receive) buffer (in bytes) */ +#define W2_SERIAL_READ_BUFFER_SIZE (255) + /** size of the error handling buffer (in errors, not bytes) */ #define W2_ERROR_BUFFER_SIZE (16) /** size of the serial communication buffer (in messages, not bytes) */ #define W2_SERCOMM_BUFFER_SIZE (16) -/** size of input (receive) buffer (in bytes) */ -#define W2_SERIAL_READ_BUFFER_SIZE (255) -/** exponential moving average new measurement weight (double 0-1) */ -#define W2_EMA_WEIGHT (0.10) /** size of mode history buffer */ #define W2_MODE_HISTORY_BUFFER_SIZE (4) +/** max logic module execution time in milliseconds */ +#define W2_MAX_MODULE_CYCLE_MS (20) + +/** exponential moving average new measurement weight (double 0-1) */ +#define W2_EMA_WEIGHT (0.10) + /** front-facing distance sensor pinout */ #define W2_FRONT_SENSOR_PIN 5 /** battery voltage sensor pinout */ diff --git a/shared/errors.h b/shared/errors.h index 4c9f7c8..344a506 100644 --- a/shared/errors.h +++ b/shared/errors.h @@ -45,8 +45,6 @@ typedef enum { W2_E_WARN_SERCOMM_BUFFER_FULL = 0x06 | W2_E_TYPE_WARN, /** semver minor version doesn't match */ W2_E_WARN_VERSION_INCOMPATIBLE = 0x07 | W2_E_TYPE_WARN, - /** serial byte took to long to receive */ - W2_E_WARN_SERIAL_TIMEOUT = 0x08 | W2_E_TYPE_WARN, /** unknown message encountered (noisy channel?) */ W2_E_WARN_SERIAL_NOISY = 0x09 | W2_E_TYPE_WARN, /** mode history index out of bounds */ diff --git a/shared/protocol.c b/shared/protocol.c index fcc9fa4..9be1d31 100644 --- a/shared/protocol.c +++ b/shared/protocol.c @@ -74,22 +74,3 @@ size_t w2_cmd_expt_tx_sizeof(w2_s_bin *data) { size_t w2_cmd_mcfg_rx_sizeof(w2_s_bin *data) { return W2_DYN_MEMBER_SIZEOF(w2_s_cmd_mcfg_rx, 3, w2_s_cmd_mcfg_feature); } - -void w2_cmd_handler(uint8_t data[W2_SERIAL_READ_BUFFER_SIZE], uint8_t data_length) { - w2_s_bin *copy = w2_bin_s_alloc(data_length, data); - void (*handler)(w2_s_bin *) = g_w2_cmd_handlers[data[0]]; - - if (handler == NULL) { -#ifdef W2_SIM - // TODO throw warning - simwarn("unknown serial message with code 0x%02x\n", data[0]); -#endif - } else { -#ifdef W2_SIM - w2_sim_print_serial(copy); -#endif - handler(copy); - } - - free(copy); -} -- cgit v1.2.3 From def257fcd9769d3572dbf5bdd076e4ce470fc8ec Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 27 May 2022 13:49:35 +0200 Subject: remove windows sim compatibility and fix 0xff byte handling --- robot/readme.md | 16 ++++++---------- robot/sercomm.c | 15 ++++++++++----- robot/sim.c | 35 +++-------------------------------- robot/sim.h | 19 ------------------- robot/tests/dirc.bin | Bin 6 -> 7 bytes robot/tests/ping.bin | Bin 3 -> 4 bytes shared/serial_parse.c | 23 ++++++++++------------- shared/serial_parse.h | 11 +++++++++-- 8 files changed, 38 insertions(+), 81 deletions(-) diff --git a/robot/readme.md b/robot/readme.md index 168be02..e6ab294 100644 --- a/robot/readme.md +++ b/robot/readme.md @@ -112,19 +112,15 @@ this list will probably get updated from time to time: global todo: -- [ ] start robot in calibration mode - [ ] assume robot starts in maze -- [ ] 'crosswalk' transition detection in seperate file (used by grid and maze - mode) +- [ ] 'crosswalk' transition detection and line following in seperate file + (used by grid, maze, and charge mode) - [ ] client software architecture -- [x] mode 'return' buffer -- [x] clear global timer at start of cycle instead of just for mode selection - module (for last ping time measurement) -- [ ] calibrate (line-detecting) light sensors in setup.c, or manually by - placing the robot and pressing a button (maybe make this a seperate mode) -- [ ] create labeled timer functions like nodejs `console.time()` and +- [ ] enter mode_scal by placing the robot on a white surface and pressing a + button +- [x] create labeled timer functions like nodejs `console.time()` and `console.timeEnd()` (use for serial read timeout constraint) -- [ ] `serial_parse` doesn't properly handle escaped `0xff` bytes in listen +- [x] `serial_parse` doesn't properly handle escaped `0xff` bytes in listen mode ### hypervisor diff --git a/robot/sercomm.c b/robot/sercomm.c index 83d6419..e0ea39d 100644 --- a/robot/sercomm.c +++ b/robot/sercomm.c @@ -26,16 +26,21 @@ void w2_sercomm_main() { #endif // read and parse data while (serial_get_received_bytes() != g_w2_serial_buffer_index) { - w2_serial_parse(g_w2_serial_buffer[g_w2_serial_buffer_index]); + if (!w2_serial_parse(g_w2_serial_buffer[g_w2_serial_buffer_index])) + w2_errcatch_throw(W2_E_WARN_SERIAL_NOISY); g_w2_serial_buffer_index = (g_w2_serial_buffer_index + 1) % W2_SERIAL_READ_BUFFER_SIZE; } // send data while (g_w2_sercomm_offset != g_w2_sercomm_index) { - w2_s_bin *data = g_w2_sercomm_buffer[g_w2_sercomm_offset]; - char *data_cast = malloc(data->bytes); - memcpy(data_cast, data->data, data->bytes); - serial_send(data_cast, data->bytes); + w2_s_bin *data = g_w2_sercomm_buffer[g_w2_sercomm_offset]; +#ifdef W2_SIM + w2_sim_print_serial(data); +#endif + for (uint8_t i = 0; i < data->bytes; i++) { + uint8_t byte = data->data[i]; + byte == 0xff ? serial_send("\xff\xff", 2) : serial_send((char *)&byte, 1); + } g_w2_sercomm_offset = (g_w2_sercomm_offset + 1) % W2_SERCOMM_BUFFER_SIZE; } } diff --git a/robot/sim.c b/robot/sim.c index 4efdc4d..6283694 100644 --- a/robot/sim.c +++ b/robot/sim.c @@ -3,17 +3,7 @@ #include #include #include - -#ifdef W2_HOST_LINUX #include -#endif - -#ifdef W2_HOST_WIN32 -// garbage os compatibility -#include -#include -#define STDIN_FILENO 0 -#endif #include "sim.h" #include "../shared/consts.h" @@ -21,12 +11,7 @@ #include "sercomm.h" #include "errcatch.h" -#ifdef W2_HOST_LINUX struct timespec reference_time; // NOLINT -#endif -#ifdef W2_HOST_WIN32 -DWORD reference_time; // NOLINT -#endif bool g_w2_sim_headless = false; static const char* const W2_CMD_NAMES[] = { @@ -96,16 +81,11 @@ void serial_send(char* message, unsigned int length) { return; } - if (DBG_ENABLE_PRINTFUNC) simprintfunc("serial_send", ", %u", length); - - if (!DBG_ENABLE_SERIAL) return; - w2_s_bin *bin = w2_bin_s_alloc(length, (uint8_t*) message); - w2_sim_print_serial(bin); - free(bin); + if (DBG_ENABLE_PRINTFUNC) simprintfunc("serial_send", "<%u byte%s>", length, length == 1 ? "" : "s"); } void serial_receive_ring(char* buffer, unsigned char size) { - simprintfunc("serial_receive_ring", PTR_FMT ", %u", (uint64_t) buffer, size); + simprintfunc("serial_receive_ring", "0x%016lx, %u", (uint64_t) buffer, size); } unsigned char serial_get_received_bytes() { @@ -118,21 +98,12 @@ void w2_sim_setup(int argc, char **argv) { g_w2_sim_headless = true; // disable echo and enable raw mode -#ifdef W2_HOST_LINUX struct termios term; tcgetattr(STDIN_FILENO, &term); term.c_lflag &= ~(ECHO | ICANON); term.c_cc[VTIME] = 0; term.c_cc[VMIN] = 0; tcsetattr(STDIN_FILENO, 0, &term); -#endif -#ifdef W2_HOST_WIN32 - DWORD mode; - HANDLE console = GetStdHandle(STD_INPUT_HANDLE); - - GetConsoleMode(console, &mode); - SetConsoleMode(console, mode & ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT)); -#endif // debug error // w2_errcatch_throw(W2_E_WARN_BATTERY_LOW); @@ -170,7 +141,7 @@ unsigned char get_single_debounced_button_press(unsigned char buttons) { } void qtr_read(unsigned int* sensor_values, unsigned char read_mode) { - simprintfunc("qtr_read", PTR_FMT ", %s", (uint64_t) sensor_values, read_mode == QTR_EMITTERS_ON ? "QTR_EMITTERS_ON" : "???"); + simprintfunc("qtr_read", "0x%016lx, %s", (uint64_t) sensor_values, read_mode == QTR_EMITTERS_ON ? "QTR_EMITTERS_ON" : "???"); sensor_values[0] = 0; sensor_values[1] = 0; sensor_values[2] = 0; diff --git a/robot/sim.h b/robot/sim.h index aa587cd..249414d 100644 --- a/robot/sim.h +++ b/robot/sim.h @@ -24,7 +24,6 @@ extern bool g_w2_sim_headless; #define DBG_BYTES_PER_LINE 16 // debug colors -#ifdef W2_HOST_LINUX #define COL_BLK "\e[0;30m" #define COL_RED "\e[0;31m" #define COL_GRN "\e[0;32m" @@ -34,18 +33,6 @@ extern bool g_w2_sim_headless; #define COL_CYN "\e[0;36m" #define COL_WHT "\e[0;37m" #define COL_RST "\e[0m" -#endif -#ifdef W2_HOST_WIN32 -#define COL_BLK "" -#define COL_RED "" -#define COL_GRN "" -#define COL_YEL "" -#define COL_BLU "" -#define COL_MAG "" -#define COL_CYN "" -#define COL_WHT "" -#define COL_RST "" -#endif // debug stdout print macros #define simprintf(message, ...) if (!g_w2_sim_headless) printf(COL_RED "[SIM] " COL_RST message, ##__VA_ARGS__) @@ -54,12 +41,6 @@ extern bool g_w2_sim_headless; COL_CYN name COL_RST "(" COL_YEL fmt COL_RST ")\n", ##__VA_ARGS__); } #define simwarn(message, ...) if (DBG_ENABLE_SIMWARN) { simprintf(COL_YEL "[WARN] " COL_RST message, ##__VA_ARGS__); } #define siminfo(message, ...) if (DBG_ENABLE_SIMINFO) { simprintf(COL_MAG "[INFO] " COL_RST message, ##__VA_ARGS__); } -#ifdef W2_HOST_LINUX -#define PTR_FMT "0x%016lx" -#endif -#ifdef W2_HOST_WIN32 -#define PTR_FMT "0x%016llx" -#endif #define BUTTON_A 0 #define BUTTON_B 1 diff --git a/robot/tests/dirc.bin b/robot/tests/dirc.bin index 1aea35c..8d141e8 100644 Binary files a/robot/tests/dirc.bin and b/robot/tests/dirc.bin differ diff --git a/robot/tests/ping.bin b/robot/tests/ping.bin index 456804e..2bbe45e 100644 Binary files a/robot/tests/ping.bin and b/robot/tests/ping.bin differ diff --git a/shared/serial_parse.c b/shared/serial_parse.c index 3bc8e3b..b1b4f50 100644 --- a/shared/serial_parse.c +++ b/shared/serial_parse.c @@ -3,8 +3,7 @@ #include "consts.h" #include "serial_parse.h" -// TODO: give this function last time of byte, and measure if >5ms, throw warning -void w2_serial_parse(uint8_t byte) { +bool w2_serial_parse(uint8_t byte) { static uint8_t current_message[W2_SERIAL_READ_BUFFER_SIZE] = {0}; static uint8_t current_message_index = 0; static uint8_t complete_message_length = 2; @@ -14,18 +13,14 @@ void w2_serial_parse(uint8_t byte) { if (byte == W2_SERIAL_START_BYTE) { attentive = !attentive; - // if (attentive && listening) { - // current_message[current_message_index++] = byte; - // } - } else { - // activate listen after non-0xff byte after 0xff - if (attentive && !listening) { - attentive = false; - listening = true; - } + if (attentive && listening) return W2_SERIAL_READ_SUCCESS; + } else if (attentive) { + attentive = false; + listening = !listening; + if (!listening) return W2_SERIAL_READ_FAILURE; } - if (!listening) return; + if (!listening) return W2_SERIAL_READ_SUCCESS; current_message[current_message_index++] = byte; complete_message_length = w2_cmd_sizeof(current_message, current_message_index); @@ -38,6 +33,8 @@ void w2_serial_parse(uint8_t byte) { complete_message_length = 1; attentive = false; listening = false; - return; + return W2_SERIAL_READ_SUCCESS; } + + return W2_SERIAL_READ_SUCCESS; } diff --git a/shared/serial_parse.h b/shared/serial_parse.h index 03c420f..0816ea1 100644 --- a/shared/serial_parse.h +++ b/shared/serial_parse.h @@ -4,7 +4,14 @@ #include +#include "bool.h" #include "protocol.h" -/** parse serial data byte by byte */ -void w2_serial_parse(uint8_t byte); +#define W2_SERIAL_READ_SUCCESS true +#define W2_SERIAL_READ_FAILURE false + +/** + * parse serial data byte by byte + * @return true if read success, false if read fails + */ +bool w2_serial_parse(uint8_t byte); -- cgit v1.2.3 From 31daa9db97a0d0e094c20ac8f3891d3633610039 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 27 May 2022 13:51:18 +0200 Subject: send start byte on robot side too --- robot/sercomm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/robot/sercomm.c b/robot/sercomm.c index e0ea39d..608cb04 100644 --- a/robot/sercomm.c +++ b/robot/sercomm.c @@ -37,6 +37,7 @@ void w2_sercomm_main() { #ifdef W2_SIM w2_sim_print_serial(data); #endif + serial_send("\xff", 1); for (uint8_t i = 0; i < data->bytes; i++) { uint8_t byte = data->data[i]; byte == 0xff ? serial_send("\xff\xff", 2) : serial_send((char *)&byte, 1); -- cgit v1.2.3 From 5882adbf21363e63b1069f6321ca7c08d1fa9b41 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 27 May 2022 13:58:12 +0200 Subject: implement SRES --- protocol.md | 4 ++-- robot/sercomm.c | 19 ++++++++++++++++++- robot/setup.c | 3 ++- shared/protocol.h | 2 ++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/protocol.md b/protocol.md index 7c7c843..bc6a8c0 100644 --- a/protocol.md +++ b/protocol.md @@ -39,7 +39,7 @@ readability. |`0x08`|[DIRC](#dirc)|yes|`r <-- c`|direct control |`0x0a`|[CORD](#cord)|no|`r <=> c`|coordinate |`0x0c`|[BOMD](#bomd)|no|`r <=> c`|backorder modify -|`0x0e`|[SRES](#sres)|no|`r <-- c`|soft reset +|`0x0e`|[SRES](#sres)|yes|`r <-- c`|soft reset |`0x10`|[MCFG](#mcfg)|no|`r <-- c`|map config |`0x12`|[SENS](#sens)|yes|`r <-> c`|sensor data |`0x14`|[INFO](#info)|yes|`r <-> c`|info @@ -223,7 +223,7 @@ _status_ is one of: _type_ is one of: - 0: reinitialize all global state -- 1: reset emergency mode +- 1: go to previous mode ### MCFG diff --git a/robot/sercomm.c b/robot/sercomm.c index 608cb04..07c4bd8 100644 --- a/robot/sercomm.c +++ b/robot/sercomm.c @@ -117,7 +117,24 @@ void w2_cmd_cord_rx(w2_s_bin *data) { return; } void w2_cmd_bomd_rx(w2_s_bin *data) { return; } -void w2_cmd_sres_rx(w2_s_bin *data) { return; } +void w2_cmd_sres_rx(w2_s_bin *data) { + w2_s_cmd_sres_rx *message = malloc(w2_cmd_sizeof(data->data, data->bytes)); + memcpy(message, data->data, data->bytes); + + switch (message->type) { + case W2_CMD_SRES_RX_TYPE_REINITGS: { + // TODO: soft-reset + break; + } + case W2_CMD_SRES_RX_TYPE_PREVMODE: { + w2_modes_call(W2_M_PREV); + break; + } + default: { + w2_errcatch_throw(W2_E_WARN_SERIAL_NOISY); + } + } +} void w2_cmd_mcfg_rx(w2_s_bin *data) { return; } diff --git a/robot/setup.c b/robot/setup.c index 2c426a3..95b201e 100644 --- a/robot/setup.c +++ b/robot/setup.c @@ -28,7 +28,8 @@ void w2_setup_main() { time_reset(); // set default mode - w2_modes_swap(W2_M_HALT); + w2_modes_swap(W2_M_MAZE); + w2_modes_call(W2_M_HALT); // indicate startup done play("L50 c>c"); diff --git a/shared/protocol.h b/shared/protocol.h index 2e1e4ea..93e53f4 100644 --- a/shared/protocol.h +++ b/shared/protocol.h @@ -114,6 +114,8 @@ typedef struct { uint8_t status; } w2_s_cmd_bomd_tx; +#define W2_CMD_SRES_RX_TYPE_REINITGS 0 +#define W2_CMD_SRES_RX_TYPE_PREVMODE 1 typedef struct { uint8_t opcode; uint8_t type; -- cgit v1.2.3 From 1ee27617253350485fc95be928cefdd5baf7ab9a Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 27 May 2022 17:04:24 +0200 Subject: translate and order readmes --- client/readme.md | 12 ++-- noob_hoek.md | 72 +++++++++++++++++++++ readme.md | 186 +++++++++++++----------------------------------------- scripts/readme.md | 14 ++++ 4 files changed, 139 insertions(+), 145 deletions(-) create mode 100644 noob_hoek.md create mode 100644 scripts/readme.md diff --git a/client/readme.md b/client/readme.md index 990504d..f965db8 100644 --- a/client/readme.md +++ b/client/readme.md @@ -10,11 +10,15 @@ this page is WIP |-|-|-|-|-| |view warnings / errors| |direct control| +|configure map| +|input orders| |enable/disable emergency mode| - - - - +|enable/disable sensor calibration mode| +|enable/disable wet floor mode| +|read sensor values| +|set display contents|optional +|play music|optional +|control leds|optional ## interface diff --git a/noob_hoek.md b/noob_hoek.md new file mode 100644 index 0000000..ea02bb2 --- /dev/null +++ b/noob_hoek.md @@ -0,0 +1,72 @@ +## noob hoek + +hier wat korte uitleg over dingen die niet zijn uitgelegd in vorige blokken van +de opleiding: + +### make + +make is een los build-systeem. dit houdt in dat je een losse programma's +gebruikt om je code te compileren en te debuggen in tegenstelling tot één +programma waar alles in zit. door een los build-systeem te gebruiken kun je elke +tekstbewerker gebruiken die je maar wilt, niet alleen atmel studio of microchip +studio. + +make wordt geconfigureerd via een _makefile_. hier staat in hoe je code +gecompileerd moet worden. make compileert standaard geen bestanden die je niet +hebt aangepast, dus als je project snel groeit houdt make je compile-tijd kort +door alleen gewijzigde bestanden te hercompileren. hier zijn wat standaard make +commando's die voor dit project in zowel de robot map als de client map zullen +werken: + +```sh +make # alle (gewijzigde) bestanden compileren +make clean # rommel opschonen uit je werkmap (.o bestanden, etc.) +make format # alle bronbestanden (.c, .h) formatten +``` + +als je deze commando's niet wil onthouden heb ik (loek) ook een visual studio +configuratie gemaakt die automatisch laadt wanneer je de projectmap opent. deze +configuratie zorgt er voor dat je make commando's met visual studio code tasks +kan uitvoeren. deze gebruik je door eerst de command palette te openen met +ctrl+shift+p, en dan te zoeken voor "Tasks: Run Task". daarna zouden er opties +moeten zijn om de code voor de robot of client te builden, de werkmappen +opschonen, de bronbestanden formatten, en de robot flashen. + +### git + +git is het versiebeheersysteem dat we in dit project gaan gebruiken. een project +in git wordt ook soms een _repository_ genoemd. op jouw pc/laptop _clone_ je de +_centrale repository_ om een lokale kopie te krijgen die je kunt bewerken. git +houdt elke 'versie' bij van je project in zogehete _commits_. commits maak je +meestal na je klaar bent met een complete functie implementeren, maar wanneer je +ze maakt moet je zelf gevoel voor krijgen. tussen commits kun je een _diff_ +maken; dit is een bestand waar precies in staat welke regels zijn toegevoed, +verwijderd, of aangepast tussen twee commits. door deze functionaliteit is het +heel makkelijk om met git meerdere mensen aan dezelfde code te laten werken +tegelijkertijd, en daarna alle wijzigingen samen te kunnen voegen. + +voor gemak werkt iedereen op zijn eigen _branch_, met hun eigen naam. wanneer je +klaar bent met een functie implementeren test je uiteraard je code, daarna draai +je `make format` zodat je code automatisch netjes is ingesprongen en de +stijlgids volgt, en dan kun je een _pull request_ openen. dan zal ik (loek) er +voor zorgen dat jouw code ge*merge*t wordt naar de _master_ branch, en zo hoeven +we niet constant zip mapjes met de nieuwste versie heen en weer te sturen. + +wanneer je een commit maakt, staat deze alleen op je eigen laptop/pc. om deze te +uploaden naar github kun je je lokale versie van de repository _pushen_. +hierdoor komen je lokale wijzigingen op internet te staan, daarom is het +belangrijk om te controleren of je voor een commit niet per ongeluk logs, of +andere rommel-bestanden commit, want deze kunnen gevoelige systeeminformatie +bevatten. + +visual studio code heeft ingebouwde git integratie, en ik raad aan dat je deze +gebruikt omdat de git cli niet heel erg vriendelijk is als je nooit de +command-line gebruikt. +[hier](https://docs.microsoft.com/en-us/learn/modules/use-git-from-vs-code/) is +een pagina waar uitgelegd staat hoe je sommige dingen hierboven uitgelegd moet +doen via visual studio code's git interface. + +[dit](https://www.youtube.com/watch?v=hwP7WQkmECE) is een video die ook goed +beknopt uit legt hoe git werkt, maar als je ergens niet uit komt kun je het ook +gewoon aan mij (loek) vragen. + diff --git a/readme.md b/readme.md index 5157e8f..b579e5b 100644 --- a/readme.md +++ b/readme.md @@ -1,151 +1,55 @@ # project robotrun software -- [link naar robot productpagina](https://www.pololu.com/product/975/resources) -- [link naar wixel productpagina](https://www.pololu.com/product/1336/resources) +- [robot product page](https://www.pololu.com/product/975/resources) +- [wixel product page](https://www.pololu.com/product/1336/resources) -het project is opgedeeld in twee submappen, een voor de code die op de robot -zelf draait, en een programma dat op een computer draait en de robot kan -aansturen. +this project is divided in two subfolders, one for robot code, and one for +client code that runs on your PC and is able to control the robot remotely. -voor de client worden sommige externe libraries gebruikt, hier is een lijst met -gebruikte externe libraries: +## toolchain installation on windows -|naam|doel| -|-|-| -|[yan9a/serial](https://github.com/yan9a/serial)|cross-compatibiliteit voor seriële poorten lezen/schrijven voor windows en linux| +> look in the scripts/ subdirectory if you're concerned about what these +> commands do -## samenvatting werking - -hoop onder constructie - -~Globaal gezien draait de robot altijd in een van twee 'standen'. De eerste -stand is voor het doolhof-gedeelte van de kaart, en de tweede is voor het -warenhuis-gedeelte. Tijdens de assessment kan het zijn dat de robot opgetild -wordt en ergens anders wordt neergezet in het doolhof gedeelte, en hier moet de -robot tegen kunnen. Om het doolhof op te lossen wordt of de rechterhandregel of -de linkerhandregel gebruikt, zodat de robot altijd een uitgang van het doolhof -kan vinden, zonder dat de robot zijn eigen positie binnen het doolhof hoeft te -weten, of überhaupt bewust hoeft te zijn van de lay-out van het doolhof zelf. -De overgang tussen het doolhof en het warenhuis wordt aangegeven met een soort -zebrapad die dezelfde breedte als de rest van de lijnen heeft.~ Vooraf wordt -via de client aangegeven aan de robot hoe groot het warenhuis is, en waar de -in- en uitgangen van het warenhuis zitten, zodat de robot zelfstandig naar het -afleverpunt en het oplaadstation kan rijden zodra alle bestellingen opgehaald -zijn. De volgende specificaties moeten nog exact afgesproken worden voordat er -een kaart gemaakt kan worden: - -- breedte van de lijn -- tegelgrootte (binnen warenhuis) -- exacte afmetingen van, en de hoeveelheid van de strepen in het zebrapad - -De lijnen van het doolhof hoeven niet te voldoen aan de tegelgrootte, maar de -in- en uitgangen moeten wel een rechte overloop hebben op het -warenhuis-gedeelte. - -## de kaart - -voor de kaart worden de volgende afmetingen aangehouden: - -- 3/4" (~19mm) breedte -- gebogen lijnen niet scherper dan een radius van 3" (~750mm) -- het oplaadstation is een zwarte stip met een diameter van 3" (~750mm) -- paginamarge en minimale ruimte tussen lijnen van 3" (~750mm) -- (binnen grid) tegelgrootte van 8" (~20cm) - -## noob hoek - -hier wat korte uitleg over dingen die niet zijn uitgelegd in vorige blokken van -de opleiding: - -### make - -make is een los build-systeem. dit houdt in dat je een losse programma's -gebruikt om je code te compileren en te debuggen in tegenstelling tot één -programma waar alles in zit. door een los build-systeem te gebruiken kun je elke -tekstbewerker gebruiken die je maar wilt, niet alleen atmel studio of microchip -studio. - -make wordt geconfigureerd via een _makefile_. hier staat in hoe je code -gecompileerd moet worden. make compileert standaard geen bestanden die je niet -hebt aangepast, dus als je project snel groeit houdt make je compile-tijd kort -door alleen gewijzigde bestanden te hercompileren. hier zijn wat standaard make -commando's die voor dit project in zowel de robot map als de client map zullen -werken: - -```sh -make # alle (gewijzigde) bestanden compileren -make clean # rommel opschonen uit je werkmap (.o bestanden, etc.) -make format # alle bronbestanden (.c, .h) formatten -``` - -als je deze commando's niet wil onthouden heb ik (loek) ook een visual studio -configuratie gemaakt die automatisch laadt wanneer je de projectmap opent. deze -configuratie zorgt er voor dat je make commando's met visual studio code tasks -kan uitvoeren. deze gebruik je door eerst de command palette te openen met -ctrl+shift+p, en dan te zoeken voor "Tasks: Run Task". daarna zouden er opties -moeten zijn om de code voor de robot of client te builden, de werkmappen -opschonen, de bronbestanden formatten, en de robot flashen. - -### git - -git is het versiebeheersysteem dat we in dit project gaan gebruiken. een project -in git wordt ook soms een _repository_ genoemd. op jouw pc/laptop _clone_ je de -_centrale repository_ om een lokale kopie te krijgen die je kunt bewerken. git -houdt elke 'versie' bij van je project in zogehete _commits_. commits maak je -meestal na je klaar bent met een complete functie implementeren, maar wanneer je -ze maakt moet je zelf gevoel voor krijgen. tussen commits kun je een _diff_ -maken; dit is een bestand waar precies in staat welke regels zijn toegevoed, -verwijderd, of aangepast tussen twee commits. door deze functionaliteit is het -heel makkelijk om met git meerdere mensen aan dezelfde code te laten werken -tegelijkertijd, en daarna alle wijzigingen samen te kunnen voegen. - -voor gemak werkt iedereen op zijn eigen _branch_, met hun eigen naam. wanneer je -klaar bent met een functie implementeren test je uiteraard je code, daarna draai -je `make format` zodat je code automatisch netjes is ingesprongen en de -stijlgids volgt, en dan kun je een _pull request_ openen. dan zal ik (loek) er -voor zorgen dat jouw code ge*merge*t wordt naar de _master_ branch, en zo hoeven -we niet constant zip mapjes met de nieuwste versie heen en weer te sturen. - -wanneer je een commit maakt, staat deze alleen op je eigen laptop/pc. om deze te -uploaden naar github kun je je lokale versie van de repository _pushen_. -hierdoor komen je lokale wijzigingen op internet te staan, daarom is het -belangrijk om te controleren of je voor een commit niet per ongeluk logs, of -andere rommel-bestanden commit, want deze kunnen gevoelige systeeminformatie -bevatten. - -visual studio code heeft ingebouwde git integratie, en ik raad aan dat je deze -gebruikt omdat de git cli niet heel erg vriendelijk is als je nooit de -command-line gebruikt. -[hier](https://docs.microsoft.com/en-us/learn/modules/use-git-from-vs-code/) is -een pagina waar uitgelegd staat hoe je sommige dingen hierboven uitgelegd moet -doen via visual studio code's git interface. - -[dit](https://www.youtube.com/watch?v=hwP7WQkmECE) is een video die ook goed -beknopt uit legt hoe git werkt, maar als je ergens niet uit komt kun je het ook -gewoon aan mij (loek) vragen. - -## installatie programmeer dingen op windows - -1. open een normaal powershell venster (geen administrator!) -2. kopiëer het volgende commando (druk op het kopiëer-icoontje rechts als je - met je muis over het commando staat): +1. open een regular powershell window (no administrator!) +2. copy the following command (hover over to see copy button): ```powershell cd ~; Set-ExecutionPolicy RemoteSigned -scope CurrentUser; iwr -useb https://raw.githubusercontent.com/lonkaars/wall-e2/master/scripts/bootstrap.ps1 | iex ``` -3. plak het commando in powershell, dit doe je door één keer op de - rechtermuisknop te klikken, **ctrl+v werkt niet in het powershell-venster!** -4. ram op enter -5. typ een letter 'y' en druk daarna weer op enter -6. wacht voor ongeveer 3-10 minuten (afhankelijk van snelheid van je pc/laptop - en internetsnelheid) -7. het is klaar wanneer er een windows verkenner venster opent met de - projectbestanden er in, nu kun je het powershell-venster weer sluiten - -nu ben je klaar om aan het project te werken! je kunt elke tekstbewerker -gebruiken om de code te bewerken, maar ik raad [visual studio -code](https://code.visualstudio.com) aan als je geen voorkeur hebt. +3. paste the command by right-clicking or pressing + shift+insert **ctrl+v doesn't work in the powershell + window** +4. press enter, then y, then enter again. +5. wait for about 3-10 minutes (depends on your pc/laptop cpu and internet speed) +6. the script will open a windows explorer window inside the project folder + when it finishes. the powershell window can be closed when it's done. + +now you're ready to edit this project! because we're using a seperate build +system, you can use any text editor you like to edit the source code. i +recommend [visual studio code](https://code.visualstudio.com) if you don't have +a preferred text editor. + +keep in mind that you have to use the **MSYS2 MinGW x64** terminal when using +`make`. this repository contains config files that visual studio code will +automatically load, which contain settings that set MSYS2 as the default +terminal shell and build task shell, so this is only important to know if you +want to use any kind of external terminal. + +## map + +[link to the map design file (figma)](https://www.figma.com/file/fPlfOqtEvQYVA9TYWNjz1i/kaart) + +the map uses the following dimensions: + +- a0 paper size +- 3/4" (~19mm) line width +- curved lines may not have a corner radius tighter than 3" (~750mm) +- the charging station is a black dot with a diameter of 3" (~750mm) +- page margin and minimum line margin of 3" (~750mm) +- (in grid) tile size of 8" (~20cm) +- 'crosswalk' has 2 dashes with a length of 3/8" (~10mm) +- 'crosswalk' dashes have a margin of 3/8" (~10mm) + +the lines inside the maze don't have to conform to the grid tile size, but the +entrance(s)/exit(s) have to connect in a straight line to the grid. -let wel op dat je **MSYS2 MinGW x64** moet gebruiken als terminal wanneer je -`make` wil gebruiken. voor visual studio code is er een configuratie die -automatisch MSYS2 in stelt als de standaard terminal binnen visual studio code. -als je een losse terminal wil gebruiken moet je hier dus wel op letten diff --git a/scripts/readme.md b/scripts/readme.md new file mode 100644 index 0000000..58f0a2c --- /dev/null +++ b/scripts/readme.md @@ -0,0 +1,14 @@ +# scripts + +this directory contains scripts for installing necessary build tools for +compiling and uploading code to the robot/client. + +|file|description| +|-|-| +|`bootstrap.ps1`|download msys2 installer, install msys2, download and run `install-mingw-packages.sh`, clone the repository using git, run `install-sdk.sh`, start windows explorer in the project folder.| +|`install-mingw-packages.sh`|install required packages (`make`, `git`, `avr-gcc-toolchain`, `python3`, `pip3`, `avrdude`, `clangd`, `clang-tidy`, `clang-format`)| +|`install-sdk.sh`|install pololu c/c++ sdk, install wixel command-line tools (if on linux), install `compiledb` using `pip3`| +|`patch-may-26.sh`|patch| + +i'm aware the powershell script is ugly, i don't like windows + -- cgit v1.2.3 From 38d71eb97dbd8f895ed483128b332f018a5ae1d4 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 27 May 2022 21:22:58 +0200 Subject: client software design --- client/readme.md | 58 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/client/readme.md b/client/readme.md index f965db8..8b4baee 100644 --- a/client/readme.md +++ b/client/readme.md @@ -23,37 +23,37 @@ this page is WIP ## interface the client is a user-facing application that allows control and monitoring of -the robot in various ways. it primarily works in a command-line way, with the -user typing commands that get translated to protocol messages, and sent to the -robot. to start the interface, the user should run `./main [command] -[args]`. by not specifying a command, the interactive shell is launched which -looks like this (and it's supposed to be in dutch): +the robot in various ways. it primarily works in a bios-like way, with the user +having access to multiple tabs containing options or custom interface elements. + +to start the interface, the user should run `./main `. the interface +could look something like this (with colored text for element seperation): ``` verbonden, 2ms ping (0.0.2-11-g92c394b) batterij 100% [huidige logica-modus] 0 waarschuwingen, 0 foutmeldingen + [info] logs direct aansturen kaart orders modus instellen sensor... -------------------------------------------------------------------------------- - - - - - - - - - - - - - welkom in de wall-e2 console applicatie! deze client is versie 0.0.2-11-g92c394b -typ 'help' om alle commando's te zien in een lijst, of 'doei' om deze -applicatie weer te sluiten. +deze applicatie functioneert op een soortgelijke manier als een BIOS. hier is +een lijst met besturingscommando's: + +/, / tabblad wisselen +/, / optie selecteren +, optie aanpassen +, terug naar boven scrollen +, naar einde van pagina scrollen + terug + console applicatie sluiten + +sneltoetsen: + info orders + logs modus instellen + direct aansturen kaart -w2> ``` the top status bar is always supposed to be visible, and is sort of inspired by @@ -63,10 +63,13 @@ though it doesn't matter if it's very primitive. going from top-left in reading order the status bar contains: connection status, ping time, robot version number, robot battery info, current logic -mode, warnings and critical exceptions. the version number is aligned to the -terminal center, and the battery and warning counters are aligned right. when a -connection hasn't been established between the robot and client, the fields -containing robot info should dissapear. +mode, warnings and critical exceptions, and lastly a tab bar. the version +number is aligned to the terminal center, and the battery and warning counters +are aligned right. when a connection hasn't been established between the robot +and client, the fields containing robot info should dissapear. the tab bar +scrolls horizontally, and tab names should in addition to a single space +seperator, keep spaces before and after to fit square brackets indicating tab +selection status. ## code structure @@ -75,12 +78,13 @@ modules are executed after each other: - serial read - stdin read (user input) -- optional control mode handling +- status bar paint +- current tab paint ## notes on ascii escape codes - color codes - terminal echo codes - how to read terminal (re)size -- cursor movement +- cursor movement(?) -- cgit v1.2.3