PowwerUp / battery.py
pvsai's picture
Upload folder using huggingface_hub
88bc772 verified
Raw
History Blame Contribute Delete
1.07 kB
class Battery:
def __init__(self, e_max_mwh, p_ch_max, p_dis_max, eta_ch, eta_dis):
self.e_max = e_max_mwh
self.p_ch_max = p_ch_max
self.p_dis_max = p_dis_max
self.eta_ch = eta_ch
self.eta_dis = eta_dis
self.soc = 0.5 * self.e_max # Start at 50% (10 MWh)
def reset(self):
self.soc = 0.5 * self.e_max
return self.soc
def step(self, action_fraction, dt_hours):
"""
action_fraction: -1 (Full Charge) to 1 (Full Discharge)
"""
if action_fraction < 0: # Charging
p_mw = max(action_fraction * self.p_ch_max, -self.p_ch_max)
# SoC increases by (Power * Time * Efficiency)
self.soc += abs(p_mw) * dt_hours * self.eta_ch
else: # Discharging
p_mw = min(action_fraction * self.p_dis_max, self.p_dis_max)
# SoC decreases by (Power * Time / Efficiency)
self.soc -= (p_mw * dt_hours) / self.eta_dis
self.soc = max(0.0, min(self.e_max, self.soc))
return self.soc