def edit_valores(self): """Funcion que edita los elementos en la base de datos del formulario""" cod = (self.edit.codigo.text()) nom = (self.edit.nombre.text()) des = (self.edit.descripcion.toPlainText()) col = (self.edit.color.text()) pre = (self.edit.precio.text()) mar = (self.edit.marca.text()) ingreso_valido = self.validar(cod, nom, des, col, pre, mar) if ingreso_valido is True: valores = [cod, nom, des, col, pre, mar] marcas = controller.obtener_marcas() if valores[5] in marcas: valores[5] = marcas.index(valores[5]) + 1 else: id_marca = len(marcas) + 1 controller.ingresar_marca(id_marca, valores[5]) valores[5] = id_marca controller.update(self.codi, valores) if self.direccion_imagen is not None: self.almacenarImagen(self.direccion_imagen, cod) self.reject() else: self.mensajeError(ingreso_valido)
def step(self, prices): """ - get what the controller would output - controller.update to pass in reward - controller initiatlization """ # get controllers points controller = self.controller controllers_points = controller.get_points(prices) end = False energy_dict = {} rewards_dict = {} for player_name in self.players_dict: # get the points output from players player = self.players_dict.get(player_name) player_energy = player.threshold_exp_response( controllers_points.numpy()) last_player_energy = player_energy energy_dict[player_name] = player_energy # get the reward from the player's output player_min_demand = player.get_min_demand() player_max_demand = player.get_max_demand() player_reward = Reward(player_energy, prices, player_min_demand, player_max_demand) player_ideal_demands = player_reward.ideal_use_calculation() last_player_ideal = player_ideal_demands # either distance from ideal or cost distance # distance = player_reward.neg_distance_from_ideal(player_ideal_demands) # print("Ideal demands: ", player_ideal_demands) # print("Actual demands: ", player_energy) reward = player_reward.scaled_cost_distance_neg( player_ideal_demands) rewards_dict[player_name] = reward total_reward = sum(rewards_dict.values()) # reward goes back into controller as controller update controller.update(total_reward, prices, controllers_points) self._timestep = self._timestep + self._time_interval if self._timestep > self._end_timestamp: self._timestep = self._start_timestamp if self.current_iter >= self.num_iters: end = True self.current_iter += 1 return controllers_points, last_player_energy, last_player_ideal, total_reward, end
def test_3_Axis(self): print "starting Axis test, press a to pass, b to fail" while True: time.sleep(0.1) cont.update() if cont.getButton(cont.A): break if cont.getButton(cont.B): self.assertEqual(True, False, "Axis Test Failed") print "X: ", cont.getPrimaryX(), " Y: ", cont.getPrimaryY(), " X2: ", cont.getSecondaryX(), " Y2: ", cont.getSecondaryY()
def test_2_buttonsWorking(self): notDone = True print "starting button test" buttons = [False, False, False, False, False, False, False, False, False, False] while notDone: cont.update() for x in range(0, 10): if cont.getButton(x) and buttons[x] == False: print "button ", x buttons[x] = True if all(buttons): notDone = False
def update(): global outputLabel cont.update() buttons1 = 0x0 buttons2 = 0x0 # going to eight would include the start button; however, it seems that when 0x80 (only the start button) is sent # the arduino lags for a second or two and reports false values for buttons for i in range(0, cont.getNumButtons()): if(cont.getButton(i)): if(cont.getValueForButton(i) <= 0xFF): buttons1 += cont.getValueForButton(i) else: buttons2 += cont.getValueForButton(i) >> 8 outbound.write("STR") # sends a signal to tell that this is the start of data outbound.write(chr(buttons1)) # writes the buttons first outbound.write(chr(buttons2)) outbound.write(str(int(cont.getPrimaryX()))) # casts the floats to ints, then to strings for simple parsing outbound.write(" ") outbound.write(str(int(cont.getPrimaryY()))) outbound.write(" ") outbound.write(str(int(cont.getSecondaryX()))) outbound.write(" ") outbound.write(str(int(cont.getSecondaryY()))) outbound.write(" ") outbound.write(str(int(cont.getTriggers()))) outbound.write(" ") counter = 10 proceed = False while True and counter > 0: counter -= 1 if outbound.readable(): if 'S' == outbound.read(1): if 'T' == outbound.read(1): if 'R' == outbound.read(1): proceed = True break if(proceed): linesToRead = int(outbound.read(3)) # allows for up to 999 lines to be read... for i in range(0, linesToRead): outputLabel['text'] = outbound.readline().rstrip() outputLabel.after(100, update)
if platform == "linux" or platform == "linux2": p = "/dev/ttyUSB0" elif platform == "darwin": p = "" elif platform == "win32": p = "3" outbound = serial.Serial( port=p, baudrate=9600, parity=serial.PARITY_NONE, # parity is error checking, odd means the message should have an odd number of 1 bits stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS # eight bits of information per pulse/packet ) cont.update() if not cont.isConnected(): print "connect the controller" cont.update() while not cont.isConnected(): cont.update() print "controller connected" # this is the main loop of the program that updates the controller then sends that modified input to the arduino while 1: cont.update() buttons1 = 0x0 buttons2 = 0x0 # going to eight would include the start button; however, it seems that when 0x80 (only the start button) is sent # the arduino lags for a second or two and reports false values for buttons for i in range(0, cont.getNumButtons()): if(cont.getButton(i)):
1, ) print("Starte 'new concept' Simulation") else: quit() controller.start() # Worker loop done = False while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True # fill the screen screen.fill((230, 230, 230)) # Do updates controller.update() # Draw stuff controller.draw() pygame.display.update() pygame.display.flip() clock.tick(60) pygame.quit()
def update(): return controller.update()
import drivers.ili9486py as disp import drivers.encoder as enc import network import ubinascii import password import utime import time import urequests as requests import ujson import machine from machine import Pin from machine import Timer import controller as con #flashing micropython: # esptool.py --chip esp32 --port COM4 erase_flash # esptool.py --chip esp32 --port COM4 write_flash -z 0x1000 esp32-idf3-20200902-v1.13.bin #copying files via ampy: # ampy --port COM4 put boot.py # ampy --port COM4 put controller.py # ampy --port COM4 put view.py # ampy --port COM4 put logic.py # ampy --port COM4 put drivers disp.init() con.init() enc.init(con.onClick, con.onLeft, con.onRight) while True: con.update() utime.sleep_ms(10)
def update(): cont.update() buttons1 = 0x0 buttons2 = 0x0 # going to eight would include the start button; however, it seems that when 0x80 (only the start button) is sent # the arduino lags for a second or two and reports false values for buttons for i in range(0, cont.getNumButtons()): if cont.getButton(i): if cont.getValueForButton(i) <= 0xFF: buttons1 += cont.getValueForButton(i) else: buttons2 += cont.getValueForButton(i) >> 8 outbound.write("STR") # sends a signal to tell that this is the start of data outbound.write(chr(buttons1)) # writes the buttons first outbound.write(chr(buttons2)) outbound.write(str(int(cont.getPrimaryX()))) # casts the floats to ints, then to strings for simple parsing outbound.write(" ") outbound.write(str(int(cont.getPrimaryY()))) outbound.write(" ") outbound.write(str(int(cont.getSecondaryX()))) outbound.write(" ") outbound.write(str(int(cont.getSecondaryY()))) outbound.write(" ") outbound.write(str(int(cont.getTriggers()))) outbound.write(" ") counter = 10 proceed = False pressureOut["bg"] = "red" voltageOut["bg"] = "red" tempOut["bg"] = "red" accelOut["bg"] = "red" depthOut["bg"] = "red" pressureLabel["bg"] = "red" voltageLabel["bg"] = "red" tempLabel["bg"] = "red" accelLabel["bg"] = "red" depthLabel["bg"] = "red" while True and counter > 0: counter -= 1 if outbound.readable(): if "S" == outbound.read(1): if "T" == outbound.read(1): if "R" == outbound.read(1): proceed = True break if proceed: linesToRead = int(outbound.read(3)) # allows for up to 999 lines to be read... for i in range(0, linesToRead // 2): label = outbound.readline().rstrip().lstrip() if label == "PSR": pressureOut["text"] = outbound.readline().rstrip() pressureOut["bg"] = "green" pressureLabel["bg"] = "green" elif label == "VLT": voltageOut["text"] = outbound.readline().rstrip() voltageOut["bg"] = "green" voltageLabel["bg"] = "green" elif label == "TMP": tempOut["text"] = outbound.readline().rstrip() tempOut["bg"] = "green" tempLabel["bg"] = "green" elif label == "ACL": accelOut["text"] = outbound.readline().rstrip() + "\n" accelOut["text"] += outbound.readline().rstrip() + "\n" accelOut["text"] += outbound.readline().rstrip() accelOut["bg"] = "green" accelLabel["bg"] = "green" elif label == "DPT": depthOut["text"] = outbound.readline().rstrip() depthOut["bg"] = "green" depthLabel["bg"] = "green" else: print "unknown datatype:", label print "data:", outbound.readline().rstrip() root.after(100, update)
def test_1_isConnected(self): cont.update() self.assertTrue(cont.isConnected(), "Controller was not found") print "controller was found"
def update(): cont.update() buttons1 = 0x0 buttons2 = 0x0 # going to eight would include the start button; however, it seems that when 0x80 (only the start button) is sent # the arduino lags for a second or two and reports false values for buttons for i in range(0, cont.getNumButtons()): if(cont.getButton(i)): if(cont.getValueForButton(i) <= 0xFF): buttons1 += cont.getValueForButton(i) else: buttons2 += cont.getValueForButton(i) >> 8 outbound.write("STR") # sends a signal to tell that this is the start of data outbound.write(chr(buttons1)) # writes the buttons first outbound.write(chr(buttons2)) outbound.write(str(int(cont.getPrimaryX()))) # casts the floats to ints, then to strings for simple parsing outbound.write(" ") outbound.write(str(int(cont.getPrimaryY()))) outbound.write(" ") outbound.write(str(int(cont.getSecondaryX()))) outbound.write(" ") outbound.write(str(int(cont.getSecondaryY()))) outbound.write(" ") outbound.write(str(int(cont.getTriggers()))) outbound.write(" ") counter = 10 proceed = False pressureOut['bg'] = "red" voltageOut['bg'] = "red" tempOut['bg'] = "red" accelOut['bg'] = "red" depthOut['bg'] = "red" pressureLabel['bg'] = "red" voltageLabel['bg'] = "red" tempLabel['bg'] = "red" accelLabel['bg'] = "red" depthLabel['bg'] = "red" while True and counter > 0: counter -= 1 if outbound.readable(): if 'S' == outbound.read(1): if 'T' == outbound.read(1): if 'R' == outbound.read(1): proceed = True break if(proceed): linesToRead = int(outbound.read(3)) # allows for up to 999 lines to be read... for i in range(0, linesToRead // 2): label = outbound.readline().rstrip().lstrip() if(label == "PSR"): pressureOut['text'] = outbound.readline().rstrip() pressureOut['bg'] = "green" pressureLabel['bg'] = "green" elif(label == "VLT"): voltageOut['text'] = outbound.readline().rstrip() voltageOut['bg'] = "green" voltageLabel['bg'] = "green" elif(label == "TMP"): tempOut['text'] = outbound.readline().rstrip() tempOut['bg'] = "green" tempLabel['bg'] = "green" elif(label == "ACL"): accelOut['text'] = outbound.readline().rstrip() + '\n' accelOut['text'] += outbound.readline().rstrip() + '\n' accelOut['text'] += outbound.readline().rstrip() accelOut['bg'] = "green" accelLabel['bg'] = "green" elif(label == "DPT"): depthOut['text'] = outbound.readline().rstrip() depthOut['bg'] = "green" depthLabel['bg'] = "green" else: print "unknown datatype:", label print "data:", outbound.readline().rstrip() root.after(100, update)
__author__ = 'johna' ports = serial_finder.serial_ports() port = serial_finder.find_port(ports) print "Using: ", port outbound = serial.Serial( port=port, baudrate=9600, parity=serial.PARITY_NONE, # parity is error checking, odd means the message should have an odd number of 1 bits stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, # eight bits of information per pulse/packet timeout=0.1 ) cont.update() if not cont.isConnected(): print "connect the controller" cont.update() while not cont.isConnected(): cont.update() print "controller connected" root = tk.Tk() root.title("Cal Poly Control Center") pressureLabel = tk.Label(root, fg="black", background='white', text="Pressure: ") pressureOut = tk.Label(root, fg="black", background="white") voltageLabel = tk.Label(root, fg="black", background='white', text="Voltage: ") voltageOut = tk.Label(root, fg="black", background="white") accelLabel = tk.Label(root, fg="black", background='white', text="Acceleration: ")
def update_after_request(response): controller.update() # print("Database updated.") # print(response.data) return response