|
|
@@ -128,13 +128,17 @@ void throttle_force_detect(void) {
|
|
|
}
|
|
|
|
|
|
/* 获取转把电压对应的油门开度 */
|
|
|
+#define THRO_CURVE_K (-1.5f)
|
|
|
+
|
|
|
float throttle_vol_to_opening(float thro_val) {
|
|
|
if (thro_val <= throttle_start_vol()) {
|
|
|
return 0;
|
|
|
}
|
|
|
float delta = thro_val - throttle_start_vol();
|
|
|
int ration = (delta * 100.0f) / throttle_vol_range();
|
|
|
- return ((float)ration)/100.0f;
|
|
|
+ float opening = ((float)ration)/100.0f;
|
|
|
+ float curve = throttle_curve(THRO_CURVE_K, opening);
|
|
|
+ return curve;
|
|
|
}
|
|
|
|
|
|
/* 获取油门开度 */
|
|
|
@@ -206,48 +210,6 @@ void throttle_detect(bool ready) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static float _throttle_torque_for_accelerate(float ration) {
|
|
|
- float max_torque = mc_gear_max_torque((s16)_throttle.vel_filted, _throttle.gear);
|
|
|
- float thro_torque = max_torque * ration;
|
|
|
-
|
|
|
- float acc_r = 1.0f;
|
|
|
- if (_throttle.throttle_opening_last < 1.0f) {
|
|
|
- acc_r = (ration - _throttle.throttle_opening_last)/ (1.0f - _throttle.throttle_opening_last);
|
|
|
- }
|
|
|
- acc_r = fclamp(acc_r, 0, 1.0f);
|
|
|
- float acc_torque = _throttle.torque_real + acc_r * (max_torque - _throttle.torque_real);
|
|
|
- if (acc_torque < 0) {
|
|
|
- acc_torque = 0;
|
|
|
- }
|
|
|
- /*
|
|
|
- 直接获取油门开度对应的加速扭矩thro_torque 不小于间接计算得到的 acc_torque
|
|
|
- */
|
|
|
- float torque_acc_ = thro_torque - acc_torque;
|
|
|
- float step = 0.0f;
|
|
|
- if (torque_acc_ > 0) {
|
|
|
- float acc_t = mc_gear_conf()->accl_time;
|
|
|
- step = torque_acc_ / (acc_t + 0.00001f);
|
|
|
- }else {
|
|
|
- torque_acc_ = 0;
|
|
|
- }
|
|
|
- step_towards(&_throttle.torque_acc_, torque_acc_, step);
|
|
|
- return (acc_torque + _throttle.torque_acc_);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-static float throttle_torque_for_accelerate(void) {
|
|
|
- return _throttle_torque_for_accelerate(_throttle.throttle_opening);
|
|
|
-}
|
|
|
-
|
|
|
-static float throttle_torque_for_decelerate(void) {
|
|
|
- if (_throttle.throttle_opening_last == 0.0f) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- float dec_r = _throttle.throttle_opening / _throttle.throttle_opening_last;
|
|
|
- dec_r = fclamp(dec_r, 0.0f, 1.0f);
|
|
|
- return dec_r * _throttle.torque_real;
|
|
|
-}
|
|
|
-
|
|
|
float throttle_get_open_ration_filted(void) {
|
|
|
return _throttle.throttle_opening;
|
|
|
}
|
|
|
@@ -258,37 +220,15 @@ float throttle_get_torque(mot_contrl_t * ctrl, float vol) {
|
|
|
float vel = mot_contrl_get_speed(ctrl);
|
|
|
_throttle.gear = mc_get_internal_gear();
|
|
|
LowPass_Filter(_throttle.vel_filted, vel, THRO_RPM_LP_CEOF);
|
|
|
-
|
|
|
if (throttle_opening > _throttle.throttle_opening) {
|
|
|
- if (!_throttle.accl) {
|
|
|
- _throttle.throttle_opening_last = _throttle.throttle_opening;
|
|
|
- _throttle.torque_real = _throttle.torque_req;
|
|
|
- if (_throttle.torque_real < 0) { //电子刹车的时候,扭矩可能为负
|
|
|
- _throttle.torque_real = 0;
|
|
|
- }
|
|
|
- _throttle.torque_acc_ = 0;
|
|
|
- }
|
|
|
_throttle.accl = true;
|
|
|
}else if (throttle_opening < _throttle.throttle_opening) {
|
|
|
- if (_throttle.accl) {
|
|
|
- _throttle.throttle_opening_last = _throttle.throttle_opening;
|
|
|
- _throttle.torque_real = ctrl->target_torque_raw;
|
|
|
- /* 如果扭矩给定的ramp没有结束,使用原始扭矩请求作为减扭矩的起始点 */
|
|
|
- if (_throttle.torque_req - line_ramp_get_interp(&ctrl->ramp_input_torque) >= 10.0f ) {
|
|
|
- _throttle.torque_real = _throttle.torque_req;
|
|
|
- }
|
|
|
- if (_throttle.torque_real < 0) { //电子刹车的时候,扭矩可能为负
|
|
|
- _throttle.torque_real = 0;
|
|
|
- }
|
|
|
- }
|
|
|
_throttle.accl = false;
|
|
|
}
|
|
|
_throttle.throttle_opening = throttle_opening;
|
|
|
- if (_throttle.accl) {
|
|
|
- return throttle_torque_for_accelerate();
|
|
|
- }else {
|
|
|
- return throttle_torque_for_decelerate();
|
|
|
- }
|
|
|
+
|
|
|
+ float max_torque = mc_gear_max_torque((s16)_throttle.vel_filted, _throttle.gear);
|
|
|
+ return max_torque * throttle_opening;
|
|
|
}
|
|
|
|
|
|
void throttle_set_torque(mot_contrl_t * ctrl, float torque) {
|
|
|
@@ -329,7 +269,6 @@ void throttle_set_torque(mot_contrl_t * ctrl, float torque) {
|
|
|
}
|
|
|
_throttle.torque_req = ref_torque;
|
|
|
}else {
|
|
|
- float ref_torque = throttle_torque_for_decelerate();
|
|
|
/* autohold 启动的情况下,转把在0位置附近小幅抖动 */
|
|
|
if (curr_vel <= CONFIG_ZERO_SPEED_RPM) {
|
|
|
float hold_torque = ctrl->autohold_torque;
|
|
|
@@ -342,10 +281,8 @@ void throttle_set_torque(mot_contrl_t * ctrl, float torque) {
|
|
|
|
|
|
/* 定速巡航需要判断是否需要加速 */
|
|
|
float get_user_request_torque(void) {
|
|
|
- if (_throttle.accl) {
|
|
|
- return throttle_torque_for_accelerate();
|
|
|
- }
|
|
|
- return throttle_torque_for_decelerate();
|
|
|
+ float max_torque = mc_gear_max_torque((s16)_throttle.vel_filted, _throttle.gear);
|
|
|
+ return max_torque * _throttle.throttle_opening;
|
|
|
}
|
|
|
|
|
|
|