summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.clang-format4
-rw-r--r--robot/calibration.c1
-rw-r--r--robot/calibration.h9
-rw-r--r--robot/consts.h33
-rw-r--r--robot/errcatch.c3
-rw-r--r--robot/errcatch.h4
-rw-r--r--robot/grid.c1
-rw-r--r--robot/grid.h8
-rw-r--r--robot/halt.c1
-rw-r--r--robot/halt.h8
-rw-r--r--robot/hypervisor.c16
-rw-r--r--robot/hypervisor.h8
-rw-r--r--robot/io.c3
-rw-r--r--robot/io.h4
-rw-r--r--robot/main.c34
-rw-r--r--robot/main.h4
-rw-r--r--robot/makefile2
-rw-r--r--robot/maze.c1
-rw-r--r--robot/maze.h8
-rw-r--r--robot/modes.c3
-rw-r--r--robot/modes.h10
-rw-r--r--robot/readme.md10
-rw-r--r--robot/sercomm.c3
-rw-r--r--robot/sercomm.h9
-rw-r--r--robot/setup.c11
-rw-r--r--robot/setup.h12
26 files changed, 175 insertions, 35 deletions
diff --git a/.clang-format b/.clang-format
index c7d6b0a..77e33d7 100644
--- a/.clang-format
+++ b/.clang-format
@@ -1,14 +1,16 @@
---
AccessModifierOffset: 0
+AlignConsecutiveAssignments: true
+AllowShortLoopsOnASingleLine: true
BasedOnStyle: LLVM
BreakBeforeBraces: Attach
ColumnLimit: 100
+IndentCaseLabels: true
IndentWidth: '4'
Language: Cpp
Standard: Cpp11
TabWidth: '4'
UseTab: Always
-IndentCaseLabels: true
...
# vim: ft=yaml
diff --git a/robot/calibration.c b/robot/calibration.c
new file mode 100644
index 0000000..7788532
--- /dev/null
+++ b/robot/calibration.c
@@ -0,0 +1 @@
+#include "calibration.h"
diff --git a/robot/calibration.h b/robot/calibration.h
new file mode 100644
index 0000000..13b80b9
--- /dev/null
+++ b/robot/calibration.h
@@ -0,0 +1,9 @@
+#pragma once
+
+/**
+ * calibration mode
+ *
+ * turns robot on its own axis 360 degress, and aligns the front sensors with
+ * the line if found, else triggers halt mode (emergency)
+ */
+void w2_mode_calb_main();
diff --git a/robot/consts.h b/robot/consts.h
new file mode 100644
index 0000000..6530528
--- /dev/null
+++ b/robot/consts.h
@@ -0,0 +1,33 @@
+#pragma once
+
+#ifndef BUILD_STR
+// should be defined with -DBUILD_STR in makefile
+#define BUILD_STR ("????????")
+#endif
+
+#define W2_MAX_MODULE_CYCLE_MS (20)
+#define W2_SERIAL_BAUD (9600)
+
+#define W2_ERR_TYPE_CRIT (0b00 << 6)
+#define W2_ERR_TYPE_WARN (0b01 << 6)
+#define W2_ERR_TYPE_INFO (0b10 << 6)
+#define W2_ERR_TYPE_VERB (0b11 << 6)
+
+/**
+ * enum storing all error codes
+ *
+ * error codes are between 0-63 because the two most significant bits are
+ * reserved for error type checking
+ */
+enum w2_e_errorcodes {
+ // critical error codes
+ W2_ERR_CONN_LOST = 0x00 | W2_ERR_TYPE_CRIT,
+ W2_ERR_COM_UNAVAILABLE = 0x01 | W2_ERR_TYPE_CRIT, // client-only
+ W2_ERR_LINE_LOST = 0x02 | W2_ERR_TYPE_CRIT,
+ W2_ERR_OBSTACLE_STUCK = 0x03 | W2_ERR_TYPE_CRIT,
+
+ // warnings
+ W2_ERR_BATTERY_LOW = 0x00 | W2_ERR_TYPE_WARN,
+ W2_ERR_OBSTACLE_DETECTED = 0x01 | W2_ERR_TYPE_WARN,
+ W2_ERR_CYCLE_EXPIRED = 0x02 | W2_ERR_TYPE_WARN,
+};
diff --git a/robot/errcatch.c b/robot/errcatch.c
new file mode 100644
index 0000000..5d2b33f
--- /dev/null
+++ b/robot/errcatch.c
@@ -0,0 +1,3 @@
+#include "errcatch.h"
+
+void w2_errcatch_main() {}
diff --git a/robot/errcatch.h b/robot/errcatch.h
new file mode 100644
index 0000000..c816051
--- /dev/null
+++ b/robot/errcatch.h
@@ -0,0 +1,4 @@
+#pragma once
+
+/** error-handler module main */
+void w2_errcatch_main();
diff --git a/robot/grid.c b/robot/grid.c
new file mode 100644
index 0000000..0c83272
--- /dev/null
+++ b/robot/grid.c
@@ -0,0 +1 @@
+#include "grid.h"
diff --git a/robot/grid.h b/robot/grid.h
new file mode 100644
index 0000000..3fd54d9
--- /dev/null
+++ b/robot/grid.h
@@ -0,0 +1,8 @@
+#pragma once
+
+/**
+ * warehouse mode
+ *
+ * processes orders from the order buffer
+ */
+void w2_mode_grid_main();
diff --git a/robot/halt.c b/robot/halt.c
new file mode 100644
index 0000000..6bf1cad
--- /dev/null
+++ b/robot/halt.c
@@ -0,0 +1 @@
+#include "halt.h"
diff --git a/robot/halt.h b/robot/halt.h
new file mode 100644
index 0000000..e88bde4
--- /dev/null
+++ b/robot/halt.h
@@ -0,0 +1,8 @@
+#pragma once
+
+/**
+ * halt (emergency) mode
+ *
+ * stops all execution until emergency status is manually cleared by the user
+ */
+void w2_mode_halt_main();
diff --git a/robot/hypervisor.c b/robot/hypervisor.c
new file mode 100644
index 0000000..db0700d
--- /dev/null
+++ b/robot/hypervisor.c
@@ -0,0 +1,16 @@
+#include "hypervisor.h"
+#include "errcatch.h"
+#include "io.h"
+#include "modes.h"
+#include "sercomm.h"
+
+void w2_hypervisor_main() {
+ w2_sercomm_main();
+ w2_errcatch_main();
+ w2_io_main();
+
+ // start timer
+ w2_modes_main();
+ // stop timer
+ // throw error if cycle expired
+}
diff --git a/robot/hypervisor.h b/robot/hypervisor.h
new file mode 100644
index 0000000..0e73259
--- /dev/null
+++ b/robot/hypervisor.h
@@ -0,0 +1,8 @@
+#pragma once
+
+/**
+ * backbone of all other modules
+ *
+ * stores global variables and controls when other modules run
+ */
+void w2_hypervisor_main();
diff --git a/robot/io.c b/robot/io.c
new file mode 100644
index 0000000..4a85458
--- /dev/null
+++ b/robot/io.c
@@ -0,0 +1,3 @@
+#include "io.h"
+
+void w2_io_main() {}
diff --git a/robot/io.h b/robot/io.h
new file mode 100644
index 0000000..14fe0af
--- /dev/null
+++ b/robot/io.h
@@ -0,0 +1,4 @@
+#pragma once
+
+/** i/o module main */
+void w2_io_main();
diff --git a/robot/main.c b/robot/main.c
index 21d0e5c..fbfd38b 100644
--- a/robot/main.c
+++ b/robot/main.c
@@ -1,34 +1,12 @@
-#include <pololu/orangutan.h>
-#include <stdlib.h>
+#include "main.h"
+#include "hypervisor.h"
+#include "setup.h"
int main() {
- play("L50 c>c");
- serial_set_baud_rate(9600);
+ w2_setup_main();
- char *buf = malloc(20);
- unsigned int counter = 0;
-
- while (1) {
- serial_receive_blocking(buf, 1, 65e3);
-
- switch (buf[0]) {
- case 0x7f: {
- counter--;
- lcd_goto_xy(counter, 0);
- print(" ");
- lcd_goto_xy(counter, 0);
- break;
- }
- default: {
- print(&buf[0]);
- counter++;
- if (counter > 20) {
- counter = 0;
- lcd_goto_xy(0, 0);
- }
- }
- }
- }
+ for (;;) w2_hypervisor_main();
+ // satisfy compiler
return 0;
}
diff --git a/robot/main.h b/robot/main.h
new file mode 100644
index 0000000..5b0a1b2
--- /dev/null
+++ b/robot/main.h
@@ -0,0 +1,4 @@
+#pragma once
+
+/** program entrypoint */
+int main();
diff --git a/robot/makefile b/robot/makefile
index d01ad30..e4366d8 100644
--- a/robot/makefile
+++ b/robot/makefile
@@ -8,7 +8,7 @@ AVRDUDE_DEVICE ?= m168
CFLAGS=-g -Wall -mcall-prologues -mmcu=$(MCU) $(DEVICE_SPECIFIC_CFLAGS) -Os
LDFLAGS=-Wl,-gc-sections -lpololu_$(DEVICE) -Wl,-relax
-PORT ?= /dev/ttyACM1
+PORT ?= /dev/ttyACM0
SOURCES := $(wildcard *.c)
HEADERS := $(wildcard *.h)
diff --git a/robot/maze.c b/robot/maze.c
new file mode 100644
index 0000000..a27414f
--- /dev/null
+++ b/robot/maze.c
@@ -0,0 +1 @@
+#include "maze.h"
diff --git a/robot/maze.h b/robot/maze.h
new file mode 100644
index 0000000..640bf9c
--- /dev/null
+++ b/robot/maze.h
@@ -0,0 +1,8 @@
+#pragma once
+
+/**
+ * maze mode
+ *
+ * finds route out of maze
+ */
+void w2_mode_maze_main();
diff --git a/robot/modes.c b/robot/modes.c
new file mode 100644
index 0000000..c5b979c
--- /dev/null
+++ b/robot/modes.c
@@ -0,0 +1,3 @@
+#include "modes.h"
+
+void w2_modes_main() {}
diff --git a/robot/modes.h b/robot/modes.h
new file mode 100644
index 0000000..dd34690
--- /dev/null
+++ b/robot/modes.h
@@ -0,0 +1,10 @@
+#pragma once
+
+extern void (*g_w2_current_mode)();
+
+/**
+ * mode logic
+ *
+ * executes mode in g_w2_current_mode
+ */
+void w2_modes_main();
diff --git a/robot/readme.md b/robot/readme.md
index 03c842b..998c8b1 100644
--- a/robot/readme.md
+++ b/robot/readme.md
@@ -28,10 +28,10 @@ majority of the control logic.
```
┌──────────────────────────────────────────────────────────────────────┐
│ "Hypervisor" │
-└────────┬───────────────────┬──────────────────┬───────────────┬──────┘
-┌────────┴─────────┐┌────────┴───────┐┌─────────┴────────┐┌─────┴──────┐
-│ PC communication ││ Error handling ││ I/O Read & Write ││ Mode logic │
-└──────────────────┘└────────────────┘└──────────────────┘└─────┬──────┘
+└────────┬──────────────────┬──────────────────┬────────────────┬──────┘
+┌────────┴───────┐┌─────────┴────────┐┌────────┴─────────┐┌─────┴──────┐
+│ Error handling ││ I/O Read & Write ││ PC communication ││ Mode logic │
+└────────────────┘└──────────────────┘└──────────────────┘└─────┬──────┘
┌──────────┬──────────────┬───────────────┤
┌───┴──┐┌──────┴────┐┌────────┴───────┐┌──────┴──────┐
*modes* -> │ Maze ││ Warehouse ││ Emergency stop ││ Calibration │
@@ -84,6 +84,6 @@ this list will probably get updated from time to time:
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.
-- constants should be placed in `consts.h`
+- general constants should be placed in `consts.h`
- run `make format` as a seperate commit in case of breaking changes
diff --git a/robot/sercomm.c b/robot/sercomm.c
new file mode 100644
index 0000000..a0eed3a
--- /dev/null
+++ b/robot/sercomm.c
@@ -0,0 +1,3 @@
+#include "sercomm.h"
+
+void w2_sercomm_main() {}
diff --git a/robot/sercomm.h b/robot/sercomm.h
new file mode 100644
index 0000000..58c79b9
--- /dev/null
+++ b/robot/sercomm.h
@@ -0,0 +1,9 @@
+#pragma once
+
+/**
+ * serial pc-robot communication module
+ *
+ * - reads and parses incoming serial data
+ * - sends all data in the message buffer
+ */
+void w2_sercomm_main();
diff --git a/robot/setup.c b/robot/setup.c
new file mode 100644
index 0000000..0652911
--- /dev/null
+++ b/robot/setup.c
@@ -0,0 +1,11 @@
+#include <pololu/orangutan.h>
+
+#include "consts.h"
+#include "setup.h"
+
+void w2_setup_main() {
+ serial_set_baud_rate(W2_SERIAL_BAUD);
+
+ // indicate startup done
+ play("L50 c>c");
+}
diff --git a/robot/setup.h b/robot/setup.h
new file mode 100644
index 0000000..9d94326
--- /dev/null
+++ b/robot/setup.h
@@ -0,0 +1,12 @@
+#pragma once
+
+/**
+ * runs once at startup, plays beep when setup finishes
+ *
+ * configures:
+ * - serial connection (wixel)
+ * - timer0 for cycle duration measurement
+ * - lcd display
+ * - underside leds
+ */
+void w2_setup_main();