Add most recent params for FT24

This commit is contained in:
Julian 2024-07-22 08:43:42 +02:00
parent 555a114ae5
commit a07d51f223
4 changed files with 95 additions and 97 deletions

View File

@ -10,17 +10,15 @@ extern "C" {
#include "util.h" #include "util.h"
CountedEnum(ParamType, size_t, PF_BBAL, PF_SLIPREF, PF_MUMAX, PF_ASRP, PF_ASRON, CountedEnum(ParamType, size_t, PF_PLIM, PF_TLIM, PF_SLIM, PF_TVEC, PF_PG, PF_REKU);
PF_ASRI, PF_PLIM);
typedef struct { typedef struct {
float bbal; unsigned plim; //< Power limit
float slipref; unsigned tlim; //< Torque limit
float mumax; unsigned slim; //< Speed limit
unsigned asrp; unsigned tvec; //< Torque vectoring
unsigned asri; unsigned pg; //< Power ground
unsigned asron; unsigned reku; //< Rekuperation
unsigned plim;
} Params; } Params;
extern Params params; extern Params params;

View File

@ -2,103 +2,98 @@
#include "can-halal.h" #include "can-halal.h"
#include "vehicle.h" #include "vehicle.h"
/**
* Decrements the given value if it is above the minimum allowed value
*/
#define DEC_IF_ABOVE(param_val, min_val, decr_amt) ((param_val) = ((param_val) - (decr_amt) ) > (min_val) ? ((param_val) - (decr_amt)) : (min_val))
#define INC_IF_BELOW(param_val, max_val, incr_amt) ((param_val) = ((param_val) + (incr_amt)) > (max_val) ? ((param_val) + (incr_amt)) : (max_val))
Params params = {0}; Params params = {0};
void params_init() { void params_init()
params.bbal = 50; {
// Default values
params.plim = 20; params.plim = 20;
params.tlim = 1400;
params.slim = 70;
params.tvec = 50;
params.pg = 0;
params.reku = 0;
} }
void params_inc(ParamType param) { void params_inc(ParamType param)
switch (param) { {
case PF_BBAL: switch (param)
params.bbal += 0.5f; {
if (params.bbal > 100.0f) {
params.bbal = 100.0f;
}
break;
case PF_SLIPREF:
params.slipref += 0.01f;
break;
case PF_MUMAX:
params.mumax += 0.1f;
break;
case PF_ASRP:
params.asrp++;
break;
case PF_ASRI:
params.asri++;
break;
case PF_ASRON:
params.asron = 1;
break;
case PF_PLIM: case PF_PLIM:
params.plim = (params.plim < 80) ? params.plim + 1 : 80; INC_IF_BELOW(params.plim, 80, 1);
break;
case PF_TLIM:
INC_IF_BELOW(params.tlim, 1500, 100);
break;
case PF_SLIM:
INC_IF_BELOW(params.slim, 100, 1);
break;
case PF_TVEC:
INC_IF_BELOW(params.tvec, 100, 1);
break;
case PF_PG:
INC_IF_BELOW(params.pg, 100, 1);
break;
case PF_REKU:
INC_IF_BELOW(params.reku, 100, 1);
break; break;
} }
} }
void params_dec(ParamType param) { void params_dec(ParamType param)
switch (param) { {
case PF_BBAL: switch (param)
params.bbal -= 0.5f; {
if (params.bbal < 0.0f) {
params.bbal = 0.0f;
}
break;
case PF_SLIPREF:
if (params.slipref > 0) {
params.slipref -= 0.01f;
}
break;
case PF_MUMAX:
if (params.mumax > 0) {
params.mumax -= 0.1f;
}
break;
case PF_ASRP:
if (params.asrp > 0) {
params.asrp--;
}
break;
case PF_ASRI:
if (params.asri > 0) {
params.asri--;
}
break;
case PF_ASRON:
params.asron = 0;
break;
case PF_PLIM: case PF_PLIM:
params.plim = (params.plim > 2) ? params.plim - 1 : 2; DEC_IF_ABOVE(params.plim, 0, 1);
break;
case PF_TLIM:
DEC_IF_ABOVE(params.tlim, 0, 100);
break;
case PF_SLIM:
DEC_IF_ABOVE(params.slim, 0, 1);
break;
case PF_TVEC:
DEC_IF_ABOVE(params.tvec, 0, 1);
break;
case PF_PG:
DEC_IF_ABOVE(params.pg, 0, 1);
break;
case PF_REKU:
DEC_IF_ABOVE(params.reku, 0, 1);
break; break;
} }
} }
void params_broadcast(ParamType param) { void params_broadcast(ParamType param)
{
int32_t value; int32_t value;
switch (param) { switch (param)
case PF_BBAL: {
value = params.bbal * 10;
break;
case PF_SLIPREF:
value = params.slipref * 100;
break;
case PF_MUMAX:
value = params.mumax * 10;
break;
case PF_ASRP:
value = params.asrp;
break;
case PF_ASRI:
value = params.asri;
break;
case PF_ASRON:
value = params.asron;
break;
case PF_PLIM: case PF_PLIM:
value = params.plim; value = params.plim;
break; break;
case PF_TLIM:
value = params.tlim;
break;
case PF_SLIM:
value = params.slim;
break;
case PF_TVEC:
value = params.tvec;
break;
case PF_PG:
value = params.pg;
break;
case PF_REKU:
value = params.reku;
break;
default: default:
return; return;
} }

View File

@ -12,6 +12,10 @@
#include "leds.h" #include "leds.h"
#define DRS_BUTTON_IDX (6)
#define DRS_PRESS_WAIT_CYCLES (10)
static drs_press_buf_cycles = 0;
void ui_thread_entry(ULONG _) { void ui_thread_entry(ULONG _) {
GPIO_TypeDef *button_ports[NUM_BUTTONS] = {BTN1_GPIO_Port, BTN2_GPIO_Port, GPIO_TypeDef *button_ports[NUM_BUTTONS] = {BTN1_GPIO_Port, BTN2_GPIO_Port,
BTN3_GPIO_Port, BTN4_GPIO_Port, BTN3_GPIO_Port, BTN4_GPIO_Port,
@ -46,12 +50,15 @@ void ui_thread_entry(ULONG _) {
tx_event_flags_set(&gui_update_events, GUI_UPDATE_NEXT_SCREEN, TX_OR); tx_event_flags_set(&gui_update_events, GUI_UPDATE_NEXT_SCREEN, TX_OR);
} }
if (button_states[6] == GPIO_PIN_SET) { if (button_states[DRS_BUTTON_IDX] == GPIO_PIN_SET) {
// Set leftmost led to blue to indicate DRS activation // Set leftmost led to blue to indicate DRS activation
drs_press_buf_cycles = DRS_PRESS_WAIT_CYCLES;
led_set(0, 0, 0, 255); led_set(0, 0, 0, 255);
} else { } if (drs_press_buf_cycles < 0) {
// Turn it off if not active // Assume no longer active, turn off
led_set(0, 0, 0, 0); led_set(0, 0, 0, 0);
} else if (drs_press_buf_cycles >= 0) {
drs_press_buf_cycles--;
} }
vehicle_broadcast_buttons(button_states); vehicle_broadcast_buttons(button_states);

View File

@ -274,14 +274,12 @@ static_assert(sizeof(dataFieldDescs) / sizeof(dataFieldDescs[0]) ==
#define PARAM_FIELD(FIELD) []() { return (void *)&params.FIELD; } #define PARAM_FIELD(FIELD) []() { return (void *)&params.FIELD; }
NamedFieldDescription paramFieldDescs[] = { NamedFieldDescription paramFieldDescs[] = {
[PF_BBAL] = {NamedFieldKind::Float, "BBAL", 2, 1, PARAM_FIELD(bbal)},
[PF_SLIPREF] = {NamedFieldKind::Float, "SLIPREF", 2, 2,
PARAM_FIELD(slipref)},
[PF_MUMAX] = {NamedFieldKind::Float, "MUMAX", 2, 1, PARAM_FIELD(mumax)},
[PF_ASRP] = {NamedFieldKind::Int, "ASR-P", 2, 0, PARAM_FIELD(asrp)},
[PF_ASRON] = {NamedFieldKind::Int, "ASR-ON", 2, 0, PARAM_FIELD(asron)},
[PF_ASRI] = {NamedFieldKind::Int, "ASR-I", 2, 0, PARAM_FIELD(asri)},
[PF_PLIM] = {NamedFieldKind::Int, "PLIM", 2, 0, PARAM_FIELD(plim)}, [PF_PLIM] = {NamedFieldKind::Int, "PLIM", 2, 0, PARAM_FIELD(plim)},
[PF_TLIM] = {NamedFieldKind::Int, "TLIM", 2, 1, PARAM_FIELD(plim)},
[PF_SLIM] = {NamedFieldKind::Int, "SLIM", 2, 2, PARAM_FIELD(slim)},
[PF_TVEC] = {NamedFieldKind::Int, "TVEC", 2, 1, PARAM_FIELD(tvec)},
[PF_PG] = {NamedFieldKind::Int, "PG", 2, 0, PARAM_FIELD(pg)},
[PF_REKU] = {NamedFieldKind::Int, "REKU", 2, 0, PARAM_FIELD(reku)},
}; };
static_assert(sizeof(paramFieldDescs) / sizeof(paramFieldDescs[0]) == static_assert(sizeof(paramFieldDescs) / sizeof(paramFieldDescs[0]) ==