Skip to content

Commit 61444f5

Browse files
Test Car (#203)
1 parent 2260088 commit 61444f5

4 files changed

Lines changed: 39 additions & 9 deletions

File tree

Core/Inc/u_dti.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Config. */
1818
#define TIRE_DIAMETER 16 /* inches */
19-
#define GEAR_RATIO (41.0f / 13.0f) /* unitless */
19+
#define GEAR_RATIO (39.0f / 13.0f) /* unitless */
2020
#define POLE_PAIRS 10 /* unitless */
2121

2222
/**

Core/Src/u_can.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,13 @@ void can_inbox(can_msg_t *message) {
246246
receive_shutdown_as_read_by_bms(message, &bms);
247247
update_bms_shutdown(bms.shutdown_state);
248248

249-
/* If shutdown is active, cancel the RTDS sound if it's active. */
250-
if(bms.shutdown_state == true) {
249+
/* If shutdown is open, cancel RTDS. */
250+
if(bms.shutdown_state == false) {
251251
rtds_cancelRTDS();
252252
rtds_stopReverseSound();
253+
if(get_active()) {
254+
set_home_mode();
255+
}
253256
}
254257
break;
255258
default:

Core/Src/u_pedals.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static pedal_data_t pedal_data = { 0 };
8080

8181
/* Performance Limits */
8282
#define PIT_MAX_SPEED 5.0 // (mph). Speed limit in pit mode.
83-
#define MAX_TORQUE 40 // (Nm). Maximum torque output
83+
#define MAX_TORQUE 160 // (Nm). Maximum torque output
8484
#define TORQUE_ACCUMULATOR_SIZE 10 // (Number). Size of the moving average filter for torque stuff.
8585
#define MAX_REGEN_CURRENT 250 // (AC Amps). Maximum regenerative braking current.
8686

@@ -683,18 +683,20 @@ void pedals_process(void) {
683683
// serial_monitor("pedals", "psi brake2", "%f", pedal_data.psi_brake2);
684684

685685
/* Set brake state, and turn brakelight on/off. */
686+
const float PEDAL_BRAKE_TURNOFF_TRESH = 0.004f; // Amount below PEDAL_BRAKE_TRESH to register the brake as 'off'. This is needed so the state doesn't flicker super quickly.
686687
if(pedal_data.percentage_brake > PEDAL_BRAKE_THRESH) {
687688
brake_pressed = true;
688689
if(efuse_get_state(EFUSE_BRAKE) == EF_AUTO) {
689690
efuse_enable(EFUSE_BRAKE);
690691
}
691692
}
692-
else {
693+
else if(pedal_data.percentage_brake < (PEDAL_BRAKE_THRESH - PEDAL_BRAKE_TURNOFF_TRESH)){
693694
brake_pressed = false;
694695
if(efuse_get_state(EFUSE_BRAKE) == EF_AUTO) {
695696
efuse_disable(EFUSE_BRAKE);
696697
}
697698
}
699+
// The brakelight was turning on and off super fast, so there's now a 0.05f lower threshold. This way, the brake's turn off point is lower than the turn on point, so the pedal needs to travel lower to turn off than it did to turn on.
698700

699701
if (pedal_data.percentage_accel >= 0.05) {
700702
accel_pressed = true;

Core/Src/u_threads.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,14 +445,26 @@ void vEFuses(ULONG thread_input) {
445445
/* Determine pump1 eFuse state. */
446446
static const uint16_t PUMP1_UPPERBOUND = 45;
447447
static const uint16_t PUMP1_LOWERBOUND = 35;
448+
static const int PUMP1_SWITCHING_TIMEOUT = 5000;
449+
static nertimer_t pump1_switching_timer = { 0 };
448450
switch(data.control_state[EFUSE_PUMP1]) {
449451
case EF_ON: efuse_enable(EFUSE_PUMP1); break;
450452
case EF_OFF: efuse_disable(EFUSE_PUMP1); break;
451453
case EF_AUTO:
452-
if(motor_temp >= PUMP1_UPPERBOUND) {
454+
if(controller_temp >= PUMP1_UPPERBOUND) {
455+
/* If timer is still active, break early. */
456+
if(!is_timer_expired(&pump1_switching_timer) && is_timer_active(&pump1_switching_timer)) { break; }
457+
458+
/* Otherwise, make the state change but restart the timer. */
453459
efuse_enable(EFUSE_PUMP1);
454-
} else if (motor_temp <= PUMP1_LOWERBOUND) {
460+
start_timer(&pump1_switching_timer, PUMP1_SWITCHING_TIMEOUT);
461+
} else if (controller_temp <= PUMP1_LOWERBOUND) {
462+
/* If timer is still active, break early. */
463+
if(!is_timer_expired(&pump1_switching_timer) && is_timer_active(&pump1_switching_timer)) { break; }
464+
465+
/* Otherwise, make the state change but restart the timer. */
455466
efuse_disable(EFUSE_PUMP1);
467+
start_timer(&pump1_switching_timer, PUMP1_SWITCHING_TIMEOUT);
456468
}
457469
break;
458470
default: efuse_enable(EFUSE_PUMP1); break;
@@ -461,14 +473,26 @@ void vEFuses(ULONG thread_input) {
461473
/* Determine pump2 eFuse state. */
462474
static const uint16_t PUMP2_UPPERBOUND = 45;
463475
static const uint16_t PUMP2_LOWERBOUND = 35;
476+
static const int PUMP2_SWITCHING_TIMEOUT = 5000;
477+
static nertimer_t pump2_switching_timer = { 0 };
464478
switch(data.control_state[EFUSE_PUMP2]) {
465479
case EF_ON: efuse_enable(EFUSE_PUMP2); break;
466480
case EF_OFF: efuse_disable(EFUSE_PUMP2); break;
467481
case EF_AUTO:
468-
if(controller_temp >= PUMP2_UPPERBOUND) {
482+
if(motor_temp >= PUMP2_UPPERBOUND) {
483+
/* If timer is still active, break early. */
484+
if(!is_timer_expired(&pump2_switching_timer) && is_timer_active(&pump2_switching_timer)) { break; }
485+
486+
/* Otherwise, make the state change but restart the timer. */
469487
efuse_enable(EFUSE_PUMP2);
470-
} else if (controller_temp <= PUMP2_LOWERBOUND) {
488+
start_timer(&pump2_switching_timer, PUMP2_SWITCHING_TIMEOUT);
489+
} else if (motor_temp <= PUMP2_LOWERBOUND) {
490+
/* If timer is still active, break early. */
491+
if(!is_timer_expired(&pump2_switching_timer) && is_timer_active(&pump2_switching_timer)) { break; }
492+
493+
/* Otherwise, make the state change but restart the timer. */
471494
efuse_disable(EFUSE_PUMP2);
495+
start_timer(&pump2_switching_timer, PUMP2_SWITCHING_TIMEOUT);
472496
}
473497
break;
474498
default: efuse_enable(EFUSE_PUMP2); break;
@@ -700,6 +724,7 @@ void vEFuses(ULONG thread_input) {
700724
}
701725
}
702726

727+
703728
/* Mux Thread (for the ADC multiplexer). */
704729
static thread_t mux_thread = {
705730
.name = "Mux Thread", /* Name */

0 commit comments

Comments
 (0)