|
@@ -1,24 +1,22 @@
|
|
|
|
+from types import CellType
|
|
import pandas as pd
|
|
import pandas as pd
|
|
import numpy as np
|
|
import numpy as np
|
|
-import datetime
|
|
|
|
|
|
+import datetime,time
|
|
import pika
|
|
import pika
|
|
import json
|
|
import json
|
|
import BatParam
|
|
import BatParam
|
|
|
|
|
|
class BatCrtl():
|
|
class BatCrtl():
|
|
- def __init__(self,host,port,df_statectrl_ram,df_rlyctrl_ram,df_balctrl_ram,df_diag,df_bms,sn_list): #参数初始化
|
|
|
|
|
|
+ def __init__(self,host,port,df_statectrl_ram,df_rlyctrl_ram,df_diag,df_bms,sn_list): #参数初始化
|
|
|
|
|
|
- celltype=1
|
|
|
|
self.host=host
|
|
self.host=host
|
|
self.port=port
|
|
self.port=port
|
|
self.sn_list=sn_list
|
|
self.sn_list=sn_list
|
|
- self.param=BatParam.BatParam(celltype)
|
|
|
|
|
|
|
|
df_bms['time']=pd.to_datetime(df_bms['time'], format='%Y-%m-%d %H:%M:%S')
|
|
df_bms['time']=pd.to_datetime(df_bms['time'], format='%Y-%m-%d %H:%M:%S')
|
|
self.df_bms=df_bms
|
|
self.df_bms=df_bms
|
|
self.df_statectrl_ram=df_statectrl_ram.copy()
|
|
self.df_statectrl_ram=df_statectrl_ram.copy()
|
|
self.df_rlyctrl_ram=df_rlyctrl_ram.copy()
|
|
self.df_rlyctrl_ram=df_rlyctrl_ram.copy()
|
|
- self.df_balctrl_ram=df_balctrl_ram.copy()
|
|
|
|
self.df_diag1=df_diag[(df_diag['fault_code']==110) | (df_diag['fault_code']==119) | (df_diag['fault_code']==12) | (df_diag['fault_code']==18)]
|
|
self.df_diag1=df_diag[(df_diag['fault_code']==110) | (df_diag['fault_code']==119) | (df_diag['fault_code']==12) | (df_diag['fault_code']==18)]
|
|
self.df_diag2=df_diag[df_diag['fault_code']==100]
|
|
self.df_diag2=df_diag[df_diag['fault_code']==100]
|
|
|
|
|
|
@@ -27,8 +25,6 @@ class BatCrtl():
|
|
# self.bms_soc=df_bms['PackSOC']
|
|
# self.bms_soc=df_bms['PackSOC']
|
|
# self.bms_soh=df_bms['PackSOH']
|
|
# self.bms_soh=df_bms['PackSOH']
|
|
# self.bmsstat=df_bms['BMSStat']
|
|
# self.bmsstat=df_bms['BMSStat']
|
|
- self.cellvolt_name=['CellVolt'+str(x) for x in range(1,self.param.CellVoltNums+1)]
|
|
|
|
- self.celltemp_name=['CellTemp'+str(x) for x in range(1,self.param.CellTempNums+1)]
|
|
|
|
|
|
|
|
#主调用函数........................................................................
|
|
#主调用函数........................................................................
|
|
def bat_crtl(self):
|
|
def bat_crtl(self):
|
|
@@ -48,12 +44,22 @@ class BatCrtl():
|
|
channel.queue_declare(queue='cmdQueue',durable=True)
|
|
channel.queue_declare(queue='cmdQueue',durable=True)
|
|
channel.basic_publish(exchange='cmdExchange',routing_key='CmdDirectRouting',body=json.dumps(dict_send)) # 消息内容
|
|
channel.basic_publish(exchange='cmdExchange',routing_key='CmdDirectRouting',body=json.dumps(dict_send)) # 消息内容
|
|
connection.close()
|
|
connection.close()
|
|
|
|
+
|
|
|
|
+ def _parameter(self,sn):
|
|
|
|
+ if 'KPD' in sn:
|
|
|
|
+ celltype=1
|
|
|
|
+ else:
|
|
|
|
+ celltype=99
|
|
|
|
+
|
|
|
|
+ self.param=BatParam.BatParam(celltype)
|
|
|
|
+ self.cellvolt_name=['CellVolt'+str(x) for x in range(1,self.param.CellVoltNums+1)]
|
|
|
|
+ self.celltemp_name=['CellTemp'+str(x) for x in range(1,self.param.CellTempNums+1)]
|
|
|
|
|
|
#电池继电器下行控制.........................................................................................................................
|
|
#电池继电器下行控制.........................................................................................................................
|
|
def _bat_rlycrtl(self):
|
|
def _bat_rlycrtl(self):
|
|
time_now=datetime.datetime.now()
|
|
time_now=datetime.datetime.now()
|
|
- factory=self.df_bms.iloc[0]['factory']
|
|
|
|
for sn in self.sn_list:
|
|
for sn in self.sn_list:
|
|
|
|
+ factory=self.df_bms.loc[self.df_bms[self.df_bms['sn']==sn].index[0], 'factory']
|
|
if sn in list(self.df_diag1['sn']): #该sn发生4级或5级故障
|
|
if sn in list(self.df_diag1['sn']): #该sn发生4级或5级故障
|
|
if sn in list(self.df_rlyctrl_ram['sn']): #ram是否包含该sn
|
|
if sn in list(self.df_rlyctrl_ram['sn']): #ram是否包含该sn
|
|
if self.df_rlyctrl_ram.loc[self.df_rlyctrl_ram[self.df_rlyctrl_ram['sn']==sn].index[0], 'batrlyctrl']==0:
|
|
if self.df_rlyctrl_ram.loc[self.df_rlyctrl_ram[self.df_rlyctrl_ram['sn']==sn].index[0], 'batrlyctrl']==0:
|
|
@@ -88,8 +94,8 @@ class BatCrtl():
|
|
|
|
|
|
#电池充放电下行控制.........................................................................................................................
|
|
#电池充放电下行控制.........................................................................................................................
|
|
def _bat_statecrtl(self):
|
|
def _bat_statecrtl(self):
|
|
- time_now=datetime.datetime.now()
|
|
|
|
- factory=self.df_bms.iloc[0]['factory']
|
|
|
|
|
|
+ time_now=datetime.datetime.now()
|
|
|
|
+
|
|
#对完成充放电循环,且超过10天的,done_flg置0
|
|
#对完成充放电循环,且超过10天的,done_flg置0
|
|
if not self.df_statectrl_ram.empty:
|
|
if not self.df_statectrl_ram.empty:
|
|
for i in range(len(self.df_statectrl_ram)):
|
|
for i in range(len(self.df_statectrl_ram)):
|
|
@@ -103,11 +109,13 @@ class BatCrtl():
|
|
#存在电池正在放电-------------------------------
|
|
#存在电池正在放电-------------------------------
|
|
if 3 in list(self.df_statectrl_ram['batstatectrl']):
|
|
if 3 in list(self.df_statectrl_ram['batstatectrl']):
|
|
sn=self.df_statectrl_ram.loc[self.df_statectrl_ram[self.df_statectrl_ram['batstatectrl']==3].index[0], 'sn']
|
|
sn=self.df_statectrl_ram.loc[self.df_statectrl_ram[self.df_statectrl_ram['batstatectrl']==3].index[0], 'sn']
|
|
|
|
+ factory=self.df_bms.loc[self.df_bms[self.df_bms['sn']==sn].index[0], 'factory']
|
|
|
|
+ self._parameter(sn)
|
|
bms_index=self.df_bms[self.df_bms['sn']==sn].index[0]
|
|
bms_index=self.df_bms[self.df_bms['sn']==sn].index[0]
|
|
packsoc=self.df_bms.loc[bms_index,'PackSOC']
|
|
packsoc=self.df_bms.loc[bms_index,'PackSOC']
|
|
cellvolt = self.df_bms.loc[bms_index,self.cellvolt_name]
|
|
cellvolt = self.df_bms.loc[bms_index,self.cellvolt_name]
|
|
time_now=self.df_bms.loc[bms_index,'time']
|
|
time_now=self.df_bms.loc[bms_index,'time']
|
|
- if packsoc<10 or 1<min(cellvolt)<3: #结束放电
|
|
|
|
|
|
+ if packsoc<self.param.DscPackSoc or 1<min(cellvolt)<self.param.CellDscVolt: #结束放电
|
|
self.df_statectrl_ram.loc[self.df_statectrl_ram[self.df_statectrl_ram['sn']==sn].index[0], 'time']=time_now
|
|
self.df_statectrl_ram.loc[self.df_statectrl_ram[self.df_statectrl_ram['sn']==sn].index[0], 'time']=time_now
|
|
self.df_statectrl_ram.loc[self.df_statectrl_ram[self.df_statectrl_ram['sn']==sn].index[0], 'batstatectrl']=2
|
|
self.df_statectrl_ram.loc[self.df_statectrl_ram[self.df_statectrl_ram['sn']==sn].index[0], 'batstatectrl']=2
|
|
dict_send={"cmd_type":2,"factory":factory,"sn":sn,"batstatectrl":2,"dischrg_volt":272}
|
|
dict_send={"cmd_type":2,"factory":factory,"sn":sn,"batstatectrl":2,"dischrg_volt":272}
|
|
@@ -118,12 +126,14 @@ class BatCrtl():
|
|
#存在电池正在静置---------------------------------
|
|
#存在电池正在静置---------------------------------
|
|
elif 2 in list(self.df_statectrl_ram['batstatectrl']):
|
|
elif 2 in list(self.df_statectrl_ram['batstatectrl']):
|
|
sn=self.df_statectrl_ram.loc[self.df_statectrl_ram[self.df_statectrl_ram['batstatectrl']==2].index[0], 'sn']
|
|
sn=self.df_statectrl_ram.loc[self.df_statectrl_ram[self.df_statectrl_ram['batstatectrl']==2].index[0], 'sn']
|
|
|
|
+ factory=self.df_bms.loc[self.df_bms[self.df_bms['sn']==sn].index[0], 'factory']
|
|
|
|
+ self._parameter(sn)
|
|
bms_index=self.df_bms[self.df_bms['sn']==sn].index[0]
|
|
bms_index=self.df_bms[self.df_bms['sn']==sn].index[0]
|
|
packcrnt=self.df_bms.loc[bms_index,'PackCrnt']
|
|
packcrnt=self.df_bms.loc[bms_index,'PackCrnt']
|
|
packsoc=self.df_bms.loc[bms_index,'PackSOC']
|
|
packsoc=self.df_bms.loc[bms_index,'PackSOC']
|
|
cellvolt = self.df_bms.loc[bms_index,self.cellvolt_name]
|
|
cellvolt = self.df_bms.loc[bms_index,self.cellvolt_name]
|
|
time_now=self.df_bms.loc[bms_index,'time']
|
|
time_now=self.df_bms.loc[bms_index,'time']
|
|
- if packsoc>25 or min(cellvolt)>3.5:
|
|
|
|
|
|
+ if packsoc>self.param.DscPackSoc+5 or self.param.CellDscVolt+0.5<min(cellvolt)<4.5:
|
|
self.df_statectrl_ram.loc[self.df_statectrl_ram[self.df_statectrl_ram['sn']==sn].index[0], 'time']=time_now
|
|
self.df_statectrl_ram.loc[self.df_statectrl_ram[self.df_statectrl_ram['sn']==sn].index[0], 'time']=time_now
|
|
self.df_statectrl_ram.loc[self.df_statectrl_ram[self.df_statectrl_ram['sn']==sn].index[0], 'batstatectrl']=3
|
|
self.df_statectrl_ram.loc[self.df_statectrl_ram[self.df_statectrl_ram['sn']==sn].index[0], 'batstatectrl']=3
|
|
dict_send={"cmd_type":2,"factory":factory,"sn":sn,"batstatectrl":3,"dischrg_volt":272}
|
|
dict_send={"cmd_type":2,"factory":factory,"sn":sn,"batstatectrl":3,"dischrg_volt":272}
|
|
@@ -148,6 +158,8 @@ class BatCrtl():
|
|
#存在电池正在充电------------------------------------
|
|
#存在电池正在充电------------------------------------
|
|
elif 1 in list(self.df_statectrl_ram['batstatectrl']):
|
|
elif 1 in list(self.df_statectrl_ram['batstatectrl']):
|
|
sn=self.df_statectrl_ram.loc[self.df_statectrl_ram[self.df_statectrl_ram['batstatectrl']==1].index[0], 'sn']
|
|
sn=self.df_statectrl_ram.loc[self.df_statectrl_ram[self.df_statectrl_ram['batstatectrl']==1].index[0], 'sn']
|
|
|
|
+ factory=self.df_bms.loc[self.df_bms[self.df_bms['sn']==sn].index[0], 'factory']
|
|
|
|
+ self._parameter(sn)
|
|
bms_index=self.df_bms[self.df_bms['sn']==sn].index[0]
|
|
bms_index=self.df_bms[self.df_bms['sn']==sn].index[0]
|
|
packsoc=self.df_bms.loc[bms_index,'PackSOC']
|
|
packsoc=self.df_bms.loc[bms_index,'PackSOC']
|
|
cellvolt = self.df_bms.loc[bms_index,self.cellvolt_name]
|
|
cellvolt = self.df_bms.loc[bms_index,self.cellvolt_name]
|
|
@@ -164,13 +176,15 @@ class BatCrtl():
|
|
#当前电池均不在充放电循环过程中,则接下来判断是否存在100故障---------------------------------
|
|
#当前电池均不在充放电循环过程中,则接下来判断是否存在100故障---------------------------------
|
|
else:
|
|
else:
|
|
for sn in self.sn_list:
|
|
for sn in self.sn_list:
|
|
|
|
+ factory=self.df_bms.loc[self.df_bms[self.df_bms['sn']==sn].index[0], 'factory']
|
|
|
|
+ self._parameter(sn)
|
|
if sn in list(self.df_diag2['sn']): #该sn发生100长时间未标定故障
|
|
if sn in list(self.df_diag2['sn']): #该sn发生100长时间未标定故障
|
|
if sn in list(self.df_bms['sn']):
|
|
if sn in list(self.df_bms['sn']):
|
|
bms_index=self.df_bms[self.df_bms['sn']==sn].index[0]
|
|
bms_index=self.df_bms[self.df_bms['sn']==sn].index[0]
|
|
packsoc=self.df_bms.loc[bms_index,'PackSOC']
|
|
packsoc=self.df_bms.loc[bms_index,'PackSOC']
|
|
cellvolt = self.df_bms.loc[bms_index,self.cellvolt_name]
|
|
cellvolt = self.df_bms.loc[bms_index,self.cellvolt_name]
|
|
time_now=self.df_bms.loc[bms_index,'time']
|
|
time_now=self.df_bms.loc[bms_index,'time']
|
|
- if packsoc>20 or min(cellvolt)>3.5:
|
|
|
|
|
|
+ if packsoc>self.param.DscPackSoc+5 or self.param.CellDscVolt+0.5<min(cellvolt)<4.5:
|
|
if sn in list(self.df_statectrl_ram['sn']): #该sn的ram不为空
|
|
if sn in list(self.df_statectrl_ram['sn']): #该sn的ram不为空
|
|
if self.df_statectrl_ram.loc[self.df_statectrl_ram[self.df_statectrl_ram['sn']==sn].index[0], 'done_flg']==0:
|
|
if self.df_statectrl_ram.loc[self.df_statectrl_ram[self.df_statectrl_ram['sn']==sn].index[0], 'done_flg']==0:
|
|
self.df_statectrl_ram.loc[self.df_statectrl_ram[self.df_statectrl_ram['sn']==sn].index[0], 'time']=time_now
|
|
self.df_statectrl_ram.loc[self.df_statectrl_ram[self.df_statectrl_ram['sn']==sn].index[0], 'time']=time_now
|
|
@@ -221,10 +235,13 @@ class BatCrtl():
|
|
|
|
|
|
#电池均衡下行控制————————————————————————————————————————————————————————————————————————————————————————————————————————
|
|
#电池均衡下行控制————————————————————————————————————————————————————————————————————————————————————————————————————————
|
|
def _bat_balcrtl(self):
|
|
def _bat_balcrtl(self):
|
|
- time_now=datetime.datetime.now()
|
|
|
|
- factory=self.df_bms.iloc[0]['factory']
|
|
|
|
|
|
|
|
for sn in self.sn_list:
|
|
for sn in self.sn_list:
|
|
|
|
+ sn_index=self.df_bms[self.df_bms['sn']==sn].index[0]
|
|
|
|
+ factory=self.df_bms.loc[sn_index, 'factory'] #获取厂家名称
|
|
|
|
+ bms_balstate=self.df_bms.loc[sn_index, 'balstate'] #获取BMS均衡状态
|
|
|
|
+ bms_balstate=list(map(int,bms_balstate.split(',')))
|
|
|
|
+ self._parameter(sn)
|
|
bms_index=self.df_bms[self.df_bms['sn']==sn].index[0]
|
|
bms_index=self.df_bms[self.df_bms['sn']==sn].index[0]
|
|
packsoc=self.df_bms.loc[bms_index,'PackSOC']
|
|
packsoc=self.df_bms.loc[bms_index,'PackSOC']
|
|
cellvolt = self.df_bms.loc[bms_index,self.cellvolt_name]
|
|
cellvolt = self.df_bms.loc[bms_index,self.cellvolt_name]
|
|
@@ -234,29 +251,45 @@ class BatCrtl():
|
|
|
|
|
|
voltdiff=np.interp(packsoc,self.param.LookTab_SOC,self.param.LookTab_DiffVolt)
|
|
voltdiff=np.interp(packsoc,self.param.LookTab_SOC,self.param.LookTab_DiffVolt)
|
|
|
|
|
|
- if min(cellvolt)>2 and max(cellvolt)<4.5 and packsoc>15 and max(cellvolt)-min(cellvolt)>voltdiff: #满足均衡开启条件
|
|
|
|
|
|
+ #满足均衡开启条件————————————————————————————————————————————————————————————————————————————————————
|
|
|
|
+ if min(cellvolt)>2 and max(cellvolt)<4.5 and packsoc>20 and max(cellvolt)-min(cellvolt)>voltdiff:
|
|
#寻找并判断最大电压是否在均衡
|
|
#寻找并判断最大电压是否在均衡
|
|
cellmax_index=list(cellvolt).index(max(cellvolt))+1
|
|
cellmax_index=list(cellvolt).index(max(cellvolt))+1
|
|
- bal_num=cellmax_index//16
|
|
|
|
- bal_index=cellmax_index%16
|
|
|
|
|
|
+ bal_group = cellmax_index // self.param.BalGroups #取整
|
|
|
|
+ bal_index = cellmax_index % self.param.BalGroups #取余
|
|
if bal_index==0:
|
|
if bal_index==0:
|
|
- bal_index=16
|
|
|
|
|
|
+ bal_index=self.param.BalNums
|
|
else:
|
|
else:
|
|
pass
|
|
pass
|
|
|
|
+
|
|
|
|
+ #获取BMS当前最大电芯电压的均衡状态
|
|
|
|
+ bmscellmax_balgroup=bms_balstate[bal_group]
|
|
|
|
+ bmscellmax_balgroup >> bal_index-1
|
|
|
|
+ bmscellmax_balstate=bmscellmax_balgroup & 1
|
|
|
|
|
|
- cellmax_balstate='balstate'+str(bal_num)
|
|
|
|
- cellmax_balstate >> bal_index-1
|
|
|
|
- cellmax_balstate=cellmax_balstate & 1
|
|
|
|
-
|
|
|
|
- if cellmax_balstate==1: #最大电压在均衡
|
|
|
|
|
|
+ if bmscellmax_balstate==1: #最大电压在均衡
|
|
pass
|
|
pass
|
|
else: #最大电芯不在均衡
|
|
else: #最大电芯不在均衡
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ cellvoltdiff=cellvolt-min(cellvolt)
|
|
|
|
+ cellvoltdiff=cellvoltdiff[cellvoltdiff>voltdiff]=1 #压差>阈值的赋1
|
|
|
|
+ cellvoltdiff=cellvoltdiff[cellvoltdiff<=voltdiff]=0 #压差<=阈值的赋0
|
|
|
|
+ cellvoltdiff=list(map(int,cellvoltdiff))
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ #均衡状态按照分组赋值————————————————————————————————————————————————
|
|
|
|
+ limsbalctrl=[]
|
|
|
|
+ for i in range(self.param.BalGroups):
|
|
|
|
+ balstate=0
|
|
|
|
+ cellvoltdiff_group=cellvoltdiff[self.param.BalNums*i : self.param.BalNums*(i+1)]
|
|
|
|
+ for j in range(self.param.BalNums): #计算每一个分组的均衡状态
|
|
|
|
+ balstate=balstate+cellvoltdiff_group[j]*2**j
|
|
|
|
+ limsbalctrl.append(balstate)
|
|
|
|
+ dict_send={"cmd_type":3,"factory":factory,"sn":sn,"batbalctrl":limsbalctrl}
|
|
|
|
+ self._rabbit_send(dict_send)
|
|
|
|
+ time.sleep(0.1)
|
|
|
|
+
|
|
|
|
+ #不满足均衡开启条件————————————————————————————————————————————————————————————————————————————————————
|
|
|
|
+ else:
|
|
|
|
+ limsbalctrl=[0]*self.param.BalGroups #所有电芯均衡关闭
|
|
|
|
+ dict_send={"cmd_type":3,"factory":factory,"sn":sn,"batbalctrl":limsbalctrl}
|
|
|
|
+ self._rabbit_send(dict_send)
|
|
|
|
+ time.sleep(0.1)
|