Skip to content

Commit

Permalink
override tsms, ccl fixed, adjusting torque and regen calcs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabramz committed Jul 24, 2024
1 parent e85f348 commit ebf234f
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 13 deletions.
2 changes: 0 additions & 2 deletions Core/Src/dti.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ void dti_set_current(int16_t current)

//endian_swap(&current, sizeof(current));
//memcpy(msg.data, &current, msg.len);
serial_print("current: %d\r\n", current);

int8_t msb = (int8_t)((current >> 8) & 0xFF);
int8_t lsb = (uint8_t)(current & 0xFF);

Expand Down
2 changes: 1 addition & 1 deletion Core/Src/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ void vSteeringIOButtonsMonitor(void* pv_params)

bool get_tsms()
{
return tsms;
return true;
}

osThreadId brakelight_monitor_handle;
Expand Down
1 change: 0 additions & 1 deletion Core/Src/state_machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ int queue_state_transition(state_req_t new_state)
if (!get_brake_state()) {
return 0;
}
serial_print("CALLING RTDS");
sound_rtds(pdu);
}

Expand Down
2 changes: 0 additions & 2 deletions Core/Src/steeringio.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ static void debounce_cb(void* arg)
steeringio_t *wheel = args->wheel;

if (wheel->raw_buttons[button]) {
serial_print("%d index pressed \r\n",button);
switch (button) {
case STEERING_PADDLE_LEFT:
paddle_left_cb();
Expand Down Expand Up @@ -183,7 +182,6 @@ void vSteeringIORouter(void* pv_params)
/* Wait until new CAN message comes into queue */
status = osMessageQueueGet(steeringio_router_queue, &message, NULL, osWaitForever);
if (status == osOK){
printf("joe mama");\
steeringio_update(wheel, message.data);
}
}
Expand Down
13 changes: 6 additions & 7 deletions Core/Src/torque.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ void decrease_torque_limit()
*/
void handle_endurance(dti_t* mc, float mph, float accel_val, float brake_val, int16_t* torque) {
// max ac current to brake with
static const float max_ac_brake = 25; // Amps AC
/* Maximum AC braking current */
static const int8_t max_curr = -25;
#ifdef USE_BRAKE_REGEN
// The brake travel ADC value at which we want maximum regen
static const float travel_scaling_max = 1000;
Expand Down Expand Up @@ -142,16 +143,15 @@ void handle_endurance(dti_t* mc, float mph, float accel_val, float brake_val, in

// if the rescaled accel is positive then convert it to torque, and full send
if (accel_val >= accel_thresh) {
/* Coefficient to map accel pedal travel % to the max torque */
const float coeff = MAX_TORQUE / (1 - accel_thresh);
/* Makes acceleration pedal more sensitive since domain is compressed but range is the same */
const float adj_accel = (accel_val - (accel_thresh)) * (1.0 / (1.0 - accel_thresh));
*torque = adj_accel * MAX_TORQUE;
*torque = coeff * accel_val - (accel_val * accel_thresh);
dti_set_regen(0);
}
else if (mph * mph_to_kmh > 5 && accel_val < regen_thresh) {

/* Adjust accel pedal to be from 0 -> regen threshold. */
const float adj_accel = regen_thresh - accel_val;
float regen_current = adj_accel * (max_ac_brake / regen_thresh);
float regen_current = (max_curr / regen_thresh) * (regen_thresh - accel_val);

/* Send regen current to motor controller */
dti_set_regen(regen_current);
Expand Down Expand Up @@ -251,7 +251,6 @@ void vCalcTorque(void* pv_params)

// serial_print("accel val: %d\r\n", pedal_data.accelerator_value);

serial_print("torque: %d\r\n", torque);
/* Send whatever torque command we have on record */
dti_set_torque(torque);
}
Expand Down

0 comments on commit ebf234f

Please sign in to comment.