Skip to content

Commit

Permalink
Found major erros with prev Accel pedal merger (pedal was unresponsiv… (
Browse files Browse the repository at this point in the history
#1071)

Same as PR #1037 just found error where I was passing in unpressed
voltage when I should have been passing in unpressed length
  • Loading branch information
shayana18 authored Nov 5, 2023
1 parent 603b1a4 commit 56a4449
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions firmware/thruna/FSM/Src/Io/Io_AcceleratorPedals.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
// min pot voltage is 0

// Raw voltage seen at the pin (used to calculate rest and max PAPPS/SAPPS length)
#define PAPPS_FULL_PRESSED_POT_V (2.55f)
#define PAPPS_UNPRESSED_POT_V (0.87f)
#define PAPPS_FULL_PRESSED_POT_V (2.57f)
#define PAPPS_UNPRESSED_POT_V (0.86f)

#define SAPPS_FULL_PRESSED_POT_V (3.05f)
#define SAPPS_UNPRESSED_POT_V (1.39f)
#define SAPPS_FULL_PRESSED_POT_V (3.08f)
#define SAPPS_UNPRESSED_POT_V (1.38f)

// Denominator term for angle calculation using the cosine law
#define PAPPS_COS_LAW_DENOMINATOR (2.0f * PAPPS_LEN_A * LEN_B)
Expand Down Expand Up @@ -58,22 +58,24 @@ static float sapps_rest_angle;
static float sapps_max_angle;

// max and min angle calculation for PAPPS/SAPPS
static float calcAppsAngle(float cos_law_coefficent, float cos_law_denominator, float pot_len)
static float calcAppsAngle(float cos_law_coefficent, float pot_len, float cos_law_denominator)
{
float angle = (acosf(cos_law_coefficent - (powf(pot_len, 2) / cos_law_denominator)));
float angle = acosf(cos_law_coefficent - (powf(pot_len, 2) / cos_law_denominator));

return angle;
}

void Io_AcceleratorPedals_Init(void)
{
papps_rest_angle = calcAppsAngle(PAPPS_COS_LAW_COEFFICIENT, PAPPS_COS_LAW_DENOMINATOR, PAPPS_UNPRESSED_POT_V);
papps_max_angle = papps_rest_angle -
calcAppsAngle(PAPPS_COS_LAW_COEFFICIENT, PAPPS_COS_LAW_DENOMINATOR, PAPPS_FULL_PRESSED_POT_V);

sapps_rest_angle = calcAppsAngle(SAPPS_COS_LAW_COEFFICIENT, SAPPS_COS_LAW_DENOMINATOR, SAPPS_UNPRESSED_POT_V);
sapps_max_angle = sapps_rest_angle -
calcAppsAngle(SAPPS_COS_LAW_COEFFICIENT, SAPPS_COS_LAW_DENOMINATOR, SAPPS_FULL_PRESSED_POT_V);
papps_rest_angle = calcAppsAngle(PAPPS_COS_LAW_COEFFICIENT, PAPPS_LENGTH_UNPRESSED_MM, PAPPS_COS_LAW_DENOMINATOR);
papps_max_angle =
papps_rest_angle -
calcAppsAngle(PAPPS_COS_LAW_COEFFICIENT, PAPPS_LENGTH_FULLY_PRESSED_MM, PAPPS_COS_LAW_DENOMINATOR);

sapps_rest_angle = calcAppsAngle(SAPPS_COS_LAW_COEFFICIENT, SAPPS_LENGTH_UNPRESSED_MM, SAPPS_COS_LAW_DENOMINATOR);
sapps_max_angle =
sapps_rest_angle -
calcAppsAngle(SAPPS_COS_LAW_COEFFICIENT, SAPPS_LENGTH_FULLY_PRESSED_MM, SAPPS_COS_LAW_DENOMINATOR);
}

float Io_AcceleratorPedals_GetPapps(void)
Expand All @@ -84,7 +86,7 @@ float Io_AcceleratorPedals_GetPapps(void)
const float pot_len_mm = RAW_VOLTAGE_TO_LEN_MM(pedal_voltage);

float pedal_angle =
papps_rest_angle - calcAppsAngle(PAPPS_COS_LAW_COEFFICIENT, PAPPS_COS_LAW_DENOMINATOR, pot_len_mm);
papps_rest_angle - calcAppsAngle(PAPPS_COS_LAW_COEFFICIENT, pot_len_mm, PAPPS_COS_LAW_DENOMINATOR);

float pedal_percentage_raw = (pedal_angle / papps_max_angle) * 100.0f;

Expand Down Expand Up @@ -112,8 +114,10 @@ float Io_AcceleratorPedals_GetSapps(void)
// length calc from SAPPS voltage reading
const float pot_len_mm = RAW_VOLTAGE_TO_LEN_MM(pedal_voltage);

float pedal_angle_raw = calcAppsAngle(SAPPS_COS_LAW_COEFFICIENT, pot_len_mm, SAPPS_COS_LAW_DENOMINATOR);

float pedal_angle =
sapps_rest_angle - calcAppsAngle(SAPPS_COS_LAW_COEFFICIENT, SAPPS_COS_LAW_DENOMINATOR, pot_len_mm);
sapps_rest_angle - calcAppsAngle(SAPPS_COS_LAW_COEFFICIENT, pot_len_mm, SAPPS_COS_LAW_DENOMINATOR);

float pedal_percentage_raw = (pedal_angle / sapps_max_angle) * 100.0f;

Expand Down

0 comments on commit 56a4449

Please sign in to comment.