Skip to content

Commit

Permalink
FIX: Eliminada implantación de calculo rms numérico. Se usa solamente…
Browse files Browse the repository at this point in the history
… el método simbólico.
  • Loading branch information
barreiroleo committed Aug 27, 2021
1 parent b78b7fc commit 8e424d0
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions dimmer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
from scipy.optimize import bisect
from tabulate import tabulate


class Dimmer:
Expand All @@ -26,10 +27,10 @@ def _v_sine(self, t):
omega = 2 * np.pi * self.frequency
return self.amplitud * np.sin(omega * t)

def v_dimmer(self, t):
def v_dimmer(self, t):
per = self.periode
tint = self.time_interrupt

# sourcery skip: flip-comparison
if (0 <= t and t < tint):
return 0
elif (tint <= t and t < 0.5 * per):
Expand All @@ -39,15 +40,6 @@ def v_dimmer(self, t):
elif (0.5*per + tint <= t and t < per):
return self._v_sine(t)

def vrms_num(self):
t_series = np.arange(0, self.periode, self.periode / 200)
v_series = [self.v_dimmer(t) for t in t_series]
v_sum = 0
for i in v_series:
v_sum = v_sum + i**2
rms = np.sqrt(v_sum / len(v_series))
return rms

def vrms_simbolic(self):
amp, omega = self.amplitud, 2 * np.pi * self.frequency
per, tint = self.periode, self.time_interrupt
Expand Down Expand Up @@ -90,3 +82,15 @@ def function(tint, bias=0):

self.time_interrupt = time_interrupt_backup
return root

def print_dimmer_state(self):
# TODO: Ver si conviene agregar un atributo de vrms actual. Se repite el calculo en ocaciones.
vrms = self.vrms_simbolic()
duty = self.convert_rms_duty(vrms)
header = ["Amplitud [V]", "Frecuencia [Hz]", "Interrupción [s]", "Vrms [V]", "Duty [%]"]
data = [[self.amplitud, self.frequency, self.time_interrupt, vrms, duty]]
print_table(header, data)

def print_table(header, data):
print(tabulate(tabular_data=data, headers=header, tablefmt="simple",
numalign="center", stralign="center"))

0 comments on commit 8e424d0

Please sign in to comment.