Skip to content

Instantly share code, notes, and snippets.

@celeron55
Created November 14, 2018 21:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save celeron55/8dd226b8993e3d244787e11a623e483a to your computer and use it in GitHub Desktop.
Save celeron55/8dd226b8993e3d244787e11a623e483a to your computer and use it in GitHub Desktop.
void update_bms_discharge_motor_torque_req_limit()
{
// Limit torque request according to bms_status.max_discharge_current_Ax10
if(bms_status.max_discharge_current_Ax10 < 2000){
// Calculate rough motor current limit based on motor speed, rail
// voltage and rail current limit
float speed_rpm = abs(inverter_status.speed / INVERTER_BITS_PER_RPM);
float rail_voltage = inverter_status.voltage / INVERTER_BITS_PER_VOLT;
float rail_current_per_motor_current = speed_rpm / 3000.0f;
float rail_current_limit = (float)bms_status.max_discharge_current_Ax10 / 10.0f;
if(rail_current_per_motor_current < 0.1)
rail_current_per_motor_current = 0.1;
float motor_current_limit = rail_current_limit / rail_current_per_motor_current;
if(motor_current_limit < MOTOR_A_AT_MAX_TORQUE_REQUEST)
bms_discharge_motor_torque_req_limit = motor_current_limit / MOTOR_A_PER_TORQUE_REQUEST;
else
bms_discharge_motor_torque_req_limit = MAX_TORQUE_REQUEST;
} else {
bms_discharge_motor_torque_req_limit = MAX_TORQUE_REQUEST;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment