Просмотр исходного кода

throttle_vol_to_open_ration 参数应该是float类型

Signed-off-by: unknown <huhui@sharkgulf.com>
unknown 2 лет назад
Родитель
Сommit
4383dbf729

+ 2 - 2
Applications/app/app.c

@@ -33,7 +33,7 @@ extern void PMSM_FOC_LogDebug(void);
 extern void mc_err_code_log(void);
 extern void encoder_log(void);
 extern void sample_log(void);
-extern void thro_torque_log(void);
+extern void throttle_log(void);
 extern bool can_is_connect_pc(void);
 extern measure_time_t g_meas_hall;
 extern measure_time_t g_meas_foc;
@@ -66,7 +66,7 @@ static void app_print_log(void) {
 	encoder_log();
 	//motor_debug();
 	sample_log();
-	//PMSM_FOC_LogDebug();
+	throttle_log();
 	//F_debug();
 	//eCtrl_debug_log();
 	//sys_debug("enc err %d, %d\n", foc_observer_enc_errcount(), foc_observer_sensorless_stable());

+ 1 - 0
Applications/foc/commands.c

@@ -405,6 +405,7 @@ static void process_foc_command(foc_cmd_body_t *command) {
 			if (command->len >= 2) {
 				bool use = decode_u8(command->data)==0?false:true;
 				u8 r = decode_u8((u8 *)command->data + 1);
+				sys_debug("set thro %d, r: %d\n", use, r);
 				mc_set_throttle_r(use, r);
 			}
 			break;

+ 11 - 5
Applications/foc/motor/throttle.c

@@ -20,7 +20,6 @@ static throttle_torque_t _throttle;
 
 void throttle_torque_reset(void) {
 	_throttle.accl = false;
-	_throttle.thro_filted = 0.0f;
 	_throttle.thro_ration = _throttle.thro_ration_last = 0.0f;
 	_throttle.torque_req = _throttle.torque_real = _throttle.torque_acc_ = 0.0f;
 	_throttle.gear = mc_get_internal_gear();
@@ -127,7 +126,7 @@ void throttle_force_detect(void) {
 }
 
 /* 获取转把电压对应的油门开度 */
-float throttle_vol_to_open_ration(int thro_val) {
+float throttle_vol_to_open_ration(float thro_val) {
 	if (thro_val <= throttle_start_vol()) {
 		return 0;
 	}
@@ -146,9 +145,10 @@ float throttle_get_open_ration(void) {
 float throttle_open_ration_to_vol(float r) {
 	if (r == 0) {
 		return 0;
+	}else if (r > 1.0f) {
+		r = 1.0f;
 	}
-	float vol = throttle_start_vol() + r * throttle_vol_range();
-	return fclamp(vol, 0, throttle_end_vol());
+	return (throttle_start_vol() + r * throttle_vol_range());
 }
 
 
@@ -253,8 +253,9 @@ float throttle_get_open_ration_filted(void) {
 #define THRO_RPM_LP_CEOF 0.01f
 float throttle_get_torque(mot_contrl_t * ctrl, float vol) {
 	float thro_r = throttle_vol_to_open_ration(vol);
+	float vel = mot_contrl_get_speed(ctrl);
 	_throttle.gear = mc_get_internal_gear();
-	LowPass_Filter(_throttle.vel_filted, mot_contrl_get_speed(ctrl), THRO_RPM_LP_CEOF);
+	LowPass_Filter(_throttle.vel_filted, vel, THRO_RPM_LP_CEOF);
 
 	if (thro_r > _throttle.thro_ration) {
 		if (!_throttle.accl) {
@@ -345,3 +346,8 @@ float get_user_request_torque(void) {
 	return throttle_torque_for_decelerate();
 }
 
+
+void throttle_log(void) {
+	sys_debug("r:%f, last %f, real:%f, req %f\n", _throttle.thro_ration, _throttle.thro_ration_last, _throttle.torque_real, _throttle.torque_req);
+	sys_debug("thro: %f-%f\n", throttle_start_vol(), throttle_end_vol());
+}

+ 1 - 2
Applications/foc/motor/throttle.h

@@ -11,7 +11,6 @@ typedef struct {
 	float torque_req;
 	float torque_real;
 	float torque_acc_;
-	float thro_filted;
 	float vel_filted;
 	float thro_ration;
 	float thro_ration_last;
@@ -35,7 +34,7 @@ float throttle_get_torque(mot_contrl_t * ctrl, float vol);
 float throttle_get_open_ration_filted(void);
 float get_user_request_torque(void);
 float throttle_open_ration_to_vol(float r);
-float throttle_vol_to_open_ration(int thro_val);
+float throttle_vol_to_open_ration(float thro_val);
 void throttle_torque_reset(void);
 #endif /* _THROTTLE_H__ */