aboutsummaryrefslogtreecommitdiff
path: root/zumo
diff options
context:
space:
mode:
Diffstat (limited to 'zumo')
-rw-r--r--zumo/control.cpp10
-rw-r--r--zumo/pid.cpp3
-rw-r--r--zumo/protocol.cpp16
-rw-r--r--zumo/protocol.h15
-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
8 files changed, 66 insertions, 16 deletions
diff --git a/zumo/control.cpp b/zumo/control.cpp
index 778969a..71e7537 100644
--- a/zumo/control.cpp
+++ b/zumo/control.cpp
@@ -6,11 +6,11 @@
#include "control.h"
#define DUI_SPEED_MOD 96.0f
-#define DUI_MOTOR_DIFF 0.6f
+#define DUI_MOTOR_DIFF 0.62f
void apply_state(dui_state_t *state) {
- float motor_l = 0.5f * state->speed * (+1.f * state->steer * DUI_MOTOR_DIFF - DUI_MOTOR_DIFF + 2) * state->speed_mod * DUI_SPEED_MOD;
- float motor_r = 0.5f * state->speed * (-1.f * state->steer * DUI_MOTOR_DIFF - DUI_MOTOR_DIFF + 2) * state->speed_mod * DUI_SPEED_MOD;
+ float motor_l = 0.5f * state->Speed * (+1.f * state->steer * DUI_MOTOR_DIFF - DUI_MOTOR_DIFF + 2) * state->speed_mod * DUI_SPEED_MOD;
+ float motor_r = 0.5f * state->Speed * (-1.f * state->steer * DUI_MOTOR_DIFF - DUI_MOTOR_DIFF + 2) * state->speed_mod * DUI_SPEED_MOD;
Serial.print(motor_l);
Serial.print(" ");
@@ -18,8 +18,7 @@ void apply_state(dui_state_t *state) {
Serial.println("");
- Zumo32U4Motors::setLeftSpeed((int16_t) motor_l);
- Zumo32U4Motors::setRightSpeed((int16_t) motor_r);
+ Zumo32U4Motors::setSpeeds((int16_t) motor_l,(int16_t) motor_r);
// TODO: print sign on OLED screen
}
@@ -38,6 +37,5 @@ unsigned char uart_read() {
}
delayMicroseconds(1000); // wait out stop bit
-
return byte;
}
diff --git a/zumo/pid.cpp b/zumo/pid.cpp
index 7c1cbda..17588e3 100644
--- a/zumo/pid.cpp
+++ b/zumo/pid.cpp
@@ -45,8 +45,7 @@ PID speed_pid = PID();
PID steer_pid = PID();
PID speed_mod_pid = PID();
void apply_pid(dui_state_t* target, dui_state_t* current) {
- current->speed = speed_pid.iter(target->speed);
+ current->Speed = speed_pid.iter(target->Speed);
current->steer = steer_pid.iter(target->steer);
current->speed_mod = speed_mod_pid.iter(target->speed_mod);
}
-
diff --git a/zumo/protocol.cpp b/zumo/protocol.cpp
index ab8397a..06e2993 100644
--- a/zumo/protocol.cpp
+++ b/zumo/protocol.cpp
@@ -1,5 +1,8 @@
-#include "protocol.h"
+#include <Zumo32U4.h>
+#include "protocol.h"
+#include <Arduino.h>
+#include <Zumo32U4LCD.h>
#define DUI_CMD_NULL 0x00
#define DUI_CMD_SIGN_START 0x01
#define DUI_CMD_SIGN_END 0x0f
@@ -7,15 +10,22 @@
#define DUI_CMD_SPEED_END 0x1f
#define DUI_CMD_STEER_START 0x20
#define DUI_CMD_STEER_END 0xff
+Zumo32U4OLED display;
void handle_cmd(unsigned char cmd, dui_state_t *state) {
+ 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();
+ 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) {
- state->speed = (float) (cmd - DUI_CMD_SPEED_START) / (float) (DUI_CMD_SPEED_END - DUI_CMD_SPEED_START);
+ Serial.print(" Hallo: " );
+ state->Speed = (float) (cmd - DUI_CMD_SPEED_START) / (float) (DUI_CMD_SPEED_END - DUI_CMD_SPEED_START);
+ 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 a1f9951..ea3e27d 100644
--- a/zumo/protocol.h
+++ b/zumo/protocol.h
@@ -19,13 +19,24 @@ 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) */
+ float Speed; /** @brief speed (0-15) */
dui_e_sign current_sign; /** @brief last seen sign */
float speed_mod; /** @brief global speed multiplier */
} dui_state_t;
/** @brief read and apply cmd to state */
void handle_cmd(unsigned char cmd, dui_state_t *state);
-
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 1a64381..9e79581 100644
--- a/zumo/zumo.ino
+++ b/zumo/zumo.ino
@@ -8,13 +8,13 @@
dui_state_t g_dui_target_state = {
.steer = 0.0f,
- .speed = 0.0f,
+ .Speed = 0.0f,
.current_sign = DUI_SIGN_NONE,
.speed_mod = 1.f,
};
dui_state_t g_dui_current_state = {
.steer = 0.f,
- .speed = 0.f,
+ .Speed = 0.f,
.current_sign = DUI_SIGN_NONE,
.speed_mod = 1.f,
};
@@ -22,7 +22,7 @@ dui_state_t g_dui_current_state = {
void setup() {
pinMode(DUI_PINOUT_NICLA_TX, OUTPUT);
pinMode(DUI_PINOUT_NICLA_RX, INPUT_PULLUP);
- Serial.begin(115200);
+ Serial.begin(11500);
}
void loop() {