diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-06-04 18:42:31 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-06-04 18:42:31 +0200 |
commit | 4fed6f532cb9c990e0a30c3e541f63b3a39383ab (patch) | |
tree | 86f8b61e64df7b0387a24859133b2ca13489b41c /robot | |
parent | 595763efb64ee861f3ccf458ff35992b94f2fa3a (diff) |
slow down motors when disconnected
Diffstat (limited to 'robot')
-rw-r--r-- | robot/makefile | 2 | ||||
-rw-r--r-- | robot/mode_dirc.c | 14 | ||||
-rw-r--r-- | robot/mode_dirc.h | 1 | ||||
-rw-r--r-- | robot/sercomm.c | 4 |
4 files changed, 10 insertions, 11 deletions
diff --git a/robot/makefile b/robot/makefile index ed700ae..5f05872 100644 --- a/robot/makefile +++ b/robot/makefile @@ -9,7 +9,7 @@ PORT ?= /dev/ttyACM0 # SIM = true CFLAGS=-g -Wall $(DEVICE_SPECIFIC_CFLAGS) -Os -LDFLAGS=-Wl,-gc-sections -Wl,-relax +LDFLAGS=-Wl,-u,vfprintf -lprintf_flt -lm -Wl,-relax -Wl,-gc-sections include ../shared/os.mk all: $(if $(SIM), $(TARGET), out.hex) diff --git a/robot/mode_dirc.c b/robot/mode_dirc.c index 397d44d..b7df974 100644 --- a/robot/mode_dirc.c +++ b/robot/mode_dirc.c @@ -5,14 +5,18 @@ #include "../shared/util.h" #include "orangutan_shim.h" +#include <string.h> +#include "../shared/errcatch.h" + int16_t g_w2_mode_dirc_motor_l = 0; int16_t g_w2_mode_dirc_motor_r = 0; -double g_w2_mode_dirc_power = 1.0; +uint8_t g_w2_mode_dirc_power = 100; void w2_mode_dirc() { - // if (g_w2_connected) g_w2_mode_dirc_power = 1.0; - // else g_w2_mode_dirc_power = W2_MAX(0, g_w2_mode_dirc_power - 0.01); + if (g_w2_connected == 1) g_w2_mode_dirc_power = 100; + else g_w2_mode_dirc_power = W2_MAX(0, g_w2_mode_dirc_power - 1); + + if (g_w2_mode_dirc_power == 0) w2_modes_call(W2_M_HALT); - // if (g_w2_mode_dirc_power == 0.0) w2_modes_call(W2_M_HALT); - set_motors(g_w2_mode_dirc_motor_l * g_w2_mode_dirc_power, g_w2_mode_dirc_motor_r * g_w2_mode_dirc_power); + set_motors(g_w2_mode_dirc_motor_l * g_w2_mode_dirc_power / 100, g_w2_mode_dirc_motor_r * g_w2_mode_dirc_power / 100); } diff --git a/robot/mode_dirc.h b/robot/mode_dirc.h index bf02270..12c967a 100644 --- a/robot/mode_dirc.h +++ b/robot/mode_dirc.h @@ -6,7 +6,6 @@ extern int16_t g_w2_mode_dirc_motor_l; extern int16_t g_w2_mode_dirc_motor_r; -extern double g_w2_mode_dirc_power; /** * direct control mode diff --git a/robot/sercomm.c b/robot/sercomm.c index 6e191d2..f14832a 100644 --- a/robot/sercomm.c +++ b/robot/sercomm.c @@ -93,10 +93,6 @@ void w2_cmd_ping_tx(w2_s_bin *data) { g_w2_ping_received = true; g_w2_ping_timeout = false; g_w2_connected = true; - - char buf[32]; - sprintf(buf, "rec: %i, tim: %i, con: %i", g_w2_ping_received, g_w2_ping_timeout, g_w2_connected); - w2_errcatch_throw_msg(0x69, strlen(buf), buf); } void w2_cmd_ping_rx(w2_s_bin *data) { |