Skip to content

Commit

Permalink
optimize control_state_t members
Browse files Browse the repository at this point in the history
  • Loading branch information
bkleiner committed Nov 26, 2022
1 parent f7a3736 commit ff223c7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/flight/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) \
Expand Down
8 changes: 4 additions & 4 deletions src/io/vbat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ff223c7

Please sign in to comment.