def main(): #global Pred i = 0 #thread.start_new_thread(adquisicion2,(i,)) while True: n = excel.main(float(16), 0) n = int(n) mcpras.set_value(n) time.sleep(0.2) # P1=Node611.sensorm() # try: Pred = adquisicion2() # # except: # time.sleep(0.1) # Pred=adquisicion2() # # # result = client.read_holding_registers(11729, 2, unit=1)#Current A 1100 # decoder = BinaryPayloadDecoder.fromRegisters(result.registers, byteorder=Endian.Big ) # print(result.registers) # print(decoder.decode_32bit_float()) # result.registers=0 #archivo.write(str(Pred)+'\n') print(Pred) i = i + 1
def main(): #global Pred v = 14.5 i = 0 k = 1 j = 1 #thread.start_new_thread(adquisicion2,(i,)) while True: n = excel.main(float(v), 0) n = int(n) mcpras.set_value(n) time.sleep(0.3) # P1=Node611.sensorm() Psol = n611_adquisicion.adquisicion() try: Pred = adquisicion2() except: time.sleep(1) Pred = adquisicion2() Pload = Psol * 0.76 + Pred * 0.56 hoja.write(j, 0, str(k)) hoja.write(j, 1, time.strftime("%X")) hoja.write(j, 2, str(v)) hoja.write(j, 3, str(Pred)) hoja.write(j, 4, str(Psol)) hoja.write(j, 5, str(Pload)) # result = client.read_holding_registers(11729, 2, unit=1)#Current A 1100 # decoder = BinaryPayloadDecoder.fromRegisters(result.registers, byteorder=Endian.Big ) # print(result.registers) # print(decoder.decode_32bit_float()) # result.registers=0 #archivo.write(str(Pred)+'\n') print(Pred) print(Psol) print(v) v = v + 0.1 i = i + 1 j = j + 1 if i == 35: k = k + 1 i = 0 v = 14.5
def SetVoltage(): if request.method == 'POST': vol = request.form['voltaje'] volt = float(vol) R2 = 360 * ((volt / 1.25) - 1) n = 256 * (R2 - 3200 - 75) / 10000 n = round(n) n = int(n) mcpras.set_value(n) cur = mysql.connection.cursor() cur.execute( 'INSERT INTO parametros (id, voltaje, corriente) VALUES (%s, %s, %s)', (0, vol, 5)) mysql.connection.commit() flash('Voltaje Ajustado') return redirect(url_for('Index'))
##Rules rule1 = ctrl.Rule(Pdif['P'], Vrefd['P']) rule2 = ctrl.Rule(Pdif['N'], Vrefd['N']) rule3 = ctrl.Rule(Pdif['Z'], Vrefd['Z']) vref_ctrl = ctrl.ControlSystem([rule1, rule2, rule3]) vrefout = ctrl.ControlSystemSimulation(vref_ctrl) i = True v = 17 while True: n = excel.main(float(v), 0) n = int(n) mcpras.set_value(n) P1 = Node611.sensorm() time.sleep(1) n = excel.main(float(v), 0) n = int(n) mcpras.set_value(n) P2 = Node611.sensorm() Pdif = P2 - P1 vrefout.input['Pdif'] = Pdif vrefout.compute() Vrefin = round(vrefout.output['Vrefd'], 2) # v=v+Vrefin
def main(): i = True #thread.start_new_thread(adquisicion2,(i,)) dired = 0.1 Vdif = 0.2 v2 = 18.6 n = excel.main(float(v2), 0) n = int(n) mcpras.set_value(n) Ired2 = adquisicion2() while True: vrefout.input['dired'] = dired vrefout.input['Vdif'] = Vdif vrefout.compute() Vrefin = round(vrefout.output['Vrefd'], 2) #if Vrefin==0: #n = excel.main(float(v2),0) #n = int(n) #mcpras.set_value(n) #time.sleep(1) #P2=Node611.sensorm() #n = excel.main(float(v2-0.3),0) #n = int(n) #mcpras.set_value(n) #time.sleep(1) #P1=Node611.sensorm() #Pdif=P2-P1 #Vdif=0.2 #else: v = v2 v2 = v2 + Vrefin Vdif = v2 - v Ired = Ired2 try: n = excel.main(float(v2), 0) n = int(n) mcpras.set_value(n) except: n = excel.main(float(14.5), 0) n = int(n) mcpras.set_value(n) v2 = 14.5 time.sleep(0.2) Ired2 = adquisicion2() dired = Ired2 - Ired Vdif = round(Vdif, 2) # print("Corriente de la red t= "+str(Ired)) # print("Corriente de la red t+1 = "+str(Ired2)) print("Cambio de corriente =" + str(dired)) # print("Vref1"+str(v)) print("Vref2 = " + str(v2)) # print("diferencia de voltaje v2-v"+str(Vdif)) # print("Cambio de potencia/voltaje = "+str(dpdv)) print("Cambio de voltaje = " + str(Vrefin))
def fuzzy(): i = True #thread.start_new_thread(adquisicion2,(i,)) dIdv = 2 v2 = 18.5 n = excel.main(float(v2), 0) n = int(n) mcpras.set_value(n) Ired2 = corrienteRed() while True: vrefout.input['dIdv'] = dIdv vrefout.compute() Vrefin = round(vrefout.output['Vrefd'], 3) Vrefinabs = abs(Vrefin) #print("Corriente de la red t= "+str(Ired)) print("Corriente de la red t+1 = " + str(Ired2)) # print("Cambio de corriente ="+str(dired)) # print("Vref1"+str(v)) print("Vref2 = " + str(v2)) # print("diferencia de voltaje v2-v"+str(Vdif)) print("Cambio de corriente/voltaje = " + str(dIdv)) print("Cambio de voltaje = " + str(Vrefin)) if Vrefinabs < 0.1: if v2 < 14.6: v2 = 14.5 elif v2 > 18.5: v2 = 18.5 #dIdv=0 n = excel.main(float(v2), 0) n = int(n) mcpras.set_value(n) time.sleep(0.2) Ired = corrienteRed() n = excel.main(float(v2 + 0.1), 0) n = int(n) mcpras.set_value(n) time.sleep(0.2) Ired2 = corrienteRed() if Ired <= 1.01 * Ired2 and Ired >= 0.09 * Ired2: dIdv = 2 else: dIdv = 0 #dired=Ired2-Ired else: v2 = v2 + Vrefin Ired = Ired2 if v2 < 14.6: v2 = 14.5 elif v2 > 18.5: v2 = 18.6 n = excel.main(float(v2), 0) n = int(n) mcpras.set_value(n) time.sleep(0.2) try: Ired2 = corrienteRed() except: try: time.sleep(0.5) Ired2 = corrienteRed() except: time.sleep(0.5) Ired2 = corrienteRed() dired = Ired2 - Ired dIdv = dired / Vrefin if dIdv >= 500: dIdv = 500 elif dIdv <= -500: dIdv = -500
def fuzzy(): sw = 0 i = True #thread.start_new_thread(adquisicion2,(i,)) dpdv = 100 v2 = 18.5 dpred = 0 n = excel.main(float(v2), 0) n = int(n) mcpras.set_value(n) time.sleep(0.2) Pred2 = potenciaRed() k = 0 while True: if sw == 0: vrefout.input['dpdv'] = dpdv vrefout.compute() Vrefin = round(vrefout.output['Vrefd'], 3) Vrefinabs = abs(Vrefin) elif sw == 1: Vrefin = 0.1 sw = 0 elif sw == 2: Vrefin = -0.1 sw = 0 # print("Corriente de la red t= "+str(Ired)) # print("Corriente de la red t+1 = "+str(Pred2)) # print("Cambio de corriente ="+str(dpred)) # print("Vref1"+str(v)) # print("Vref2 = "+str(v2)) # print("diferencia de voltaje v2-v"+str(Vdif)) # print("Cambio de corriente/voltaje = "+str(dpdv)) print("Cambio de voltaje= " + str(Vrefin) + "\n") k = k + 1 v2 = v2 + Vrefin print("Vref2 = " + str(v2)) print(time.strftime("%X")) Pred = Pred2 hoja1.write(k, 0, str(v2)) hoja1.write(k, 1, time.strftime("%X")) # print(v2) if v2 < 14.6: v2 = 14.5 elif v2 > 18.5: v2 = 18.5 n = excel.main(float(v2), 0) n = int(n) mcpras.set_value(n) time.sleep(1) # try: Pred2 = potenciaRed() #except: # try: # time.sleep(0.5) # Ired2=corrienteRed() # except: # time.sleep(0.5) # Ired2=corrienteRed() dpred = Pred2 - Pred # try: if Vrefin < 0: dpdv = dpred * -10 elif Vrefin > 0: dpdv = dpred * 10 else: sw = 1 #dpdv=dpred/Vrefin # except: # sw=1 # if dpred>0.05*Pred2: # Predbck=potenciaRed() # if Predbck<0.9*Pred2 and Predbck>1.1*Pred2: # sw=1 # Pred2=Predbck # dpred=Pred2-Pred # else: # sw=1 if abs(Vrefin) < 0.09 and abs(dpdv) > 35: #dIdv=1.5 if dpdv < 0: sw = 1 else: sw = 2 if dpdv >= 500: dpdv = 500 elif dpdv <= -500: dpdv = -500