Skip to content

Commit

Permalink
debugging, changing more func signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabramz committed Jul 31, 2024
1 parent 88a53af commit 98b427e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Core/Inc/dti.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void dti_set_torque(int16_t torque);
*
* @param current_target The desired AC current to do regenerative braking at. Must be positive.
*/
void dti_set_regen(uint16_t current_target);
void dti_set_regen(float current_target);

/**
* @brief Send a CAN message containing the AC current target for regenerative braking.
Expand Down
10 changes: 3 additions & 7 deletions Core/Src/dti.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ void dti_set_torque(int16_t torque)
dti_set_current(ac_current);
}

void dti_set_regen(uint16_t current_target)
void dti_set_regen(float current_target)
{
/* Simple moving average to smooth change in braking target */

// Static variables for the buffer and index
static int16_t buffer[SAMPLES] = { 0 };
static float buffer[SAMPLES] = { 0 };
static int index = 0;

// Add the new value to the buffer
Expand All @@ -89,10 +89,6 @@ void dti_set_regen(uint16_t current_target)
}
float average = sum / SAMPLES;

if (current_target == 0) {
average = 0;
}

dti_send_brake_current(average);
}

Expand All @@ -119,7 +115,7 @@ void dti_send_brake_current(float brake_current)
.len = 8,
.data = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } };
/* Motor controller expects int value * 10 */
int16_t adjusted_brake_current = brake_current * 10;
uint16_t adjusted_brake_current = (uint16_t)(brake_current * 10);
/* convert to big endian */
endian_swap(&adjusted_brake_current, sizeof(adjusted_brake_current));
/* Send CAN message */
Expand Down
5 changes: 2 additions & 3 deletions Core/Src/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ void vPedalsMonitor(void *pv_params)

uint16_t accel_val = (uint16_t)(accel_val1 + accel_val2) / 2;

is_braking = (adc_data[BRAKEPIN_1] + adc_data[BRAKEPIN_2]) / 2;
is_braking = ((adc_data[BRAKEPIN_1] + adc_data[BRAKEPIN_2]) /
2) > PEDAL_BRAKE_THRESH;
brake_state = is_braking;

osMessageQueuePut(brakelight_signal, &is_braking, 0U, 0U);
Expand Down Expand Up @@ -400,8 +401,6 @@ void vTsmsMonitor(void *pv_params)
for (;;) {
/* If we got a reliable TSMS reading, handle transition to and out of ACTIVE*/
if (!read_tsms_sense(pdu, &tsms_status)) {
printf("Checking pdu");

// Timer has not been started, and there is a change in TSMS, so start the timer
if (tsms != tsms_status &&
!is_timer_active(&tsms_debounce_timer)) {
Expand Down
5 changes: 2 additions & 3 deletions Core/Src/torque.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,11 @@ void handle_endurance(dti_t *mc, float mph, float accel_val, float brake_val)
}

dti_set_torque(torque);
} else if (mph * mph_to_kmh > 2 && accel_val < regen_thresh) {
} else if (mph * mph_to_kmh > 2 && accel_val <= regen_thresh) {
float regen_current =
(max_curr / regen_thresh) * (regen_thresh - accel_val);

/* Send regen current to motor controller */
dti_set_regen((uint16_t)regen_current);
dti_set_regen(regen_current);
} else {
/* Pedal travel is between thresholds, so there should not be acceleration or braking */
dti_set_torque(0);
Expand Down

0 comments on commit 98b427e

Please sign in to comment.