Explorar el Código

更新最小二乘

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui hace 5 años
padre
commit
9bad437c3e
Se han modificado 1 ficheros con 7 adiciones y 7 borrados
  1. 7 7
      Application/app/sox/soc.c

+ 7 - 7
Application/app/sox/soc.c

@@ -32,7 +32,7 @@ static least_square_t discharger_capacity_coef;
 static shark_timer_t least_square_timer = {.handler = _least_square_timer_handler};
 static int least_square_time = 0;
 static int least_square_started = 0;
-#define LEAST_SQUARE_STEP_TIME 1000
+#define LEAST_SQUARE_STEP_TIME 1000 * 5
 #endif
 void soc_init(void){
 	set_log_level(MOD_SOC, L_debug);
@@ -59,9 +59,9 @@ void soc_init(void){
 #if LEAST_SQUARE==1
 static void start_least_square(int start){
 	if (start && !least_square_started) {
-		least_square_init(&discharger_vol_coef, 100);
-		least_square_init(&discharger_cell_coef, 100);
-		least_square_init(&discharger_capacity_coef, 100);
+		least_square_init(&discharger_vol_coef, 10);
+		least_square_init(&discharger_cell_coef, 10);
+		least_square_init(&discharger_capacity_coef, 10);
 		least_square_time = 0;
 		least_square_started = 1;
 		shark_timer_post(&least_square_timer, LEAST_SQUARE_STEP_TIME);
@@ -75,17 +75,17 @@ static void start_least_square(int start){
 static void _least_square_timer_handler(shark_timer_t *timer){
 	if (least_square_put(&discharger_vol_coef, least_square_time, bms_state_get()->pack_voltage/1000.0f) == 1) {
 		soc_error("voltage: A = %f, B = %f, v: %f\n", discharger_vol_coef.Cb, discharger_vol_coef.Ka, get_y_by_x(&discharger_vol_coef, least_square_time));
-		int delta = get_x_by_y(&discharger_vol_coef, bms_state_get()->pack_voltage/1000.0f) - get_x_by_y(&discharger_vol_coef, bms_health_pack_lower_voltage()/1000.0f);
+		int delta = get_x_by_y(&discharger_vol_coef, bms_health_pack_lower_voltage()/1000.0f) - get_x_by_y(&discharger_vol_coef, bms_state_get()->pack_voltage/1000.0f);
 		soc_error("remain %d s to reach lower pack voltage\n", delta);
 	}
 	if (least_square_put(&discharger_cell_coef, least_square_time, bms_state_get()->cell_min_vol/1000.0f) == 1) {
 		soc_error("cell: A = %f, B = %f, v: %f\n", discharger_cell_coef.Cb, discharger_cell_coef.Ka, get_y_by_x(&discharger_cell_coef, least_square_time));
-		int delta = get_x_by_y(&discharger_cell_coef, bms_state_get()->cell_min_vol/1000.0f) - get_x_by_y(&discharger_cell_coef, bms_health_cell_lower_voltage()/1000.0f);
+		int delta = get_x_by_y(&discharger_cell_coef, bms_health_cell_lower_voltage()/1000.0f) - get_x_by_y(&discharger_cell_coef, bms_state_get()->cell_min_vol/1000.0f);
 		soc_error("remain %d s to reach lower cell voltage\n", delta);
 	}
 	if (least_square_put(&discharger_capacity_coef, least_square_time, _soc.coulomb_now/3600.0f) == 1) {
 		soc_error("capacity: A = %f, B = %f, c: %f\n", discharger_capacity_coef.Cb, discharger_capacity_coef.Ka, get_y_by_x(&discharger_capacity_coef, least_square_time));
-		int delta = get_x_by_y(&discharger_capacity_coef, _soc.coulomb_now/3600.0f) - get_x_by_y(&discharger_capacity_coef, _soc.coulomb_min/3600.0f);
+		int delta = get_x_by_y(&discharger_capacity_coef, _soc.coulomb_min/3600.0f) - get_x_by_y(&discharger_capacity_coef, _soc.coulomb_now/3600.0f);
 		soc_error("remain %d s to reach 0 min AH\n", delta);
 	}
 	least_square_time ++;