Browse Source

定速巡航考虑加减速后的转把加速

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 3 năm trước cách đây
mục cha
commit
be5c550de0

+ 1 - 4
Applications/foc/commands.c

@@ -202,10 +202,7 @@ static void process_foc_command(foc_cmd_body_t *command) {
 		{
 			u8 mode = decode_u8(command->data);
 			float rpm = (float)decode_s16((u8 *)command->data + 1);
-			if (mode == 0) {
-				rpm = PMSM_FOC_GetSpeed() + rpm;	
-			}
-			if (!PMSM_FOC_Set_CruiseSpeed(rpm)) {
+			if (!mc_set_cruise_speed(mode?true:false, rpm)) {
 				erroCode = PMSM_FOC_GetErrCode();
 			}
 			sys_debug("Cruise RPM %d\n", (int)rpm);

+ 14 - 0
Applications/foc/motor/motor.c

@@ -350,6 +350,20 @@ bool mc_is_cruise_enabled(void) {
 	return motor.b_cruise;
 }
 
+bool mc_set_cruise_speed(bool rpm_abs, float target_rpm) {
+	bool ret;
+	if (rpm_abs) {
+		ret = PMSM_FOC_Set_CruiseSpeed(target_rpm);
+	}else {
+		ret = PMSM_FOC_Set_CruiseSpeed(PMSM_FOC_GetSpeed() + target_rpm);
+	}
+	if (ret) {
+		motor.cruise_time = shark_get_seconds();
+		motor.cruise_torque = 0.0f;
+	}
+	return ret;
+}
+
 bool mc_set_foc_mode(u8 mode) {
 	if (mode == motor.mode) {
 		return true;

+ 1 - 0
Applications/foc/motor/motor.h

@@ -77,6 +77,7 @@ void mc_force_run_open(s16 vd, s16 vq);
 u16 mc_get_running_status2(void);
 bool mc_enable_cruise(bool enable);
 bool mc_is_cruise_enabled(void);
+bool mc_set_cruise_speed(bool rpm_abs, float target_rpm);
 
 static __INLINE float motor_encoder_get_angle(void) {
 #ifdef USE_ENCODER_HALL