aboutsummaryrefslogtreecommitdiff
path: root/zumo
diff options
context:
space:
mode:
Diffstat (limited to 'zumo')
-rw-r--r--zumo/protocol.cpp12
-rw-r--r--zumo/protocol.h12
-rw-r--r--zumo/strlutest/.gitignore1
-rw-r--r--zumo/strlutest/makefile21
-rw-r--r--zumo/strlutest/strlutest.cpp10
-rw-r--r--zumo/zumo.ino6
6 files changed, 50 insertions, 12 deletions
diff --git a/zumo/protocol.cpp b/zumo/protocol.cpp
index d176c24..06e2993 100644
--- a/zumo/protocol.cpp
+++ b/zumo/protocol.cpp
@@ -13,18 +13,18 @@
Zumo32U4OLED display;
void handle_cmd(unsigned char cmd, dui_state_t *state) {
- Serial.println(cmd,HEX);
+ Serial.println(cmd, HEX);
if (cmd == DUI_CMD_NULL) return;
else if (DUI_CMD_SIGN_START <= cmd && cmd <= DUI_CMD_SIGN_END) {
state->current_sign = (dui_e_sign) (cmd - DUI_CMD_SIGN_START);
- display.clear();
- display.print(state->current_sign+1);
- display.gotoXY(0, 1);
+ display.clear();
+ if (DUI_SIGN_LOOKUP[state->current_sign] == nullptr) return;
+ display.print(DUI_SIGN_LOOKUP[state->current_sign]);
} else if (DUI_CMD_SPEED_START <= cmd && cmd <= DUI_CMD_SPEED_END) {
- Serial.print(" Hallo: " );
+ Serial.print(" Hallo: " );
state->Speed = (float) (cmd - DUI_CMD_SPEED_START) / (float) (DUI_CMD_SPEED_END - DUI_CMD_SPEED_START);
- Serial.println(state->Speed);
+ Serial.println(state->Speed);
} else if (DUI_CMD_STEER_START <= cmd && cmd <= DUI_CMD_STEER_END) {
state->steer = (float) (cmd - DUI_CMD_STEER_START) / (float) (DUI_CMD_STEER_END - DUI_CMD_STEER_START) * (float) 2 - (float) 1;
}
diff --git a/zumo/protocol.h b/zumo/protocol.h
index 5eb2343..ea3e27d 100644
--- a/zumo/protocol.h
+++ b/zumo/protocol.h
@@ -19,6 +19,18 @@ typedef enum {
DUI_SIGN_LIGHT_GO, /** @brief traffic light green (keep current speed) */
} dui_e_sign;
+const char* const DUI_SIGN_LOOKUP[16] = {
+ [DUI_SIGN_NONE] = "",
+ [DUI_SIGN_STOP] = "bord\nstop",
+ [DUI_SIGN_LEFT] = "bord\nlinks",
+ [DUI_SIGN_RIGHT] = "bord\nrechts",
+ [DUI_SIGN_SPEED_LIMIT_LOW] = "snelheid\nlaag",
+ [DUI_SIGN_SPEED_LIMIT_HIGH] = "snelheid\nhoog",
+ [DUI_SIGN_LIGHT_STOP] = "stop.l.\nrood",
+ [DUI_SIGN_LIGHT_FLOOR_IT] = "stop.l.\ngeel",
+ [DUI_SIGN_LIGHT_GO] = "stop.l.\ngroen",
+};
+
typedef struct {
float steer; /** @brief steer value (-1 is left, +1 is right) */
float Speed; /** @brief speed (0-15) */
diff --git a/zumo/strlutest/.gitignore b/zumo/strlutest/.gitignore
new file mode 100644
index 0000000..15010c5
--- /dev/null
+++ b/zumo/strlutest/.gitignore
@@ -0,0 +1 @@
+strlutest
diff --git a/zumo/strlutest/makefile b/zumo/strlutest/makefile
new file mode 100644
index 0000000..f05e0ba
--- /dev/null
+++ b/zumo/strlutest/makefile
@@ -0,0 +1,21 @@
+CPP = g++
+LD = g++
+RM = rm -f
+CFLAGS =
+LFLAGS =
+TARGET = strlutest
+
+SRCS := strlutest.cpp
+OBJS := strlutest.o
+
+all: strlutest
+
+%.o: %.cpp
+ $(CPP) -c $(CFLAGS) $< -o $@
+
+$(TARGET): $(OBJS)
+ $(LD) $^ $(LFLAGS) -o $@
+
+clean:
+ $(RM) $(TARGET) $(OBJS)
+
diff --git a/zumo/strlutest/strlutest.cpp b/zumo/strlutest/strlutest.cpp
new file mode 100644
index 0000000..72ec591
--- /dev/null
+++ b/zumo/strlutest/strlutest.cpp
@@ -0,0 +1,10 @@
+#include <cstdio>
+
+#include "../protocol.h"
+
+int main() {
+ for (unsigned int i = 0; i < 15; i++) {
+ if (DUI_SIGN_LOOKUP[i] == NULL) continue;
+ printf("%d: %s\n", i, DUI_SIGN_LOOKUP[i]);
+ }
+}
diff --git a/zumo/zumo.ino b/zumo/zumo.ino
index a4f4d6b..9e79581 100644
--- a/zumo/zumo.ino
+++ b/zumo/zumo.ino
@@ -2,7 +2,6 @@
#include <Arduino.h>
#include <Wire.h>
-
#include "control.h"
#include "protocol.h"
#include "pid.h"
@@ -24,12 +23,9 @@ void setup() {
pinMode(DUI_PINOUT_NICLA_TX, OUTPUT);
pinMode(DUI_PINOUT_NICLA_RX, INPUT_PULLUP);
Serial.begin(11500);
-
}
void loop() {
-
-
static unsigned char cmd_old = 0x00;
for (unsigned int i = 0; i < 1000; i++) {
digitalWrite(DUI_PINOUT_NICLA_TX, LOW);
@@ -44,6 +40,4 @@ void loop() {
g_dui_current_state.current_sign = g_dui_target_state.current_sign;
apply_state(&g_dui_current_state);
-
-
}