Skip to content

Commit

Permalink
acceleration is steps of 1% travel
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabramz committed Jul 26, 2024
1 parent 26cddc4 commit 8e40340
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Core/Src/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ void vPedalsMonitor(void* pv_params)
uint16_t brake2_adj = adjust_pedal_val(adc_data[BRAKEPIN_2], BRAKE2_OFFSET, BRAKE2_MAX_VAL);

/* Low Pass Filter */
sensor_data.accelerator_value = (sensor_data.accelerator_value + (accel_val)) / num_samples;
sensor_data.accelerator_value = (sensor_data.accelerator_value + (accel_val)) / 2;
sensor_data.brake_value = (sensor_data.brake_value + (brake1_adj + brake2_adj) / 2) / num_samples;

/* Publish to Onboard Pedals Queue */
Expand Down
14 changes: 9 additions & 5 deletions Core/Src/torque.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,9 @@ void handle_endurance(dti_t* mc, float mph, float accel_val, float brake_val, in
}
#else
// percent of accel pedal to be used for regen
static const float regen_thresh = 0.2;
static const float accel_thresh = 0.25;
static const float regen_thresh = 0.01;
static const float accel_thresh = 0.05;
// static const float mph_to_kmh = 1.609;
// serial_print("%i\n", (int) (accel_val < regen_thresh));
// 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 */
Expand All @@ -149,7 +148,8 @@ void handle_endurance(dti_t* mc, float mph, float accel_val, float brake_val, in
*torque = coeff * accel_val - (accel_val * accel_thresh);
dti_set_regen(0);
}
else if (accel_val < regen_thresh) {
else if (//mph * mph_to_kmh > 5 &&
accel_val < regen_thresh) {

float regen_current = (max_curr / regen_thresh) * (regen_thresh - accel_val);

Expand All @@ -162,6 +162,10 @@ void handle_endurance(dti_t* mc, float mph, float accel_val, float brake_val, in
*torque = 0;
dti_set_regen(0);
}

if (*torque > MAX_TORQUE) {
*torque = MAX_TORQUE;
}

#endif
}
Expand All @@ -182,7 +186,7 @@ void vCalcTorque(void* pv_params)
for (;;) {
stat = osMessageQueueGet(pedal_data_queue, &pedal_data, 0U, delay_time);

float accelerator_value = (float) pedal_data.accelerator_value / 10.0; // 0 to 1
float accelerator_value = (float) pedal_data.accelerator_value / 100.0; // 0 to 1
float brake_value = (float) pedal_data.brake_value * 10.0; // ACTUAL PSI

/* If we receive a new message within the time frame, calc new torque */
Expand Down

0 comments on commit 8e40340

Please sign in to comment.