|
@@ -1,6 +1,7 @@
|
|
|
import pandas as pd
|
|
|
import numpy as np
|
|
|
import matplotlib.pyplot as plt
|
|
|
+import datetime
|
|
|
# from pymysql import paramstyle
|
|
|
from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import BatParam
|
|
|
|
|
@@ -16,12 +17,13 @@ class BatInterShort():
|
|
|
self.sn=sn
|
|
|
self.celltype=celltype
|
|
|
self.param=BatParam.BatParam(celltype)
|
|
|
- self.df_bms=df_bms
|
|
|
self.packcrnt=df_bms['总电流[A]']*self.param.PackCrntDec
|
|
|
self.packvolt=df_bms['总电压[V]']
|
|
|
self.bms_soc=df_bms['SOC[%]']
|
|
|
- self.bmstime= pd.to_datetime(df_bms['时间戳'], format='%Y-%m-%d %H:%M:%S')
|
|
|
+ df_bms['time']=pd.to_datetime(df_bms['时间戳'], format='%Y-%m-%d %H:%M:%S')
|
|
|
+ self.bmstime= df_bms['time']
|
|
|
|
|
|
+ self.df_bms=df_bms
|
|
|
self.df_soh=df_soh
|
|
|
self.df_last=df_last
|
|
|
self.df_last1=df_last1
|
|
@@ -49,12 +51,12 @@ class BatInterShort():
|
|
|
#寻找当前行数据的最小温度值.............................................................................
|
|
|
def _celltemp_weight(self,num):
|
|
|
celltemp = list(self.df_bms.loc[num,self.celltemp_name])
|
|
|
- celltemp=np.mean(celltemp)
|
|
|
+ celltemp=min(celltemp)
|
|
|
self.celltemp=celltemp
|
|
|
if self.celltype==99:
|
|
|
if celltemp>=25:
|
|
|
self.tempweight=1
|
|
|
- self.StandardStandingTime=3600
|
|
|
+ self.StandardStandingTime=4800
|
|
|
elif celltemp>=15:
|
|
|
self.tempweight=0.6
|
|
|
self.StandardStandingTime=7200
|
|
@@ -65,12 +67,12 @@ class BatInterShort():
|
|
|
self.tempweight=0.1
|
|
|
self.StandardStandingTime=10800
|
|
|
else:
|
|
|
- if celltemp>=20:
|
|
|
+ if celltemp>=25:
|
|
|
self.tempweight=1
|
|
|
- self.StandardStandingTime=3600
|
|
|
- elif celltemp>=10:
|
|
|
+ self.StandardStandingTime=4800
|
|
|
+ elif celltemp>=15:
|
|
|
self.tempweight=0.8
|
|
|
- self.StandardStandingTime=3600
|
|
|
+ self.StandardStandingTime=7200
|
|
|
elif celltemp>=5:
|
|
|
self.tempweight=0.6
|
|
|
self.StandardStandingTime=7200
|
|
@@ -78,8 +80,28 @@ class BatInterShort():
|
|
|
self.tempweight=0.2
|
|
|
self.StandardStandingTime=10800
|
|
|
|
|
|
+ #获取前半个小时每个电压的平均值........................................................................................
|
|
|
+ def _avgvolt_get(self,num):
|
|
|
+ time_now=self.df_bms.loc[num, 'time']
|
|
|
+ time_last=time_now-datetime.timedelta(seconds=1800)
|
|
|
+ df_volt=self.df_bms[(self.df_bms['time']>=time_last) & (self.df_bms['time']<=time_now)]
|
|
|
+ df_volt=df_volt[self.cellvolt_name]
|
|
|
+ if len(df_volt)>2:
|
|
|
+ cellvolt_sum=df_volt.sum(0)-df_volt.max(0)-df_volt.min(0)
|
|
|
+ cellvolt_mean=cellvolt_sum/(len(df_volt)-2)
|
|
|
+ cellvolt=cellvolt_mean/1000
|
|
|
+ elif len(df_volt)==2:
|
|
|
+ # df_volt=pd.DataFrame(df_volt,dtype=np.float)
|
|
|
+ if max(abs(df_volt.iloc[1]-df_volt.iloc[0]))<3:
|
|
|
+ cellvolt=df_volt.mean(0)/1000
|
|
|
+ else:
|
|
|
+ cellvolt=pd.DataFrame()
|
|
|
+ else:
|
|
|
+ cellvolt=df_volt.iloc[0]
|
|
|
+ return cellvolt
|
|
|
+
|
|
|
#获取当前行所有电压数据........................................................................................
|
|
|
- def _cellvolt_get(self,num):
|
|
|
+ def _cellvolt_get(self,num):
|
|
|
cellvolt = np.array(self.df_bms.loc[num,self.cellvolt_name])/1000
|
|
|
return cellvolt
|
|
|
|
|
@@ -109,6 +131,20 @@ class BatInterShort():
|
|
|
else:
|
|
|
celldeltsoc.append(cellsoc[j]-cellsocmean2)
|
|
|
return np.array(celldeltsoc), np.array(cellsoc)
|
|
|
+
|
|
|
+ elif self.celltype==99:
|
|
|
+ consum_num=10
|
|
|
+ cellsoc1=cellsoc[:self.param.CellVoltNums-consum_num] #切片,将bms耗电的电芯和非耗电的电芯分离开
|
|
|
+ cellsocmean1=(sum(cellsoc1)-max(cellsoc1)-min(cellsoc1))/(len(cellsoc1)-2)
|
|
|
+ cellsoc2=cellsoc[self.param.CellVoltNums-consum_num:]
|
|
|
+ cellsocmean2=(sum(cellsoc2)-max(cellsoc2)-min(cellsoc2))/(len(cellsoc2)-2)
|
|
|
+
|
|
|
+ for j in range(len(cellsoc)): #计算每个电芯的soc差
|
|
|
+ if j<self.param.CellVoltNums-consum_num:
|
|
|
+ celldeltsoc.append(cellsoc[j]-cellsocmean1)
|
|
|
+ else:
|
|
|
+ celldeltsoc.append(cellsoc[j]-cellsocmean2)
|
|
|
+ return np.array(celldeltsoc), np.array(cellsoc)
|
|
|
|
|
|
else:
|
|
|
cellsocmean=(sum(cellsoc)-max(cellsoc)-min(cellsoc))/(len(cellsoc)-2)
|
|
@@ -277,13 +313,15 @@ class BatInterShort():
|
|
|
if firsttime==1:
|
|
|
if standingtime>self.StandardStandingTime*2: #静置时间满足要求
|
|
|
standingtime=0
|
|
|
- cellvolt_now=self._cellvolt_get(i)
|
|
|
+ cellvolt_now=self._avgvolt_get(i)
|
|
|
cellvolt_min=min(cellvolt_now)
|
|
|
cellvolt_max=max(cellvolt_now)
|
|
|
- cellvolt_last=self._cellvolt_get(i-1)
|
|
|
- deltvolt=max(abs(cellvolt_now-cellvolt_last))
|
|
|
+ # cellvolt_last=self._avgvolt_get(i-1)
|
|
|
+ # deltvolt=max(abs(cellvolt_now-cellvolt_last))
|
|
|
+ cellsoc_max=np.interp(cellvolt_max,self.param.LookTab_OCV,self.param.LookTab_SOC)
|
|
|
+ cellsoc_min=np.interp(cellvolt_min,self.param.LookTab_OCV,self.param.LookTab_SOC)
|
|
|
|
|
|
- if 2<cellvolt_min<4.5 and 2<cellvolt_max<4.5 and deltvolt<0.005:
|
|
|
+ if (not cellvolt_now.empty) and 2<cellvolt_min<4.5 and 2<cellvolt_max<4.5 and (45<cellsoc_max or cellsoc_max<30) and (45<cellsoc_min or cellsoc_min<30):
|
|
|
dict_baltime={} #获取每个电芯的均衡时间
|
|
|
deltsoc_last, cellsoc_last=self._celldeltsoc_get(i,dict_baltime,capacity)
|
|
|
time_last=self.bmstime[i]
|
|
@@ -291,15 +329,15 @@ class BatInterShort():
|
|
|
df_ram_last.loc[0]=[self.sn,time_last,deltsoc_last,cellsoc_last] #更新RAM信息
|
|
|
else:
|
|
|
pass
|
|
|
- elif standingtime>3600*10:
|
|
|
+ elif standingtime>3600*12:
|
|
|
standingtime=0
|
|
|
- cellvolt_now=self._cellvolt_get(i)
|
|
|
+ cellvolt_now=self._avgvolt_get(i)
|
|
|
cellvolt_min=min(cellvolt_now)
|
|
|
cellvolt_max=max(cellvolt_now)
|
|
|
- cellvolt_last=self._cellvolt_get(i-1)
|
|
|
- deltvolt=max(abs(cellvolt_now-cellvolt_last))
|
|
|
+ # cellvolt_last=self._avgvolt_get(i-1)
|
|
|
+ # deltvolt=max(abs(cellvolt_now-cellvolt_last))
|
|
|
|
|
|
- if 2<cellvolt_min<4.5 and 2<cellvolt_max<4.5 and deltvolt<0.005:
|
|
|
+ if (not cellvolt_now.empty) and 2<cellvolt_min<4.5 and 2<cellvolt_max<4.5:
|
|
|
dict_baltime=self._bal_time(dict_bal) #获取每个电芯的均衡时间
|
|
|
deltsoc_now, cellsoc_now=self._celldeltsoc_get(i,dict_baltime,capacity)
|
|
|
time_now=self.bmstime[i]
|
|
@@ -337,14 +375,14 @@ class BatInterShort():
|
|
|
#满电静置法计算内短路-开始.....................................................................................................................................................
|
|
|
if self.StandardStandingTime<standingtime1:
|
|
|
standingtime1=0
|
|
|
- cellvolt_now1=self._cellvolt_get(i)
|
|
|
+ cellvolt_now1=self._avgvolt_get(i)
|
|
|
cellvolt_max1=max(cellvolt_now1)
|
|
|
cellvolt_min1=min(cellvolt_now1)
|
|
|
- cellvolt_last1=self._cellvolt_get(i-1)
|
|
|
- deltvolt1=max(abs(cellvolt_now1-cellvolt_last1))
|
|
|
+ # cellvolt_last1=self._avgvolt_get(i-1)
|
|
|
+ # deltvolt1=max(abs(cellvolt_now1-cellvolt_last1))
|
|
|
cellsoc_now1=np.interp(cellvolt_max1,self.param.LookTab_OCV,self.param.LookTab_SOC)
|
|
|
|
|
|
- if cellsoc_now1>=self.param.FullChrgSoc-10 and 2<cellvolt_min1<4.5 and 2<cellvolt_max1<4.5 and deltvolt1<0.005:
|
|
|
+ if (not cellvolt_now1.empty) and cellsoc_now1>=self.param.FullChrgSoc-10 and 2<cellvolt_min1<4.5 and 2<cellvolt_max1<4.5:
|
|
|
if firsttime1==1:
|
|
|
dict_baltime1={} #获取每个电芯的均衡时间
|
|
|
deltsoc_last1, cellsoc_last1=self._celldeltsoc_get(i,dict_baltime1,capacity)
|
|
@@ -354,7 +392,7 @@ class BatInterShort():
|
|
|
else:
|
|
|
dict_baltime1=self._bal_time(dict_bal1) #获取每个电芯的均衡时间
|
|
|
time_now1=self.bmstime[i]
|
|
|
- if (time_now1-time_last1).total_seconds()>3600*12:
|
|
|
+ if (time_now1-time_last1).total_seconds()>3600*20:
|
|
|
deltsoc_now1, cellsoc_now1=self._celldeltsoc_get(i,dict_baltime1,capacity)
|
|
|
df_ram_last1.loc[0]=[self.sn,time_now1,deltsoc_now1] #更新RAM信息
|
|
|
|
|
@@ -483,13 +521,15 @@ class BatInterShort():
|
|
|
if firsttime==1:
|
|
|
if standingtime>self.StandardStandingTime: #静置时间满足要求
|
|
|
standingtime=0
|
|
|
- cellvolt_now=self._cellvolt_get(i)
|
|
|
+ cellvolt_now=self._avgvolt_get(i)
|
|
|
cellvolt_min=min(cellvolt_now)
|
|
|
cellvolt_max=max(cellvolt_now)
|
|
|
- cellvolt_last=self._cellvolt_get(i-1)
|
|
|
- deltvolt=max(abs(cellvolt_now-cellvolt_last))
|
|
|
+ # cellvolt_last=self._avgvolt_get(i-1)
|
|
|
+ # deltvolt=max(abs(cellvolt_now-cellvolt_last))
|
|
|
+ cellsoc_max=np.interp(cellvolt_max,self.param.LookTab_OCV,self.param.LookTab_SOC)
|
|
|
+ cellsoc_min=np.interp(cellvolt_min,self.param.LookTab_OCV,self.param.LookTab_SOC)
|
|
|
|
|
|
- if 2<cellvolt_max<self.param.OcvInflexionBelow-0.002 and 2<cellvolt_min<4.5 and abs(deltvolt)<0.003:
|
|
|
+ if (not cellvolt_now.empty) and cellsoc_max<self.param.SocInflexion1-2 and 12<cellsoc_min:
|
|
|
dict_baltime={} #获取每个电芯的均衡时间
|
|
|
deltsoc_last, cellsoc_last=self._celldeltsoc_get(i,dict_baltime,capacity)
|
|
|
time_last=self.bmstime[i]
|
|
@@ -499,15 +539,17 @@ class BatInterShort():
|
|
|
pass
|
|
|
else:
|
|
|
pass
|
|
|
- elif standingtime>3600*10:
|
|
|
+ elif standingtime>3600*12:
|
|
|
standingtime=0
|
|
|
- cellvolt_now=np.array(self._cellvolt_get(i))
|
|
|
+ cellvolt_now=np.array(self._avgvolt_get(i))
|
|
|
cellvolt_min=min(cellvolt_now)
|
|
|
cellvolt_max=max(cellvolt_now)
|
|
|
- cellvolt_last=np.array(self._cellvolt_get(i-1))
|
|
|
- deltvolt=max(abs(cellvolt_now-cellvolt_last))
|
|
|
+ # cellvolt_last=np.array(self._avgvolt_get(i-1))
|
|
|
+ # deltvolt=max(abs(cellvolt_now-cellvolt_last))
|
|
|
+ cellsoc_max=np.interp(cellvolt_max,self.param.LookTab_OCV,self.param.LookTab_SOC)
|
|
|
+ cellsoc_min=np.interp(cellvolt_min,self.param.LookTab_OCV,self.param.LookTab_SOC)
|
|
|
|
|
|
- if 2<cellvolt_max<self.param.OcvInflexionBelow-0.002 and 2<cellvolt_min<4.5 and abs(deltvolt)<0.003:
|
|
|
+ if (not cellvolt_now.empty) and cellsoc_max<self.param.SocInflexion1-2 and 12<cellsoc_min:
|
|
|
dict_baltime=self._bal_time(dict_bal) #获取每个电芯的均衡时间
|
|
|
deltsoc_now, cellsoc_now=self._celldeltsoc_get(i, dict_baltime,capacity) #获取每个电芯的SOC差
|
|
|
time_now=self.bmstime[i]
|
|
@@ -547,13 +589,15 @@ class BatInterShort():
|
|
|
#非平台区间静置法计算内短路-开始.....................................................................................................................................................
|
|
|
if standingtime1>self.StandardStandingTime:
|
|
|
standingtime1=0
|
|
|
- cellvolt_now1=self._cellvolt_get(i)
|
|
|
+ cellvolt_now1=self._avgvolt_get(i)
|
|
|
cellvolt_max1=max(cellvolt_now1)
|
|
|
cellvolt_min1=min(cellvolt_now1)
|
|
|
- cellvolt_last1=self._cellvolt_get(i-1)
|
|
|
- deltvolt1=max(abs(cellvolt_now1-cellvolt_last1))
|
|
|
+ # cellvolt_last1=self._avgvolt_get(i-1)
|
|
|
+ # deltvolt1=max(abs(cellvolt_now1-cellvolt_last1))
|
|
|
+ cellsoc_max1=np.interp(cellvolt_max1,self.param.LookTab_OCV,self.param.LookTab_SOC)
|
|
|
+ cellsoc_min1=np.interp(cellvolt_min1,self.param.LookTab_OCV,self.param.LookTab_SOC)
|
|
|
|
|
|
- if 2<cellvolt_max1<self.param.OcvInflexionBelow-0.002 and 2<cellvolt_min1<4.5 and deltvolt1<0.005:
|
|
|
+ if (not cellvolt_now1.empty) and cellsoc_max1<self.param.SocInflexion1-2 and 12<cellsoc_min1:
|
|
|
if firsttime1==1:
|
|
|
dict_baltime1=self._bal_time(dict_bal1) #获取每个电芯的均衡时间
|
|
|
deltsoc_last1, cellsoc_last1=self._celldeltsoc_get(i,dict_baltime1,capacity)
|
|
@@ -628,7 +672,7 @@ class BatInterShort():
|
|
|
continue
|
|
|
elif min(cellvolt_now)>self.param.CellFullChrgVolt-0.13: #电压>满充电压-0.13V,即3.37V
|
|
|
self._celltemp_weight(i)
|
|
|
- if i-chrg_start>10 and self.celltemp>15:
|
|
|
+ if i-chrg_start>10 and self.celltemp>20:
|
|
|
chrg_end=i+1
|
|
|
charging=0
|
|
|
|