From ff223c70911fed38d6a82af83740eec57c5b5fb2 Mon Sep 17 00:00:00 2001 From: bkleiner Date: Sat, 19 Nov 2022 22:00:42 +0100 Subject: [PATCH] optimize control_state_t members --- src/flight/control.h | 8 ++++---- src/io/vbat.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/flight/control.h b/src/flight/control.h index 3893971b8..6774365f7 100644 --- a/src/flight/control.h +++ b/src/flight/control.h @@ -46,11 +46,11 @@ typedef struct { uint32_t looptime_us; // looptime in us float uptime; // running sum of looptimes float armtime; // running sum of looptimes (while armed) - float cpu_load; // micros we have had left last loop + uint32_t cpu_load; // micros we have had left last loop uint32_t failsafe_time_ms; // time the last failsafe occured in ms - float lipo_cell_count; + uint8_t lipo_cell_count; float cpu_temp; @@ -109,8 +109,8 @@ typedef struct { MEMBER(looptime_us, uint32) \ MEMBER(uptime, float) \ MEMBER(armtime, float) \ - MEMBER(cpu_load, float) \ - MEMBER(lipo_cell_count, float) \ + MEMBER(cpu_load, uint32) \ + MEMBER(lipo_cell_count, uint8) \ MEMBER(cpu_temp, float) \ MEMBER(vbat, float) \ MEMBER(vbat_filtered, float) \ diff --git a/src/io/vbat.c b/src/io/vbat.c index 11705f220..e411a9f68 100644 --- a/src/io/vbat.c +++ b/src/io/vbat.c @@ -27,12 +27,12 @@ void vbat_init() { for (int i = 6; i > 0; i--) { float cells = i; if (state.vbat_filtered / cells > 3.7f) { - state.lipo_cell_count = (float)cells; + state.lipo_cell_count = cells; break; } } } else { - state.lipo_cell_count = (float)profile.voltage.lipo_cell_count; + state.lipo_cell_count = profile.voltage.lipo_cell_count; } state.vbat_filtered_decay *= (float)state.lipo_cell_count; @@ -50,7 +50,7 @@ void vbat_calc() { lpf(&state.vbat_filtered, state.vbat, 0.9968f); lpf(&state.vbat_filtered_decay, state.vbat_filtered, FILTERCALC(1000, 18000e3)); - state.vbat_cell_avg = state.vbat_filtered_decay / state.lipo_cell_count; + state.vbat_cell_avg = state.vbat_filtered_decay / (float)state.lipo_cell_count; // average of all motors // filter motorpwm so it has the same delay as the filtered voltage @@ -114,7 +114,7 @@ void vbat_calc() { hyst = 0.0f; state.vbat_compensated = tempvolt + vdrop_factor * thrfilt; - state.vbat_compensated_cell_avg = state.vbat_compensated / state.lipo_cell_count; + state.vbat_compensated_cell_avg = state.vbat_compensated / (float)state.lipo_cell_count; if ((state.vbat_compensated_cell_avg < profile.voltage.vbattlow + hyst) || (state.vbat_cell_avg < VBATTLOW_ABS)) flags.lowbatt = 1;