Endurance view

This commit is contained in:
2024-06-10 22:09:21 +02:00
parent e23389a0b9
commit 5a66f9bc54
36 changed files with 2154 additions and 170 deletions

View File

@ -4,7 +4,56 @@
Model::Model() : modelListener(0) {}
#ifdef SIMULATOR
void Model::tick() { modelListener->vehicleStateUpdated(); }
void bounce(float &value, bool &rising, float step, float lower, float upper) {
if (rising) {
value += step;
if (value > upper) {
value = upper;
rising = false;
}
} else {
value -= step;
if (value < lower) {
value = lower;
rising = true;
}
}
}
void Model::tick() {
static float last_lap_delta = 0;
static bool lap_delta_rising = true;
static float overall_delta = 0;
static bool overall_delta_rising = false;
static float power_limit = 20;
static bool power_limit_rising = false;
static float speed_limit = 70;
static bool speed_limit_rising = true;
static float soc = 100;
static bool soc_rising = false;
static float bat_temp = 13;
static bool bat_temp_rising = true;
static int iter = 0;
if (iter++ % 5 != 0) {
return;
}
bounce(last_lap_delta, lap_delta_rising, 0.2, -12, 12);
bounce(overall_delta, overall_delta_rising, 0.1, -12, 12);
bounce(power_limit, power_limit_rising, 0.1, 5, 30);
bounce(speed_limit, speed_limit_rising, 0.2, 50, 100);
bounce(soc, soc_rising, 0.5, 0, 100);
bounce(bat_temp, bat_temp_rising, 0.2, 10, 59);
vehicle_state.bat_delta_last = last_lap_delta;
vehicle_state.bat_delta_overall = overall_delta;
vehicle_state.power_limit = power_limit;
vehicle_state.speed_limit = speed_limit;
vehicle_state.soc_ts = soc;
vehicle_state.max_cell_temp = bat_temp;
vehicle_state.active_mission = MISSION_MANUAL;
modelListener->vehicleStateUpdated();
}
#else
#include "main.h"