Skip to content

Commit

Permalink
- made components phase accessable to env
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Weber committed Apr 27, 2021
1 parent 7acfb4d commit 57426c4
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions openmodelica_microgrid_gym/net/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,25 +128,27 @@ def __init__(self, v_ref=(1, 0, 0), pdroop=None, qdroop=None, **kwargs):
self.pdroop_ctl = DroopController(DroopParams(nom_value=self.net.freq_nom, **pdroop), self.net.ts)
self.qdroop_ctl = DroopController(DroopParams(nom_value=self.net.v_nom, **qdroop), self.net.ts)
self.dds = DDS(self.net.ts)
self.phase = 0.0

def reset(self):
super().reset()
self.pdroop_ctl.reset()
self.qdroop_ctl.reset()
self.dds.reset()
self.phase = 0.0

def calculate(self):
super().calculate()
instPow = -inst_power(self.v, self.i)
freq = self.pdroop_ctl.step(instPow)
# Get the next phase rotation angle to implement
phase = self.dds.step(freq)
self.phase = self.dds.step(freq)

instQ = -inst_reactive(self.v, self.i)
v_refd = self.qdroop_ctl.step(instQ)
v_refdq0 = np.array([v_refd, 0, 0]) * self.v_ref

return dict(i_ref=dq0_to_abc(self.i_ref, phase), v_ref=dq0_to_abc(v_refdq0, phase))
return dict(i_ref=dq0_to_abc(self.i_ref, self.phase), v_ref=dq0_to_abc(v_refdq0, self.phase))

def normalize(self, calc_data):
super().normalize(calc_data),
Expand All @@ -163,30 +165,32 @@ def calculate(self):
instPow = -inst_power(self.v, self.i)
freq = self.pdroop_ctl.step(instPow)
# Get the next phase rotation angle to implement
phase = self.dds.step(freq)
self.phase = self.dds.step(freq)

instQ = -inst_reactive(self.v, self.i)
v_refd = self.qdroop_ctl.step(instQ)
v_refdq0 = np.array([v_refd, 0, 0]) * self.v_ref

return dict(i_ref=self.i_ref, v_ref=v_refdq0)
return dict(i_ref=np.array(self.i_ref), v_ref=v_refdq0)


class MasterInverterCurrentSourcing(Inverter):
def __init__(self, f_nom=50, **kwargs):
super().__init__(out_calc=dict(i_ref=3), **kwargs)
self.dds = DDS(self.net.ts)
self.f_nom = f_nom
self.phase = 0.0

def reset(self):
super().reset()
self.dds.reset()
self.phase = 0.0

def calculate(self):
super().calculate()
# Get the next phase rotation angle to implement
phase = self.dds.step(self.f_nom)
return dict(i_ref=dq0_to_abc(self.i_ref, phase))
self.phase = self.dds.step(self.f_nom)
return dict(i_ref=dq0_to_abc(self.i_ref, self.phase))


class Load(Component):
Expand Down

0 comments on commit 57426c4

Please sign in to comment.