|
@@ -274,28 +274,19 @@ float mc_gear_max_torque(s16 vel, u8 gear_n) {
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (vel > gear->max_speed) {
|
|
|
|
|
- vel = gear->max_speed;
|
|
|
|
|
- }
|
|
|
|
|
vel = ABS(vel);
|
|
vel = ABS(vel);
|
|
|
if (vel <= 1000) {
|
|
if (vel <= 1000) {
|
|
|
return gear_rpm_2_torque(gear->torque[0], gear->max_torque);
|
|
return gear_rpm_2_torque(gear->torque[0], gear->max_torque);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- for (int i = 1; i < CONFIG_GEAR_SPEED_TRQ_NUM; i++) {
|
|
|
|
|
- if (vel <= 1000 * (i + 1)) { //线性插值
|
|
|
|
|
- float trq1 = gear_rpm_2_torque(gear->torque[i-1], gear->max_torque);
|
|
|
|
|
- float min_rpm = (i * 1000);
|
|
|
|
|
- float trq2 = gear_rpm_2_torque(gear->torque[i], gear->max_torque);
|
|
|
|
|
- float max_rpm = (i + 1) * 1000;
|
|
|
|
|
- if (trq1 > trq2) {
|
|
|
|
|
- return f_map_inv((float)vel, min_rpm, max_rpm, trq2, trq1);
|
|
|
|
|
- }else {
|
|
|
|
|
- return f_map((float)vel, min_rpm, max_rpm, trq1, trq2);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ int vel_idx = vel / 1000;
|
|
|
|
|
+ if (vel >= CONFIG_GEAR_SPEED_TRQ_NUM -1 ) {
|
|
|
|
|
+ return gear_rpm_2_torque(gear->torque[CONFIG_GEAR_SPEED_TRQ_NUM-1], gear->max_torque);
|
|
|
}
|
|
}
|
|
|
- return gear_rpm_2_torque(gear->torque[CONFIG_GEAR_SPEED_TRQ_NUM-1], gear->max_torque);
|
|
|
|
|
|
|
+ float torque_1 = gear_rpm_2_torque(gear->torque[vel_idx-1], gear->max_torque);
|
|
|
|
|
+ float min_rpm = vel_idx * 1000;
|
|
|
|
|
+ float torque_2 = gear_rpm_2_torque(gear->torque[vel_idx], gear->max_torque);
|
|
|
|
|
+ float max_rpm = min_rpm + 1000;
|
|
|
|
|
+ return f_map((float)vel, min_rpm, max_rpm, torque_1, torque_2);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|