diff options
author | UnavailableDev <69792062+UnavailableDev@users.noreply.github.com> | 2023-06-06 12:00:58 +0200 |
---|---|---|
committer | UnavailableDev <69792062+UnavailableDev@users.noreply.github.com> | 2023-06-06 12:00:58 +0200 |
commit | 077069b82a34bd5e0d51509eb751df9b44a5f6d3 (patch) | |
tree | 1753f1266c2837282c7a1f7ce8137161c85a1a0a /zumo/protocol.cpp | |
parent | f2335307a26a8ab3e18d8990d2640a8de4cbd0e4 (diff) | |
parent | 0f764db3c3595e863a4949c67592451c7d65a2cf (diff) |
Merge branch 'master' of https://github.com/unavailabledev/avans-dui
Diffstat (limited to 'zumo/protocol.cpp')
-rw-r--r-- | zumo/protocol.cpp | 32 |
1 files changed, 7 insertions, 25 deletions
diff --git a/zumo/protocol.cpp b/zumo/protocol.cpp index fea8a00..ab8397a 100644 --- a/zumo/protocol.cpp +++ b/zumo/protocol.cpp @@ -1,39 +1,21 @@ -#include <Zumo32U4Motors.h> - #include "protocol.h" -#define DUI_SPEED_MOD 96.0f -#define DUI_MOTOR_DIFF 0.6f - #define DUI_CMD_NULL 0x00 #define DUI_CMD_SIGN_START 0x01 #define DUI_CMD_SIGN_END 0x0f -#define DUI_CMD_STEER_START 0x10 -#define DUI_CMD_STEER_END 0x1f -#define DUI_CMD_SPEED_START 0x20 -#define DUI_CMD_SPEED_END 0xff +#define DUI_CMD_SPEED_START 0x10 +#define DUI_CMD_SPEED_END 0x1f +#define DUI_CMD_STEER_START 0x20 +#define DUI_CMD_STEER_END 0xff void handle_cmd(unsigned char cmd, dui_state_t *state) { 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); - } 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); } else if (DUI_CMD_SPEED_START <= cmd && cmd <= DUI_CMD_SPEED_END) { - state->speed = ((float) (cmd - DUI_CMD_SPEED_START) / (float) (DUI_CMD_SPEED_START - DUI_CMD_SPEED_END) * (float) 2 - (float) 1); + state->speed = (float) (cmd - DUI_CMD_SPEED_START) / (float) (DUI_CMD_SPEED_END - DUI_CMD_SPEED_START); + } 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; } } -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; - - Zumo32U4Motors::setLeftSpeed((int16_t) motor_l); - Zumo32U4Motors::setRightSpeed((int16_t) motor_r); - - // TODO: print sign on OLED screen -} - -unsigned char uart_read() { - return 0x00; -} |