From a779298de317e09aeb8f31a574d1e4398df1af16 Mon Sep 17 00:00:00 2001 From: crinq Date: Tue, 26 Apr 2022 16:43:21 +0200 Subject: [PATCH] print clamping warning --- shared/comps/fault.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/shared/comps/fault.c b/shared/comps/fault.c index 26730709..98f01fcb 100644 --- a/shared/comps/fault.c +++ b/shared/comps/fault.c @@ -63,6 +63,9 @@ HAL_PIN(print); HAL_PIN(brake_release); +HAL_PIN(warn_timer); +HAL_PIN(error_timer); + //fault strings for fault_t form common.h static const char* fault_string[] = { "no error", @@ -289,6 +292,9 @@ static void rt_func(float period, void *ctx_ptr, hal_pin_inst_t *pin_ptr) { if(PIN(brake_release) > 0.0) { PIN(mot_brake) = 1.0; } + + PIN(warn_timer) = MAX(PIN(warn_timer) - period, 0.0); + PIN(error_timer) = MAX(PIN(error_timer) - period, 0.0); } @@ -296,6 +302,23 @@ static void nrt_func(void *ctx_ptr, hal_pin_inst_t *pin_ptr) { struct fault_ctx_t *ctx = (struct fault_ctx_t *)ctx_ptr; struct fault_pin_ctx_t *pins = (struct fault_pin_ctx_t *)pin_ptr; + if(PIN(warn_timer) <= 0.0){ + if(PIN(dc_volt) > PIN(high_dc_volt)){ + printf("WARNING: over voltage current clamping active\n"); + PIN(warn_timer) = 1.0; + } + + if(PIN(mot_temp) > PIN(high_mot_temp)){ + printf("WARNING: over temperature (motor) current clamping active\n"); + PIN(warn_timer) = 1.0; + } + + if(PIN(hv_temp) > PIN(high_hv_temp)){ + printf("WARNING: over temperature (driver) current clamping active\n"); + PIN(warn_timer) = 1.0; + } + } + //TODO: fix EDGE if(EDGE(ctx->state) || PIN(print) > 0.0) { PIN(print) = 0.0;