Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pedal to torque #254

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Core/Inc/dti.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
0x496 /* Throttle signal, Brake signal, IO, Drive enable */

#define TIRE_DIAMETER 16 /* inches */
#define GEAR_RATIO 47 / 13.0 /* unitless */
#define GEAR_RATIO 35 / 13.0 /* unitless */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where did you find this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I messaged Abby directly

#define POLE_PAIRS 10 /* unitless */

typedef struct {
Expand Down
2 changes: 1 addition & 1 deletion Core/Inc/emrax.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define EMRAX_NOMINAL_VOLTAGE 520 /* V */
#define EMRAX_PEAK_EFFICIENCY 90 /* % */
#define EMRAX_PEAK_POWER 124 /* kW, at 5500 RPM */
#define EMRAX_PEAK_TORQUE 230 /* Nm */
#define EMRAX_PEAK_TORQUE 220 /* Nm */
#define EMRAX_CONT_TORQUE 112 /* Nm */
#define EMRAX_LIMITING_SPEED 6500 /* RPM */
#define EMRAX_KV 15.53
Expand Down
29 changes: 28 additions & 1 deletion Core/Src/pedals.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ float torque_limit_percentage = 1.0;
#define PEDAL_DIFF_THRESH 30
#define PEDAL_FAULT_TIME 500 /* ms */

/* Alterante pedal mode */
//#define POWER_REGRESSION_PEDAL_TORQUE_TRANSFER

static bool brake_state = false;
osMutexId_t brake_mutex;

Expand Down Expand Up @@ -216,6 +219,7 @@ bool calc_bspd_prefault(float accel_val, float brake_val)
return motor_disabled;
}

#ifndef POWER_REGRESSION_PEDAL_TORQUE_TRANSFER
caiodasilva2005 marked this conversation as resolved.
Show resolved Hide resolved
static void linear_accel_to_torque(float accel)
{
/* Sometimes, the pedal travel jumps to 1% even if it is not pressed. */
Expand All @@ -228,6 +232,21 @@ static void linear_accel_to_torque(float accel)
dti_set_torque(torque);
}

#else
static void power_regression_accel_to_torque(float accel)
{
/* Sometimes, the pedal travel jumps to 1% even if it is not pressed. */
if (fabs(accel - 0.01) < 0.001) {
accel = 0;
}
/* map acceleration to torque */
int16_t torque =
(int16_t)(0.137609 * powf(accel, 1.43068) * MAX_TORQUE);
caiodasilva2005 marked this conversation as resolved.
Show resolved Hide resolved

dti_set_torque(torque);
}
#endif

/**
* @brief Derate torque target to keep car below the maximum pit/reverse mode speed.
*
Expand Down Expand Up @@ -371,8 +390,12 @@ void handle_endurance(dti_t *mc, float mph, float accel_val, float brake_val)
if (brake_val > 650 && (mph * 1.609) > 5) {
brake_pedal_regen(brake_val);
} else {
// accelerating, limit torque
// accelerating, limit torque
#ifndef POWER_REGRESSION_PEDAL_TORQUE_TRANSFER
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want this for brake regen, just for linear accel -> torque

linear_accel_to_torque(accel_val, torque);
#else
power_regression_accel_to_torque(accel_val, torque);
#endif
}
#else
/* Factor for converting MPH to KMH */
Expand Down Expand Up @@ -459,7 +482,11 @@ void vProcessPedals(void *pv_params)
handle_endurance(mc, mph, accelerator_value, brake_val);
break;
case F_PERFORMANCE:
#ifndef POWER_REGRESSION_PEDAL_TORQUE_TRANSFER
linear_accel_to_torque(accelerator_value);
#else
power_regression_accel_to_torque(accelerator_value);
#endif
break;
case F_PIT:
handle_pit(mph, accelerator_value);
Expand Down
Loading