소스 검색

设置和查询挡位信息

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 3 년 전
부모
커밋
0eaca20590
4개의 변경된 파일71개의 추가작업 그리고 11개의 파일을 삭제
  1. 39 0
      Applications/app/nv_storage.c
  2. 3 0
      Applications/app/nv_storage.h
  3. 28 11
      Applications/foc/commands.c
  4. 1 0
      Applications/foc/commands.h

+ 39 - 0
Applications/app/nv_storage.c

@@ -240,6 +240,45 @@ void nv_read_gear_configs(void) {
 	}
 }
 
+bool nv_set_gear_config(u8 mode4896, u8 gear, u16 rpm, u16 torque, u16 idc, u16 acc) {
+	mc_gear_t *gear_cfg;
+	if (gear >= CONFIG_MAX_GEAR_NUM) {
+		return false;
+	}
+
+	if (mode4896 == 0) { //48vmode
+		gear_cfg = &gear_config.gears_48[gear];
+	}else {
+		gear_cfg = &gear_config.gears_96[gear];
+	}
+	gear_cfg->u_maxRPM = rpm;
+	gear_cfg->u_maxTorque = torque;
+	gear_cfg->u_maxIdc = idc;
+	gear_cfg->u_accTime = acc;
+
+	nv_save_gear_configs();
+	return true;
+}
+
+bool nv_get_gear_config(u8 mode4896, u8 gear, u16 *rpm, u16 *torque, u16 *idc, u16 *acc) {
+	mc_gear_t *gear_cfg;
+	if (gear >= CONFIG_MAX_GEAR_NUM) {
+		return false;
+	}
+
+	if (mode4896 == 0) { //48vmode
+		gear_cfg = &gear_config.gears_48[gear];
+	}else {
+		gear_cfg = &gear_config.gears_96[gear];
+	}
+	*rpm = gear_cfg->u_maxRPM;
+	*torque = gear_cfg->u_maxTorque;
+	*idc = gear_cfg->u_maxIdc;
+	*acc = gear_cfg->u_accTime;
+
+	return true;
+}
+
 
 void nv_set_pid(u8 id, pid_conf_t *pid) {
 	foc_params.pid_conf[id] = *pid;

+ 3 - 0
Applications/app/nv_storage.h

@@ -100,6 +100,9 @@ void nv_get_pid(u8 id, pid_conf_t *pid);
 void nv_set_hwbrake_mode(u8 mode);
 void nv_set_throttle_vol(float min, float max);
 void nv_set_ebrake_current(float phase_curr, float dc_curr);
+bool nv_set_gear_config(u8 mode4896, u8 gear, u16 rpm, u16 torque, u16 idc, u16 acc);
+bool nv_get_gear_config(u8 mode4896, u8 gear, u16 *rpm, u16 *torque, u16 *idc, u16 *acc);
+
 torque_lut_t *nv_get_trq_tlb(void);
 
 #endif /* _NV_Storage_H__ */

+ 28 - 11
Applications/foc/commands.c

@@ -177,19 +177,36 @@ static void process_foc_command(foc_cmd_body_t *command) {
 		}
 		case Foc_Set_Gear_Limit:
 		{
-			if (command->len < 5) {
+			if (command->len < 7) {
 				erroCode = FOC_Param_Err;
 			}else {
-				u16 maxRPM = decode_u16(command->data);
-				u16 maxPhaseCurr = decode_u8((u8 *)command->data + 2);
-				u8  maxiDC = decode_u8((u8 *)command->data + 4);
-				PMSM_FOC_SpeedLimit((float)maxRPM);
-				PMSM_FOC_PhaseCurrLim((float)maxPhaseCurr);
-				PMSM_FOC_DCCurrLimit((float)maxiDC);
-				encode_u16(response + 3, (u16)PMSM_FOC_GetSpeedLimit());
-				encode_u16(response + 5, (u16)PMSM_FOC_GetPhaseCurrLim());
-				encode_u8(response + 7, (u8)PMSM_FOC_GetDCCurrLimit());
-				len += 5;
+				u8  gear = decode_u8(command->data);
+				u16 maxRPM = decode_u16((u8 *)command->data + 1);
+				u16 maxPhaseCurr = decode_u8((u8 *)command->data + 3);
+				u16 maxiDC = decode_u8((u8 *)command->data + 5);
+				u16 accline = decode_u8((u8 *)command->data + 7);
+				if (!nv_set_gear_config((gear>>4 & 0xF), (gear & 0xF), maxRPM, maxPhaseCurr, maxiDC, accline)){
+					erroCode = FOC_Param_Err;
+				}
+			}
+			break;
+		}
+		case Foc_Get_Gear_Limit:
+		{
+			u8  gear = decode_u8(command->data);
+			u16 maxRPM;
+			u16 maxPhaseCurr;
+			u16 maxiDC;
+			u16 accline;
+			if (!nv_get_gear_config((gear>>4 & 0xF), (gear & 0xF), &maxRPM, &maxPhaseCurr, &maxiDC, &accline)){
+				erroCode = FOC_Param_Err;
+			}else {
+				encode_u8(response + 3, gear);
+				encode_u8(response + 4, maxRPM);
+				encode_u8(response + 6, maxPhaseCurr);
+				encode_u8(response + 8, maxiDC);
+				encode_u8(response + 10, accline);
+				len += 9;
 			}
 			break;
 		}

+ 1 - 0
Applications/foc/commands.h

@@ -30,6 +30,7 @@ typedef enum {
 	Foc_Get_Config,
 	Foc_Get_Pid,
 	Foc_Fan_Duty, //57
+	Foc_Get_Gear_Limit,
 	Foc_Hall_Phase_Cali_Result = 160,
 	Foc_Hall_Offset_Cali_Result,
 	Foc_Report_Speed,