Beispiel #1
0
def enviar(comando,ser): #función enviar , recibe el caracter a enviar (comando) y el
    objeto serial (ser) que puede hacer referencia tanto al mega como al esp32
    ser.write(bytes(comando,'utf-8'))#escribe en el serial el comando
    print('enviado',comando)
    while (not ser.read().decode('utf-8')=='F'): #mientras no reciba una 'F' no sale de este bucle
        print('Ejecutando accion')
    print('F')
 def run(self):
     global voluto
     integrale = 0
     derivata = 0
     errore = 10
     while ((1) and not self.event.is_set()):
         errore = (voluto) - dato
         derivata = errore - derivata
         integrale = integrale + errore
         if (integrale < -windup):
             integrale = -windup
         if (integrale > windup):
             integrale = windup
         valore = (prop * voluto) - (kp * errore) - (ki * integrale) - (
             kd * derivata)
         #print(valore)
         derivata = errore
         if (valore < 0):
             valore = 45
         if (valore > 255):
             valore = 255
         valore = valore
         valore = int(valore)
         #print(valore)
         serial(valore)
         time.sleep(0.01)
def main(e):
    if e.display:
        # Now we can connect a client to the server
        client(e)

    elif e.stream:
        # Now we can run the server
        server(e)

    elif e.serial:
        serial(e)

    else:
        writer(e, force=True)
def main(e):
    if e.display:
        # Now we can connect a client to the server
        client(e)

    elif e.stream:
        # Now we can run the server
        server(e)

    elif e.serial:
        serial(e)

    else:
        writer(e, force=True)
Beispiel #5
0
 def _queueJobsInQueue(self, queue, quota_names, job_infos, serialize=True,
                       begin_by=None, begin_after=None):
     """Queue multiple jobs in the specified queue."""
     scheduled = [self.wrapJob(job_info) for job_info in job_infos]
     if serialize:
         job = serial(*scheduled)
     else:
         job = parallel(*scheduled)
     return self.__queueJobInQueue(begin_by, begin_after,
                                   queue, quota_names, job)
Beispiel #6
0
    def timedRead(self, timeout):
        sera = serial()
        start_time = time.time()
        while (time.time() - start_time < timeout):
            c = sera.read()
            if c >= 0:
                self.result = c
            else:
                self.result = -1

            return self.result
Beispiel #7
0
	def update(self):
		if self.lectura1 == True:
			i = 0
			for i in range(10):
				ch1, ch2, chd1, chd2 = serial()
				self.pch1.extend(ch1)
				self.pch2.extend(ch2)
				self.pchd1.extend(chd1)
				self.pchd2.extend(chd2)
			self.lectura1=False
		else:
			del self.pch1[:200]
			del self.pch2[:200]
			del self.pchd1[:200]
			del self.pchd2[:200]
			ch1, ch2, chd1, chd2 = serial()
			self.pch1.extend(ch1)
			self.pch2.extend(ch2)
			self.pchd1.extend(chd1)
			self.pchd2.extend(chd2)

		zero = np.zeros(2000)
		if self.c1 == True:
			self.trace("CH1",self.t,self.pch1,'y')
		else:
			self.trace("CH1",self.t,zero,'k')
		if self.c2 == True:
			self.trace("CH2",self.t,self.pch2,'r')
		else:
			self.trace("CH2",self.t,zero,'k')
		if self.cd1 == True:
			self.trace("CHD1",self.t,self.pchd1,'y')
		else:
			self.trace("CHD1",self.t,zero,'k')
		if self.cd2 == True:
			self.trace("CHD2",self.t,self.pchd2,'r')
		else:
			self.trace("CHD2",self.t,zero,'k')
Beispiel #8
0
 def run(self):
     global voluto
     selettore=0
     while((1) and not self.event.is_set()):
             selettore+=1
             selettore=selettore%2
             if(selettore==0):
                  if(ASX.voluto==0):
                     serial(0,0)
                     ASX.integrale=0
                 else:
                     ASX.errore=ASX.voluto-ASX.enc
                     ASX.derivata=ASX.errore-ASX.derivata
                     ASX.integrale=ASX.integrale+ASX.errore
                     if(ASX.integrale<-windup):
                         ASX.integrale=0
                     if(ASX.integrale>windup):
                         ASX.integrale=0
                     ASX.valore=(prop*ASX.voluto)-(kp*ASX.errore)-(ki*ASX.integrale)-(kd*ASX.derivata)
                     ASX.derivata=ASX.errore
                     if(ASX.valore<0):
                        ASX.valore=0
                     if(ASX.valore>255):
                         ASX.valore=255
                     ASX.valore=int(ASX.valore)
                     serial(ASX.valore,0)
                     time.sleep(0.01)
             if(selettore==1):
                  if(ADX.voluto==0):
                     serial(0,1)
                     ADX.integrale=0
                 else:
                     ADX.errore=ADX.voluto-ADX.enc
                     ADX.derivata=ADX.errore-ADX.derivata
                     ADX.integrale=ADX.integrale+ADX.errore
                     if(ADX.integrale<-windup):
                         ADX.integrale=0
                     if(ADX.integrale>windup):
                         ADX.integrale=0
                     ADX.valore=(prop*ADX.voluto)-(kp*ADX.errore)-(ki*ADX.integrale)-(kd*ADX.derivata)
                     ADX.derivata=ADX.errore
                     if(ADX.valore<0):
                        ADX.valore=0
                     if(ADX.valore>255):
                         ADX.valore=255
                     ADX.valore=int(ADX.valore)
                     serial(ADX.valore,1)
                     time.sleep(0.01)
Beispiel #9
0
 def _queueJobsInQueue(self, queue, quota_names, job_infos, serialize=True):
     """Queue multiple jobs in the specified queue."""
     portal = getUtility(ISiteRoot)
     portal_path = portal.getPhysicalPath()
     uf_path, user_id = _getAuthenticatedUser()
     scheduled = []
     for (func, context, args, kwargs) in job_infos:
         context_path = context.getPhysicalPath()
         job = Job(_executeAsUser, context_path, portal_path, uf_path, user_id,
                   func, *args, **kwargs)
         scheduled.append(job)
     if serialize:
         job = serial(*scheduled)
     else:
         job = parallel(*scheduled)
     if quota_names:
         job.quota_names = quota_names
     job = queue.put(job)
     job.addCallbacks(success=job_success_callback,
                      failure=job_failure_callback)
     return job
Beispiel #10
0
 def _queueJobsInQueue(self, queue, quota_names, job_infos, serialize=True):
     portal = getUtility(ISiteRoot)
     portal_path = portal.getPhysicalPath()
     pm = getToolByName(portal, 'portal_membership')
     user = pm.getAuthenticatedMember()
     user_id = user.getId()
     uf_path = user.aq_parent.aq_parent.getPhysicalPath()
     scheduled = []
     for (func, context, args, kwargs) in job_infos:
         context_path = context.getPhysicalPath()
         job = Job(_executeAsUser, portal_path, context_path, user_id,
                   uf_path, func, *args, **kwargs)
         scheduled.append(job)
     if serialize:
         job = serial(*scheduled)
     else:
         job = parallel(*scheduled)
     if quota_names:
         job.quota_names = quota_names
     job = queue.put(job)
     job.addCallbacks(success=job_success_callback,
                      failure=job_failure_callback)
     return job
Beispiel #11
0
class asciirw:
    _platform = 'WIN'
    ser = serial()

    def __init__(self):
        pass

    def __init__(self, platform, portName, baudrate, parity, stopbit,
                 databits):

        config = ConfigParser.ConfigParser()
        config.read('./App_V100/app.config')

        self._platform = platform
        log.debug(self._platform + " Selected")

        self.InitializeSerialPort()

    def InitializeSerialPort(self):
        self.ser = serial.Serial(self.portName)
        self.ser.baudrate = self.baudrate
        self.ser.parity = self.parity
        self.ser.stopbits = self.stopbit
        self.ser.bytesize = self.databits
Beispiel #12
0
import serial

port = serial('/dev/cu.wchusbserial14310', basestring=115200, timeout=3.0)

port.write('2')
Beispiel #13
0
spd1 = '1SP' #y-axis
spd2 = '2SP' #x-axis

a = '1la-' #Position header for Y-axis
c = '2la' #Position header for X-axis

Yspd = spd1+str(spdy)
Xspd = spd2+str(spdx)

############################################################
###########        Create Serial Object         ############
############################################################

# CREATE SERIAL OBJECT
s = serial('COM8') #create serial object
s.InputBufferSize = 8388608
fopen(s) #connect to serial object


############################################################
#############         Initialisation          ##############
############################################################

fprintf(s,'JMP2') #Homing Sequence/Initialise
pause(5)
fprintf(s,Xspd) #set X-axis speed to user's choice
fprintf(s,Yspd) #set Y-axis speed to user's choice

############################################################
#############            Counters             ##############
Beispiel #14
0
		if name in self.traces:
			self.traces[name].setData(dataset_x,dataset_y)
		else:
			self.traces[name] = self.Canvas.plot(pen=color) 
			#self.traces[name] = self.Canvas.plot(pen=color,symbolBrush=color,symbolPen=color) #Observar puntos de muestreo

<<<<<<< HEAD
	def update(self): #Actualizar datos
		if self.lectura1 == True: #Primera lectura debe leer 10 veces del serial
=======
	def update(self):                            
		if self.lectura1 == True:            #Bucle para la lectura de los datos                    
>>>>>>> af475479ea6477ac383016e753278b9a4c80517d
			i = 0
			for i in range(10):
				ch1, ch2, chd1, chd2 = serial()
				self.pch1.extend(ch1)
				self.pch2.extend(ch2)
				self.pchd1.extend(chd1)
				self.pchd2.extend(chd2)
			self.lectura1=False
		else: #Siguientes lecturas: eliminar los 200 datos más viejos y leer nuevos
			del self.pch1[:200]
			del self.pch2[:200]
			del self.pchd1[:200]
			del self.pchd2[:200]
			ch1, ch2, chd1, chd2 = serial()
			self.pch1.extend(ch1)
			self.pch2.extend(ch2)
			self.pchd1.extend(chd1)
			self.pchd2.extend(chd2)
Beispiel #15
0
import matplotlib.pyplot as plt
from math import pi
import serial

ser = serial('/dev/ttyUSB0', 115200)

f = open('dump.csv', 'r')

lines = f.readlines()

# remove picocom output,
# strip windows line endings,
# split by comma,
# remove failures,
# and turn into numbers
# sort
# split into to lists
lines = lines[2:-25]
lines = [e[:-2] for e in lines]
lines = [e.split(',')  for e in lines]
lines = [e for e in lines if e[1]!='failure']
lines = [[int(e[0]), int(e[1])] for e in lines]
lines.sort()
t = [e[0] for e in lines]
r = [e[1] for e in lines]

# reduce it to one value for each theta
data = []
i = 0
while i < len(r):
    rsum = 0
 def run(self):
     global voluto, direzione
     sel = 0
     NPD = 2
     NAD = 0
     NPS = 3
     NAS = 1
     contatore = 0
     while ((1) and not self.event.is_set()):
         if (sel == 0):
             if (AS.voluto == 0):
                 serial(0, 2, AS.direzione)
                 integrale = 0
             else:
                 AS.errore = AS.voluto - AS.enc
                 AS.derivata = AS.errore - AS.derivata
                 AS.integrale = AS.integrale + AS.errore
                 if (AS.integrale < -windup):
                     AS.integrale = -windup
                 if (AS.integrale > windup):
                     AS.integrale = windup
                 AS.valore = (prop * voluto) - (kp * AS.errore) - (
                     ki * AS.integrale) - (kd * AS.derivata)
                 AS.derivata = AS.errore
                 if (AS.valore < 0):
                     AS.valore = 0
                 if (AS.valore > 255):
                     AS.valore = 255
                 AS.valore = int(AS.valore)
                 serial(AS.valore, NAS, AS.direzione)
                 #print(AS.valore)
         if (sel == 1):
             if (AD.voluto == 0):
                 serial(0, 3, AS.direzione)
                 integrale = 0
             else:
                 AD.errore = AD.voluto - AD.enc
                 AD.derivata = AD.errore - AD.derivata
                 AD.integrale = AD.integrale + AD.errore
                 if (AD.integrale < -windup):
                     AD.integrale = -windup
                 if (AD.integrale > windup):
                     AD.integrale = windup
                 AD.valore = (prop * voluto) - (kp * AD.errore) - (
                     ki * AD.integrale) - (kd * AD.derivata)
                 AD.derivata = AD.errore
                 if (AD.valore < 0):
                     AD.valore = 0
                 if (AD.valore > 255):
                     AD.valore = 255
                 AD.valore = int(AD.valore)
                 serial(AD.valore, NAD, AS.direzione)
         if (sel == 2):
             if (PS.voluto == 0):
                 serial(0, 0, AS.direzione)
                 integrale = 0
             else:
                 PS.errore = PS.voluto - PS.enc
                 PS.derivata = PS.errore - PS.derivata
                 PS.integrale = PS.integrale + PS.errore
                 if (PS.integrale < -windup):
                     PS.integrale = -windup
                 if (PS.integrale > windup):
                     PS.integrale = windup
                 PS.valore = (prop * voluto) - (kp * PS.errore) - (
                     ki * PS.integrale) - (kd * PS.derivata)
                 PS.derivata = PS.errore
                 if (PS.valore < 0):
                     PS.valore = 0
                 if (PS.valore > 255):
                     PS.valore = 255
                 PS.valore = int(PS.valore)
                 serial(PS.valore, NPS, AS.direzione)
                 #print(PS.valore)
         if (sel == 3):
             if (PD.voluto == 0):
                 serial(0, 1, AS.direzione)
                 integrale = 0
             else:
                 PD.errore = PD.voluto - PD.enc
                 PD.derivata = PD.errore - PD.derivata
                 PD.integrale = PD.integrale + PD.errore
                 if (PD.integrale < -windup):
                     PD.integrale = -windup
                 if (PD.integrale > windup):
                     PD.integrale = windup
                 PD.valore = (prop * voluto) - (kp * PD.errore) - (
                     ki * PD.integrale) - (kd * PD.derivata)
                 PD.derivata = PD.errore
                 if (PD.valore < 0):
                     PD.valore = 0
                 if (PD.valore > 255):
                     PD.valore = 255
                 PD.valore = int(PD.valore)
                 serial(PD.valore, NPD, AS.direzione)
                 #print(PD.valore)
                 contatore += 1
                 if (((contatore % 50) == 0) and (AD.voluto != 0)):
                     head, roll, pitch = bno.read_euler()
                     if ((pitch > 5) or (pitch < -5)):
                         setta(2700, dati.direzione)
                     else:
                         setta(1600, dati.direzione)
         time.sleep(0.001)
         sel += 1
         sel = sel % 4
Beispiel #17
0
import matplotlib.pyplot as plt
from math import pi
import serial

ser = serial('/dev/ttyUSB0', 115200)

f = open('dump.csv', 'r')

lines = f.readlines()

# remove picocom output,
# strip windows line endings,
# split by comma,
# remove failures,
# and turn into numbers
# sort
# split into to lists
lines = lines[2:-25]
lines = [e[:-2] for e in lines]
lines = [e.split(',') for e in lines]
lines = [e for e in lines if e[1] != 'failure']
lines = [[int(e[0]), int(e[1])] for e in lines]
lines.sort()
t = [e[0] for e in lines]
r = [e[1] for e in lines]

# reduce it to one value for each theta
data = []
i = 0
while i < len(r):
    rsum = 0
            if CSV: print x, ",", y, ",", maxRadius, ",", circles.total, ",", time.time()

            if len(last_xs) == 5: del last_xs[0] # Remove first item
            last_xs.append(x)
            if len(last_ys) == 5: del last_ys[0] # Remove first item
            last_ys.append(y)
 
            if abs(average(last_xs)-x) > 40: # Then x is probably a bad measurement 
                x = average(last_xs)
                if DEBUG: print "ball fixed:",x,",",y
            if abs(average(last_ys)-y) > 40: # Then y is probably a bad measurement 
                y = average(last_ys)
                if DEBUG: print "ball fixed:",x,",",y
            

            # Communicate commands or location via serial cable
            if x > 320:
                # Copter must move right
               serial("ROLL","RIGHT")
            elif x < 320:
               serial("ROLL","LEFT")

            if y > 240:
                # Copter must move backwards 
               serial("PITCH","FORWARD")
            elif y < 240:
               serial("PITCH","BACK")

copter.close()
# Stop taking frames from camera
Beispiel #19
0
        self.add_event('select_prompt', r'Make an entry \[[a-z]-[a-z],x\/X\]:.*', self._select_prompt)

        self.start()

    def _select_prompt(self, name, data):
        pass

    def get_motor_calibration(self, mode='raw'):
        """
        :description: Request and retrieve the display data for the motor calibration.  This is a blocking call.
        :return:
        """
        self.execute('d', 'a')
        return self._data

dh = DisplayHandler(serial=serial(port='/dev/ttyACM0', baud=115200))
raw_data = dh.get_motor_calibration()
parsed_data = dh.get_motor_calibration(mode='parsed')


if __name__ == '__main__':
    def wait():
        #global finished_count
        global prompt_received
        #while finished_count < 2:
        while not prompt_received:
            print prompt_received
            time.sleep(0.001)
    
    def reset():
        global finished_count
Beispiel #20
0
"""
acreroad_1420 Drive software

Software designed to drive the 1420 MHz telescope on the roof of the
Acre Road observatory. This class interacts with "qp", the telescope
drive software by Norman Gray (https://bitbucket.org/nxg/qp) via a
serial (USB) interface.

The serial interfacing is done through pySerial.

Parameters
----------

device : str
   The name of the unix device which the drive is connected to
port : int
   The port number of the drive
simulate : bool
   A boolean flag to set the drive in simulation mode
   (the class does not connect to the controller in simulation mode)


"""

import re, datetime, time
import ConfigParser
import numpy as np
import astropy
from astropy.coordinates import SkyCoord, ICRS, EarthLocation, AltAz
import astropy.units as u
Beispiel #21
0
from mosquitto import
from serial import 
from random import



Board = serial ("/dev/cu.usbmodemfd111",9600, timeout=2)


client = mosquitto("Courtney090")

client.connect("10.212.62.136")

client.subscribe("/Lights")

def messageRecieved (broker, obj, msg):
    payload = msg.payload.decode()
    print("MESSAGE "+ msg.topic + " CONTAINING:" + payload)
    
    
    if (payload == "ON"):
        message= "1"
    if (payload == "OFF"):
        message= "0"
    board.write(message.encode())
    

    
client.on_message= messageRecieved

import serial
ser = serial('/dev/ttyUSB0', 9600)
# to read a single byte
data = ser.read()


# Neo4j and Cypher using Py2Neo.
results = News.objects.todays_news()
for r in results:
    article = graph.merge_one("NewsArticle", "news_id", r)
    if 'LOCATION' in results[r].keys():
        for loc in results[r]['LOCATION']:
            loc = graph.merge_one("Location", "name", loc)
            try:
                rel = graph.create_unique(Relationship(article, "about_place", loc))
            except Exceptione:
                print(e)

# Autocomplete on News Title
def get_auticomplete(text):
    query = """
    start n = node(*) where n.name =~ '(?i)%s.*' return n.name,labels(n) limit 10;
    """
    query = query % (text)
    obj = []
    for res in graph.cypher.executed(query):
        obj.append({'name':res[0],'entity_type':res[1]})
        return res

#Templets in python
from string import Template
import sys
import serial
import threading

ser = serial('/dev/ttyUSB0', baudrate=9600, timeout=1)

while True:
    input_string = ser.readline().decode()
    radar = int(input_string)

    input_string = ser.readline().decode()
    IR_data = int(input_string)

    print(radar)
    print(IR_data)
    print()
Beispiel #24
0
    print( 'Logging to /tmp/'+myName+'.log')
    rh = logging.handlers.RotatingFileHandler( '/tmp/'+myName+'.log',
                 maxBytes=10000000, backupCount=1 )
    rh.setFormatter( fmt )
    log.addHandler( rh )

# create mqtt client
mqttC = mqtt.Client(client_id="jee2mqtt")
mqttC.isConnected = False
mqttC.on_connect = on_connect
mqttC.on_message = on_mqtt
mqttC.on_subscribe = on_subscribe
mqttC.on_log = on_log
mqttC.loop_start()        # create rx/tx thread in background
try:
    mqttC.connect( args.mqtt_server, args.mqtt_port, 10)
except:
    log.error("Failed to connect to mqtt server. Retry in 2 secs ....")
while not mqttC.isConnected:
    time.sleep(1)           # wait till mqtt server arrives.

try:
    # start serial coroutine
    s = serial( args.serial_port, args.serial_baudrate )
    asyncio.run( s.main() )
except KeyboardInterrupt:
    time.sleep(2)
    mqttC.loop_stop()
    print("Terminated")

Beispiel #25
0
 def run(self):
     global voluto, direzione
     sel = 0
     NPD = 2
     NAD = 0
     NPS = 3
     NAS = 1
     while ((1) and not self.event.is_set()):
         if (sel == 0):
             if (AS.voluto == 0):
                 serial(0, 2, AS.direzione)
                 integrale = 0
             else:
                 AS.errore = AS.voluto - AS.enc
                 AS.derivata = AS.errore - AS.derivata
                 AS.integrale = AS.integrale + AS.errore
                 if (AS.integrale < -windup):
                     AS.integrale = -windup
                 if (AS.integrale > windup):
                     AS.integrale = windup
                 AS.valore = (prop * voluto) - (kp * AS.errore) - (
                     ki * AS.integrale) - (kd * AS.derivata)
                 AS.derivata = AS.errore
                 if (AS.valore < 0):
                     AS.valore = 0
                 if (AS.valore > 255):
                     AS.valore = 255
                 AS.valore = int(AS.valore)
                 serial(AS.valore, NAS, AS.direzione)
                 #print(AS.valore)
         if (sel == 1):
             if (AD.voluto == 0):
                 serial(0, 3, AS.direzione)
                 integrale = 0
             else:
                 AD.errore = AD.voluto - AD.enc
                 AD.derivata = AD.errore - AD.derivata
                 AD.integrale = AD.integrale + AD.errore
                 if (AD.integrale < -windup):
                     AD.integrale = -windup
                 if (AD.integrale > windup):
                     AD.integrale = windup
                 AD.valore = (prop * voluto) - (kp * AD.errore) - (
                     ki * AD.integrale) - (kd * AD.derivata)
                 AD.derivata = AD.errore
                 if (AD.valore < 0):
                     AD.valore = 0
                 if (AD.valore > 255):
                     AD.valore = 255
                 AD.valore = int(AD.valore)
                 serial(AD.valore, NAD, AS.direzione)
         if (sel == 2):
             if (PS.voluto == 0):
                 serial(0, 0, AS.direzione)
                 integrale = 0
             else:
                 PS.errore = PS.voluto - PS.enc
                 PS.derivata = PS.errore - PS.derivata
                 PS.integrale = PS.integrale + PS.errore
                 if (PS.integrale < -windup):
                     PS.integrale = -windup
                 if (PS.integrale > windup):
                     PS.integrale = windup
                 PS.valore = (prop * voluto) - (kp * PS.errore) - (
                     ki * PS.integrale) - (kd * PS.derivata)
                 PS.derivata = PS.errore
                 if (PS.valore < 0):
                     PS.valore = 0
                 if (PS.valore > 255):
                     PS.valore = 255
                 PS.valore = int(PS.valore)
                 serial(PS.valore, NPS, AS.direzione)
                 #print(PS.valore)
         if (sel == 3):
             if (PD.voluto == 0):
                 serial(0, 1, AS.direzione)
                 integrale = 0
             else:
                 PD.errore = PD.voluto - PD.enc
                 PD.derivata = PD.errore - PD.derivata
                 PD.integrale = PD.integrale + PD.errore
                 if (PD.integrale < -windup):
                     PD.integrale = -windup
                 if (PD.integrale > windup):
                     PD.integrale = windup
                 PD.valore = (prop * voluto) - (kp * PD.errore) - (
                     ki * PD.integrale) - (kd * PD.derivata)
                 PD.derivata = PD.errore
                 if (PD.valore < 0):
                     PD.valore = 0
                 if (PD.valore > 255):
                     PD.valore = 255
                 PD.valore = int(PD.valore)
                 serial(PD.valore, NPD, AS.direzione)
                 #print(PD.valore)
         time.sleep(0.001)
         sel += 1
         sel = sel % 4
Beispiel #26
0
	def update(self): #Actualizar datos
		if self.cont == 6:
			self.cont = 0
		if self.lectura1 == True: #Primera lectura debe leer 10 veces del serial
			i = 0
			for i in range(20):
				ch1, chd1, chd2, rms = serial()
				self.pch1.extend(ch1)
			self.lectura1=False
		else: #Siguientes lecturas: eliminar los 200 datos más viejos y leer nuevos
			del self.pch1[:100]
			ch1, chd1, chd2, rms = serial()
			self.pch1.extend(ch1)


		zero = np.zeros(2000)
		if not chd1:
			self.trace("CH1",self.t,self.pch1,'b')
		#Conversion 
			RMS = ((((rms/100))**(0.5))/0.0063
			#RMS = rms/(100*31*0.0063)
			if self.Maximo < RMS:
				self.Maximo = RMS

		if self.cont == 0:
			if chd2:
				display = self.Maximo
				self.Display.display(display)
				if not chd1:
					self.Maximo = 0
				print(display)
			else: 
				display = 20*math.log10(self.Maximo)   #REVISAR LA CONVERSION
				self.Display.display(display)
				if not chd1:
					self.Maximo = 0
				print(display)
		self.cont = self.cont + 1

		


	def animation(self): #Timer de actualizacion
		timer = QtCore.QTimer()
		timer.timeout.connect(self.update)
		timer.start(45) #De usarse symbolBrush y symbolPen cambiar el tiempo a 0.5 o menos, ya que tarda mucho en graficar y el buffer se llena, sino dejarlo en 90
		self.start()


	#FUNCION PERILLA DE VOLTAJE
	def changebasevolt(self):
		value = self.PerillaAmp.value()
		if value == 1:
			axisY = [(0.9,'0.9'),(1.2,'1.2'),(1.8,'1.8'),(2.1,'2.1')]
			self.CaxisY.setTicks([axisY])
			self.Canvas.setYRange(0.9, 2.1, 0)
		elif value == 2:
			axisY = [(0,'0'),(1,'1'),(2,'2'),(3,'3')]
			self.CaxisY.setTicks([axisY])
			self.Canvas.setYRange(0, 3, 0)
		elif value == 3:
			axisY = [(0,'0'),(3*1,'3'),(3*2,'6'),(3*3,'9')]
			self.CaxisY.setTicks([axisY])
			self.Canvas.setYRange(0, 3*3, 0)

	#FUNCION PERILLA DE TIEMPO
	def changebasetime(self):
		value = self.PerillaTiempo.value()
		if value == 1:
			self.Canvas.setXRange(0, 1, 0)
		elif value == 2:
			n = 1/10
			self.Canvas.setXRange(1-n, 1, 0)
		elif value == 3:
			n = 1/100
			self.Canvas.setXRange(0.998-n, 0.998, 0)
		elif value == 4:
			n = 1/1000
			self.Canvas.setXRange(0.9994-n, 0.9994, 0)


if __name__ == '__main__':
	app = QtGui.QApplication(sys.argv)
	window = MyApp()
	window.show()
	window.animation()
	sys.exit(app.exec_())     
import serial
#import RPi.GPIO as GPIO
import time
from guizero import App, Combo, Text, CheckBox, ButtonGroup, PushButton, info, TextBox

ser = serial("/dev/ttyACM0",
             9600)  #change ACM number as found from ls /dev/tty/ACM*
ser.baudrate = 9600

##def do_booking():
##    info("Booking", "Thank you for booking")
##    print(film_choice.value)
##    print(vip_seat.value)
##    print(row_choice.value)

serr = ser.readline()


def LeftRoom():
    info("Lights on", "Keep Exploring")
    if light_choiceL.value == "On":
        ser.write(b'9')
    if light_choiceL.value == "Off":
        ser.write(b'X')


def RightRoom():
    info("Lights on", "Keep Exploring")
    if light_choiceR.value == "On":
        ser.write(b'8')
    if light_choiceR.value == "Off":
 def run(self):
     global voluto,direzione
     sel=0
     NPD=2
     NAD=0
     NPS=3
     NAS=1
     cont=0
     errore_h=0
     kp_h=10
     kd_h=10
     derivata_h=0
     ki_h=0
     correzione=0
     integrale_h=0
     while((1) and not self.event.is_set()):
         if(sel==0):
             if(AS.voluto==0):
                 serial(0,2,AS.direzione)
                 integrale=0
                 errore_h=0
                 correzione=0
                 integrale_h=0
             else:
                 AS.errore=AS.voluto-AS.enc
                 AS.derivata=AS.errore-AS.derivata
                 AS.integrale=AS.integrale+AS.errore
                 if(AS.integrale<-windup):
                     AS.integrale=-windup
                 if(AS.integrale>windup):
                     AS.integrale=windup
                 AS.valore=(prop*voluto)-(kp*AS.errore)-(ki*AS.integrale)-(kd*AS.derivata)
                 AS.derivata=AS.errore
                 if(AS.valore<0):
                    AS.valore=0
                 if(AS.valore>255):
                     AS.valore=255
                 AS.valore=int(AS.valore)
                 serial(AS.valore,NAS,AS.direzione)
                 #print(AS.valore)
         if(sel==1):
             if(AD.voluto==0):
                 serial(0,3,AS.direzione)
                 integrale=0
             else:
                 AD.errore=AD.voluto-AD.enc
                 AD.derivata=AD.errore-AD.derivata
                 AD.integrale=AD.integrale+AD.errore
                 if(AD.integrale<-windup):
                     AD.integrale=-windup
                 if(AD.integrale>windup):
                     AD.integrale=windup
                 AD.valore=(prop*voluto)-(kp*AD.errore)-(ki*AD.integrale)-(kd*AD.derivata)
                 AD.derivata=AD.errore
                 if(AD.valore<0):
                    AD.valore=0
                 if(AD.valore>255):
                     AD.valore=255
                 AD.valore=int(AD.valore)
                 serial(AD.valore,NAD,AS.direzione)
         if(sel==2):
             if(PS.voluto==0):
                 serial(0,0,AS.direzione)
                 integrale=0
             else:
                 PS.errore=PS.voluto-PS.enc
                 PS.derivata=PS.errore-PS.derivata
                 PS.integrale=PS.integrale+PS.errore
                 if(PS.integrale<-windup):
                     PS.integrale=-windup
                 if(PS.integrale>windup):
                     PS.integrale=windup
                 PS.valore=(prop*voluto)-(kp*PS.errore)-(ki*PS.integrale)-(kd*PS.derivata)
                 PS.derivata=PS.errore
                 if(PS.valore<0):
                    PS.valore=0
                 if(PS.valore>255):
                     PS.valore=255
                 PS.valore=int(PS.valore)
                 serial(PS.valore,NPS,AS.direzione)
                 #print(PS.valore)
         if(sel==3):
             if(PD.voluto==0):
                 serial(0,1,AS.direzione)
                 integrale=0
             else:
                 PD.errore=PD.voluto-PD.enc
                 PD.derivata=PD.errore-PD.derivata
                 PD.integrale=PD.integrale+PD.errore
                 if(PD.integrale<-windup):
                     PD.integrale=-windup
                 if(PD.integrale>windup):
                     PD.integrale=windup
                 PD.valore=(prop*voluto)-(kp*PD.errore)-(ki*PD.integrale)-(kd*PD.derivata)
                 PD.derivata=PD.errore
                 if(PD.valore<0):
                    PD.valore=0
                 if(PD.valore>255):
                     PD.valore=255
                 PD.valore=int(PD.valore)
                 serial(PD.valore,NPD,AS.direzione)
                 #print(PD.valore)
         cont+=1
         if(((cont%50)==0) and (dati.state==True) and (AS.voluto!=0)): 
             temp, roll, pitch = bno.read_euler()
             errore_h=dati.HEADM-temp
             #print(correzione)
             if(dati.counter!=0):
                 integrale_h=integrale_h+errore_h
                 derivata_h=-errore_h+derivata_h
                 correzione=(errore_h*kp_h)+(integrale_h*ki_h)+(derivata_h*kd_h)
                 derivata_h=errore_h
                 #print(correzione)
                 if(errore_h<0):
                     #print("verso sinistra")
                     AS.voluto=dati.voluto
                     PS.voluto=dati.voluto
                     AD.voluto=AD.voluto+correzione
                     PD.voluto=AD.voluto+correzione
                 else:
                     #print("verso destra")
                     AD.voluto=dati.voluto
                     PD.voluto=dati.voluto
                     AS.voluto=AS.voluto-correzione
                     PS.voluto=AS.voluto-correzione
             else:
                 if(errore_h>-90):
                     integrale_h=integrale_h+errore_h
                     derivata_h=-errore_h+derivata_h
                     correzione=(errore_h*kp_h)+(integrale_h*ki_h)+(derivata_h*kd_h)
                     derivata_h=errore_h
                     #print("verso sinistra")
                     AD.voluto=dati.voluto
                     PD.voluto=dati.voluto
                     AS.voluto=AS.voluto-correzione
                     PS.voluto=PS.voluto-correzione
                 elif(errore_h<-270):
                     errore_h=errore_h+360
                     integrale_h=integrale_h+errore_h
                     derivata_h=-errore_h+derivata_h
                     correzione=(errore_h*kp_h)+(integrale_h*ki_h)+(derivata_h*kd_h)
                     derivata_h=errore_h
                     #print(correzione)
                     #print("verso destra")
                     AS.voluto=dati.voluto
                     PS.voluto=dati.voluto
                     AD.voluto=AD.voluto+correzione
                     PD.voluto=PD.voluto+correzione
         time.sleep(0.001)
         sel+=1
         sel=sel%4