Projecte d'interfície d'usuari per a l'adquisició de dades en el Laboratori de control
Full text
PROJECTE FINAL DE CARRERA Projecte d'interfície d'usuari per a l'adquisició de dades en el Laboratori de control Grau en enginyeria d’electrònica industrial i automàtica Projectista: Ignacio Gonzàlez Valero Director: Ramon Comasólivas Font Data: Juny 2015
2 Índex 1. Introducció 1.1. Definició del projecte 1.2. Targeta d’adquisició 1.2.1. Actual al laboratori 1.2.2. Exploració d’altres opcions 1.3. Eines utilitzades de Matlab 1.3.1. Guide 1.3.2. Simulink 1.3.3. Script 1.3.4. Ident 2. Estructura del programa 2.1. Introducció al CIC 2.2. Diagrama de blocs i flux 2.3. Explicació i funcionalitats 2.3.1. Comunicació 2.3.2. Identificació 2.3.3. Control 3. Conclusions 4. Pressupost 5. Bibliografia 6. Annexos 6.1. Annex 1: Aspectes pràctics Guide 6.2. Annex 2: Aspectes pràctics Ident 6.3. Annex 3: Ús del CIC 6.4. Annex 4: Incidències 6.5. Datasheet PCI1711 d’Advantech 6.6. Models Simulink 6.7. Interfícies gràfiques Guide p. 3 p. 3 p. 5 p. 5 p. 10 p. 11 p. 11 p. 11 p. 12 p. 13 p. 14 p. 14 p. 17 p. 19 p. 19 p. 40 p. 55 p. 64 p. 66 p. 67 p. 68 p. 69 p. 75 p. 77 p. 78 p. 79 p. 80 p. 83
3 1. Introducció: 1.1. Definició projecte: El TR11 és l’edifici de sistemes, d’automàtica e informàtica industrial, utilitzat tant per l’EET com per l’ETSEIAT en pràctiques docent per alumnes de Grau i Master. A la primera planta trobem el laboratori de control, que consta de 13 estacions de treballs amb els seus respectius ordinadors i targetes d’adquisicions de dades d’Advantech. Les estacions són motors elèctric o bombes d’aigua. Aquestes estacions de treball (de l’empresa alecop) venen preparades amb mòduls per tal de controlar aquesta, mitjançant ports d’entrada i sortida, els quals s’utilitzen per comunicar amb les targetes d’adquisició de dades les quals es poden comunicar amb l’ordinador mitjançant Matlab. En aquest laboratori de control d’ESAII, es proposa una millora de l’actual interfície d’adquisició i de monitorització dels senyals, que ha de permetre també fer el control dels processos de laboratori i canviar els paràmetres de forma còmoda per l’usuari. Actualment, l’adquisició dels senyals al laboratori de control del TR11, es fa mitjançant la targeta PCI1711 d’Advantech. Amb l’ajuda del Simulink en mode extern i el Real- Time Windows Target podem establir una comunicació entre l’ordinador i l’estació de treball. El fitxer que s’utilitza es troba al directori K:\TEST_19_enero_2015 i s’anomena test.mdl. Aquest fitxer està preparat per versions de Simulink 7.0 o posteriors, el que fa referència a Matlab R2007b. Al laboratori està la versió R2013b, per tant, cap problema. També es pot fer l’adquisició de dades utilitzant la Data Adquisition Toolbox (daq) de Matlab. En qualsevol d’aquests dos casos, l’alumne ha de fer un seguit de passos per poder comunicar-se, enviar i rebre dades amb l’estació a la qual estigui i finalment poder visualitzar les dades, parametritzar-les i d’altres gestions per assolir l’objectiu de la pràctica que estigui realitzant.
4 En aquest projecte, es proposa una interfície gràfica, completament produïda amb Matlab, la qual permetrà a l’estudiant enviar, rebre, generar, simular, identificar i controlar d’una manera molt més ràpida, amb la finalitat que aquest pugui aprofundir més en temes propis de l’assignatura i no en codis passatgers que, tot i que són necessaris per a la pràctica, es pot automatitzar per fer les més eficients. D’aquesta manera, el projecte es dividirà en tres parts: Comunicació, Identificació i Control. El programa s’anomena CIC. El seu nom prové de les tres parts de les quals està composat. Mitjançant aquesta interfície s’aconseguirà assolir els objectius d’aquest projecte.
5 1.2. Targeta d’adquisició: 1.2.1. Actual al laboratori: L’adquisició de dades es fa des del Simulink utilitzant la toolbox Real- Time Windows Target (RTWT) de MATLAB. Amb la RTWT es pot crear un model en Simulink i accedir a l’exterior en temps real per a realitzar les simulacions amb la planta disponible físicament. Per això es necessari disposar d’una tarja d’adquisició de dades. La targeta de la qual disposem i que va connectada al bus PCI del PC, és el model PCI1711 (fig. 1.1) de la casa Advantech. Aquest tarja disposa de 16 entrades analògiques, 2 canals de sortida analògics, 16 canals de sortida digitals i 16 canals d’entrada digitals. El conversor AD/DA és de 12 bits amb una freqüència de mostreig superior a 100KHz. Fig. 1.1 Pins de la targeta d’adquisició de dades
6 Real-Time Windows Target La Real-Time Windows Target (RTWT) està dissenyada per a tenir una major flexibilitat i rapidesa permetent la sintonia de paràmetres i senyals durant el funcionament en temps real. La integració entre el Simulink en mode extern i el Real-Time Windows Target permet utilitzar els models de Simulink com una interfície gràfica per: Visualitzar senyals: visualització de senyals mentre funciona l’aplicació en temps real, s’utilitzen els mateixos blocs Scope del Simulink emprats per a visualitzar senyals en processos simulats. Ajust de paràmetres: es fa mitjançant la utilització de les caixes de diàleg dels blocs de paràmetres, que es transferiran automàticament a l’aplicació en temps real. Real-time kernel: La Real-Time Windows Target utilitza la Real-Time Kernel per a assegurar que l’aplicació en temps real funciona efectivament en temps real. La Real-Time Kernel funciona quan la CPU es posa a zero (kernel mode) i utilitza el rellotge intern del PC per a mesurar el temps. La real-time kernel també comunica amb el hardware I/O (Entrada/Sortida) utilitzant drivers, blocs de I/O i verifica la instal·lació de la placa I/O. Mode Extern de Simulink: La comunicació entre el Simulink i l’aplicació real-time es fa a través del mòdul d’interfície de mode extern. Aquest mòdul connecta directament amb la real-time kernel i s’utilitza per a començar l’aplicació real-time, canviar paràmetres i recuperar dades. Es a dir, és la interfície de comunicació per a poder passar dades externes al Simulink.
7 Llibreria Simulink de la RTWT: En el Simulink es disposa de la llibreria de la RTWT on es troben els mòduls d’adquisició i enviament de dades. Per les entrades analògiques el bloc és el següent: Per emmagatzemar les dades hi ha dues opcions, mitjançant un scope (fig. 1.3) on es visualitzen els resultats i a la vegada es poden guardar, o mitjançant un bloc que memoritza les dades en una variable en el workspace (fig. 1.4). La configuració de les entrades analògiques es fa sobre cadascun dels blocs individualment (fig. 1.5 i 1.6). Bàsicament s’ha d’escollir quina serà la targeta amb la que s’adquiriran les dades, el temps de mostreig i quin serà el canal de la targeta. També s’ha de decidir quin és el rang de tensió de les dades que es rebran, que amb la PCL 1711 es pot escollir entre -10 a 10V, -5 a 5V, -2.5 a 2.5V, -1.25 a 1.25V i de -0.625 a 0.625V. Fig. 1.2 Bloc de lectura de dades Fig. 1.3 Mostrar dades en un ‘scope’ Fig. 1.4 Guardar dades al workspace
8 Exemple de fitxer Simulink per adquirir les dades: En la figura següent (fig. 1.7) veiem el fitxer test.mdl creat per a provar l’adquisició i la visualització de les dades d’un procés al laboratori de control. El fitxer és molt senzill i ens permet la lectura de dos canals, un senyal graó que excita el sistema, i la sortida corresponent al procés en estudi. Veiem que els resultats es poden visualitzar tant en el Scope o bé fent un plot a partir de les dades registrades amb el bloc “to workspace” de Simulink. Fig. 1.5 Fig. 1.6 Configuració individuals del blocs
9 Fig. 1.7 Model Simulink per connectar amb la targeta d’adquisició de dades d’advantech
16 Pel tema de les imatges, es generen uns ‘axes’, i en la funció de ‘create function’ (fig. 2.4), que serà just quan es creï l’objecte, se li executarà la comanda ‘imshow()’ perquè mostri la imatge que vulguem, passant-li aquesta per referència. S’ha de tenir en compte que les imatges han d’estar en el mateix directori. Fig. 2.4 Mostrar imatges en el CIC des de el CreateFcn dels axis
17 2.2. Diagrama de blocs i flux En el següent diagrama de flux (fig. 2.5) veurem encerclat tot el que són arxius, ja siguin scripts, arxius de simulink, d’ident o d’interfícies gràfiques. Els quadrats fan referència als botons dins de la seva respectiva interfície, situada a sobre seu en el diagrama, i ens permeten accedir a interfícies posteriors o executar altres fitxers o codi de fons Per executar el programa principal del projecte cal escriure a la “Command Windows” CIC, que és el nom del programa. Fig. 2.5 Diagrama de blocs del CIC
18 Un cop executat aquest programa apareixen tres botons amb els següents noms: 2.2.1. COMUNICACIÓ: Obre la línia de programa que executa la gestió de senyals i comunicació entre l’ordinador i l’estació de treball mitjançant la targeta d’adquisició de dades. Primerament s’obre una finestra per generar els senyals. Un cop generats, prement el botó d’enviar i rebre, s’obrirà una nova finestra per enviar els senyals generats i rebre la resposta de la màquina. Amb els senyals, procedirem a veure les dades en una figura configurant el senyal com vulguem que es vegi i podent re nombrant-lo. 2.2.2. IDENTIFICACIÓ S’obriran dues finestres a la vegada: - Ident, que és una aplicació pròpia de Matlab per poder fer estudis mitjançant senyals d’entrada i sortida. - Identif, que és una interfície amb GUIDE amb la qual, mitjançant els objectes generats per l’aplicació anterior, obtindrem els paràmetres de la planta. 2.2.3. CONTROL Aquesta interfície permet establir una Kp i una Ki a una simulació d’un llaç tancat, que tindrà com a funció de transferència els paràmetres obtinguts en l’apartat anterior. Un cop executada la simulació, se li dona a l’usuari l’opció de fer el control a temps real amb l’estació de treball acceptant que els resultats de la simulació són correctes i que no poden fer mal bé cap element de l’estació. Finalment, un cop amb els resultats, tindrem l’opció de plotejar aquests resultats.
19 2.3. Explicació i funcionalitats 2.3.1. Comunicació: Al prémer el botó de comunicació, s’obrirà la primera finestra (fig. 2.6) per generar el senyal que posteriorment enviarem. En l’altre imatge (fig. 2.7) tenim la vista des de la GUIDE. Fig. 2.6 Vista de l’arxiu EYR executat
20 Mitjançant aquesta aplicació es generaran els senyals que posteriorment s’enviaran a la planta. Fig. 2.7 Vista de l’arxiu EYR des de la Guide
21 A continuació es mostraran el tipus de senyals que es poden generar i els paràmtres en qüestió: Senyal a enviar: Es pot triar que el senyal que es generi sigui un grao o una rampa o Graó o Rampa Paràmetres o Valor inicial o Valor final o Temps canvi o Temps final o Període de mostreig. Entre el temps final i el període de mostreig es definirà el total de mostres. Fig. 2.8 Exemple de graó Fig. 2.9 Exemple de rampa
22 En tots els callback (fig. 2.10) on es puguin introduïr valors, estan protegits contra lletres o valors fora de rang, mostrant per pantalla un avis (fig. 2.11) i rectificant el valor del camp per un acceptable. Així mateix, si s’estableix un periode de mostreig i un temps final que facin un numero de mostres no sencer, també apreix un avis (fig. 2.11) i s’autorectifiquen els camps (fig. 2.12). Fig. 2.10 Codi condicional per la generació del missatge d’error en les dades mitjançant ‘warndlg’ Fig. 2.11 Missatge d’error en les dades Fig. 2.12 Codi condicional per la generació del missatge d’error en les dades mitjançant ‘msgbox’
23 Quan es prem el botó de generar, s’executa un codi(fig 2.13 i 2.14) el qual genera els senyals en funció dels paràmetres establerts. Tots els paràmetres s’importaran al workspace per poder utilitzar-los més endavant. El senyal també es guardarà com un array de numeros per utilitzar-lo posteriorment i es convertirà en format CellArray per tal de poder mostrar-lo en les dues columnes. Fig. 2.13 Part 1 d’importació de dades i generació de senyals
24 Seleccionar columna Amb aquesta opció decidirem on enviar el senyal. Cal tenir en compte que la columna fa referència directa al port de sortida, és a dir, la columna 1 anirà al Output 1 de la tarjeta d’adquisició i la 2 al segon port. El codi (fig 2.15 i 2.16) és continu al anterior. Fig. 2.14 Part 2 d’importació de dades i generació de senyals Fig. 2.15 Mostrar el senyal en la primera columna en funció del ‘radiobutton’
25 Es pot veure al final del codi (fig. 2.16) com es deshabilita els camps de periode de mostreig, temps final i mostres (fig 2.17) . Això és degut a que els dos senyals han de ser de la mateix longitud i mateix periode de mostreig. Fig. 2.16 Mostrar el senyal en la segona columna en funció del ‘radiobutton’
32 És important just després de enviar i rebre, passar a la finestra de veure les dades, per guardar-les amb el nom que l’usuari desitgi, ja que si no es fa, al tornar a enviar es perden els senyals anteriors. Fig. 2.24 Model ‘test’ per comunicar amb la targeta d’adquisició de dades
33 S’ha creat una interficie (fig 2.25) per facilitar la visualització i salvació de dades, permetent a l’usuari tota posibilitat a l’hora de mostrar-les. Per exemple, en la seguent imatge, es vol mostrar les dades que s’acabaen d’enviar i rebre pels respectius ports 1. Definim un nom per les dades (i al fer-ho la casella automàticament ja es marca), i personalitzaem el color, estil de línia i punt. Fig. 2.25 Vista de l’arxiu ‘toplot’ executat Fig. 2.26 Vista de l’arxiu ‘toplot’ des de la Guide
34 Un cop ha quedat preparat, es procedeix a premer el botó perquè automàticament es crei una “figure” (fig. 2.27) en la cual es veuran aquests senyals personalitzats i la llegenda en qüestió. Al ser mostrat d’aquesta manera, l’usuari ho podrà guardar com a imatge per posteriorment afegir-ho a l’informe de laboratori. . Fig. 2.27 Exemple de plotejat d’un senyal des de l’interfície
35 Aquestes característiques són pròpies de Matlab, anomenades LineSpec. (fig. 2.28). Aquestes són les diferents opcions que hi ha: Fig. 2.28 Retall de ‘Matlab help’ sobre les opcions per mostrar els senyals
36 Per aconseguir això s’ha fet de la següent manera: Fig. 2.29 Codi de selecció de les propietats per mostrar el senyal
37 I d’aquesta manera s’executa la funció plot amb els paràmetres seleccionats i amb un ‘hold on’ perquè es mantinguin tots. En la següent imatge (fig. 2.31), es veu un altre visualització de dades: Fig. 2.30 Exemple per enviar un senyal pel por número 2 Fig. 2.31 Exemple de plot pel port número 2 amb error en la lectura
38 En aquest cas es poden observar dues coses: 1. El nom que s’ha guardat con a entrada, al ser més curt que l’altre, se li afegeixen punts ‘·’ per tal que es pugui crear la llegenda. Això és degut ja que per crear la llegenda, s’utilitza una comanda a la qual se li pasa per referencia una taula de ‘Strings’. Matlab no contempla una taula en que la llargada de cadascun dels ‘Strings’ sigui diferent, i tampoc accepta espais en blanc a la dreta, per això s’ha optat a afegir-li aquests punts, que tot i que es veuen, pasen més desapercebuts que altres caracters. Per identificar aquests espais s’ha procedit a utilitzar els següent algoritme (fig. 2.32): Fig. 2.32 Codi de generació de la llegenda variable en funció dels senyals seleccionats
39 Un cop creada la figura, es pot accedir a cada nom de la llegenda i verificar-ho manualment si es desitja. 2. Com es pot veure (fig. 2.31), tot i que són del mateix color, la sortida de la rampa està a 0, tot i haver enviat un senyal. Es important sempre tenir en compte per on s’envii físicament estigui conectat. És obvi, però pot passar.
40 2.1.1. Identificació Un cop tenim els senyals, es procedeix a fer la identificació de la planta mitjançant aquestes interfícies. Primer de tot cal executar el programa mitjançant el botó de “IDENTIFICACIÓ” de la finestra del programa principal CIC. S’obriràn dues finestres: L’aplicació ident (fig. 2.33) de Matlab per identificar la planta a partir dels senyals d’entrada i sortida La interficie gràfica (fig 2.34) pròpia creada amb la GUIDE per mostrar directament totes les dades generades des de l’ident. Fig. 2.33 Vista d’execució de l’aplicació ident de Matlab
41 Fig. 2.35 Vista de l’arxiu ident des de la Guide Fig. 2.34 Vista de l’arxiu ident executat
48 S’ha de tenir en compte que tot i que aparegui en la interfície la paraula pol o zero, no vol dir que sigui exactament el pol o el zero, sinó que és el paràmetre al que està associat dins de la equació. Per tant, zero serà igual a − i el pol serà − . Igual que en l’anterior interfície, s’ha establert un mètode contra errors en el camp on s’ha de posar la variable (fig. 2.45). En aquest cas s’ha fet d’una manera diferent. Fig. 2.44 Informació de la funció de transferència a la ‘command windows’ Fig. 2.45 Codi de verificació d’existència de la variable a mostrar
49 Per no haver de fer un algoritme massa llarg comprovant tot el workspace amb el nom, he aplicat un ‘try - catch’ ja que quan intenta agafar una variable del workspace i no existeix salta un error en la línia de la variable ‘existe’, aleshores, en aquest punt, el fil d’execució salta al catch, on s’executa una línia de codi que mostra un missatge avisant de l’error. En cas que existeixi, continua l’execució (fig. 2.46) agafant els tres primers paràmetres que tenen els dos tipus de models i enviant-ho a la interfície. A continuació s’avalua el paràmetre Tp1 (fig. 2.47). Si aquest és igual a zero, voldrà dir que s’haurà triat un model tipus ‘underdamped’(fig. 2.48). En cas contrari, sent tot reals (fig. 2.49), el paràmetre Tp1 sempre ha de ser diferent de zero. Un cop es sap el tipus de model, s’importen la resta de paràmetres. Fig. 2.46 Codi d’import ació de dades comunes de la variable a la interfície
50 Fig. 2.47 Mètode per identificar quin tipus de model és. Fig. 2.48 Codi d’importació de dades de la variable a la interfície de mode ‘underdamped’
51 Fig. 2.49 Codi d’importació de dades de la variable a la interfície de mode ‘ all real’
52 El següent apartat és definir les equacions (fig. 2.50). Per això cal identificar el numerador i el denominador. Com s’ha pogut veure en les dues figures anteriors, les últimes línies de codi defineixen el denominador i l’enviaven al workspace. Després només a estat necessari definir el numerador i el retard i, mitjançant la funció ‘tf’ de matlab, la qual crea funcions. Crea l’equació en funció dels paràmetres que li passem per referència. La línia directa en la qual esta la funció no te ‘;’ al final per tal que aparegui en la ‘command windows’. Per obtenir la equació en discret (fig. 2.51) s’ha utilitzat la funció ‘c2d’, el qual vol dir ‘continuous to discrete’. Per utilitzar aquesta funció se li ha de passar per referencia l’equació i el període de mostreig, el qual obtindrem del workspace i ha estat definit anteriorment en la primera finestra de Comunicació. Al igual que en el cas anterior, no posarem ‘;’ en la línia de la funció ‘c2d’ per tal que aparegui en la ‘command windows’. Fig. 2.50 Generació de la funció de transferència en continu Fig. 2.51 Generació de la funció de transferència en discret
53 Un cop tenim l’equació en discret, ja podem obtenir els paràmetres (fig. 2.51). Els paràmetres es creen, dins de l’objecte que te la equació, en el camp num o den respectivament. Aquest camp es un cellarray, el qual conté l’array de números i serà d’aquí d’on obtindrem els paràmetres. En cas que no existeixi un paràmetre, el programa està preparat creant-lo amb valor 0. Aquests paràmetres seran escurçats fins a 3 decimals. També obtindrem el retard en mostres i enviarem totes les dades a la interfície gràfica. Fig. 2.52 Algoritme per limitar a 3 decimals i exportació a la interfície
54 Es disposa d’un botó reset (fig. 2.53) que neteja automàticament tota la finestra i la deixa com si s’acabés d’executar i neteja la ‘command windows’. Fig. 2.53 Algoritme de neteja de la interfície i de la ‘command windows’
55 2.1.2. Control Amb la planta identificada, ja es pot procedir a fer contol en llaç tancat. En aquest apartat primerament es fara una simulació de com reaccionarà la planta identificada amb els paràmetres Kp i Ki que nosaltres establirem fron una entrada amb els mateixos paràmetres del apartat de comunicació. Aquesta interfície (fig. 2.54) per tant es dividirà en dues parts. En la part duperior tindrem tota la part de simulació i en la part inferior, a posterior de assumir que la resposta de la planta es correcta, es procedeix a fer control en temps real. Fig. 2.54 Vista de l’arxiu control executat
56 En la part superior trobem dos gràfics. En el primer gràfic apareixerà l’entrada i la sortida simulada. En el segon gràfic apareixerà l’acció de control de la planta simulada. També apareix un text adalt a la dreta que mostra el valor màxim de l’acció de control. L’intenció d’aquest text és que l’usuari valori si la planta pot acceptar el valor màxim de l’acció de control, sabent que les estacions del laboratori soporten un màxim de 10 volts. Al premer el botó simulació, s’exporten els valors de Kp i Ki al workspace perqué l’arxiu de simulink que farà la simulació agafi els paràmetres. Tot seguit, s’executa l’arxiu de simulink encarregat de la simulació, però, al ser executat des de codi de GUIDE, els blocs de ‘to workspace’ no envien el valor, això només es fa si es compila l’arxiu, per tant utilitzarem la funció ‘simOut’ (fig. 2.56) per guardar els valors. Fig. 2.55 Vista de l’arxiu control des de la Guide
57 La funció ‘sim’ retorna un objecte amb els diferents paràmetres simulats en el model (fig. 2.57). Un cop tenim la simulació i els paràmetres obtinguts, s’aplica un petit algoritme (fig. 2.58) per aconseguir que tots els senyals siguin de la mateixa longitud per no tenir cap problema a l’hora de mostrar-los en una gràfica. Aquest ajust de vectors serà donant-li prioritat al vector temps, i ajustant als altres a la mateixa longitud que aquest. En cas que algun vector sigui més curt que el vector temps, se li afegirà tants cops com sigui necessari el valor de la última mostra al final, i en cas que sigui més llarg, es retallarà. Finalment, els mostrarem per les gràfiques superiors de la interfície (fig.2.59). Fig. 2.56 Codi per simular un model e importar les dades Fig. 2.57 Model per simular en llaç tancat els paràmetres Kp i Ki triats per l’usuari
64 3. Conclusions En aquest projecte s’han arribat a assolir els objectius gràcies a aquesta interfície final anomenada CIC. Tal i com s’han explicat al principi, s’ha aconseguit elaborar una interfície gràfica per als usuaris del laboratori de control del TR11 que els hi permetrà elaborar, enviar, i rebre senyals, identificar en continu i transformar en discret models de les estacions de treball del laboratori i controlar aquests amb els paràmetres Kp i Ki que es desitgin. Així mateix, a part de la funcionalitat d’aquest projecte, s’ha intentat elaborar una interfície el mes agradable i el més ordenat possible, separant els tres blocs principals. Per altra banda, tot i els objectius i que ha quedat ordenat, m’hagués agradat haver tingut més coneixements previs sobre l’ús de la Guide i de l’Ident. Sobretot, en el cas de la Guide, se li ha hagut de dedicar bastant de temps en aprendre a utilitzar-la per mi mateix. Tot i l’ajuda del meu director i d’altres professors, proporcionant-me documentació bàsica que per començar a situarme em va ajudar molt, no ha estat del tot útil a la llarga, ja que es quedava amb temes bastant bàsics. Apart dels aspectes pràctics sobre la Guide que es troba als annexos, a la bibliografia trobareu enllaços, ja sigui per youtube, canals en el que el propietari penja vídeos de pocs minuts explicant apartats en concret, o ja sigui en blogs o d’altres, en els que hi ha hagut altres manuals més extensos. En el cas de l’Ident ha estat una mica diferent ja que, tot i que era un programa completament desconegut bastant complexa, ha estat bastant directe trobar informació sobre l’ús d’aquest. Per desgracia només s’arriba a tocar la capa superficial, tal i com s’ha dit abans, avarca molts aspectes i és una aplicació molt potent.
65 A part de descobrir aquestes dues aplicacions, també s’ha hagut d’experimentar molt en certes funcions que té matlab i que no s’han arribat a tractar a classe. Ja sigui per necessitat de modelització, per control de seguretat de l’usuari en les dades o per mostrar vectors en les taules de la Guide, funcions com ‘warndlg’, ‘msgbox’, ’rtwgen’, ‘sim’, ‘tf’, ‘c2d’, ‘cla’ o els cellarrays. Personalment, tot i la quantitat de temps dedicat, el resultat ha estat molt satisfactori, tenint en compte el projecte final i els coneixements apresos des de els inicis d’aquest. Voldria agrair, en primer lloc, al meu tutor Ramón Comasólivas, per tota l’ajuda proporcionada al llarg del projecte, sobretot en aquells moments en els que m’estancava i per totes les recomanacions per millorar la meva interfície i rectificacions en la memòria. També agrair a l’Albert Masip, que gràcies a l’assignatura de PSSP, em va donar la solució per compilar i connectar un model simulink des de codi, ja que després de tant buscar, no aconseguia trobar res. Finalment, agrair a la Fatiha Nejjari l’ajuda proporcionada en forma de documentació per iniciar-me i començar a conèixer la Guide.
66 4. Pressupost Cost de personal: Cost mensual d’un enginyer: 1750€ Mesos invertits: 4 mesos Cost de l’enginyer: 7000€ Cost del software: Cost de la llicencia individual de Matlab: 2000€ Cost de la llicencia individual de Simulink: 3000€ Cost de la llicencia individual de ‘Data Acquisition Toolbox’: 1000€ Cost de la llicencia individual de ‘System Identification Toolbox’ (ident): 1000€ Cost final de software: 7000€ Cost de hardware: Cost targeta adquisició de dades PCI 1711 d’Advantech: 333€ Cost final del projecte: 14333€
67 5. Bibliografia - Matlab documentation [en línia]. Espanya: Mathworks. Disponible en: http://es.mathworks.com/help/ - Diegokillemall. MATLAB, VHDL & PICs [Canal de youtube]. Espanya. Disponible en: https://www.youtube.com/user/diegokillemall - Matlab. MATLAB. [Canal de youtube]. Espanya. Disponible en: https://www.youtube.com/user/MATLAB - Guy and Seth on Simulink [en línia]. Espanya: Mathwork. Disponible en: http://blogs.mathworks.com/seth/ - Documentació proporcionada pel tutor. - Advantech products [en línia]. Espanya: Advantech. Disponible en: http://buy.advantech.eu/12+Bit+Multifunction+PCI+Card+16/PCI+1711U+CE/m odel-PCI-1711U-CE.htm - Mathwork Pricing and Licensing [en línia]. Espanya: Mathworks. Disponible en: https://es.mathworks.com/pricinglicensing/index.html?intendeduse=comm&s_tid=htb_learn_gtwy_cta1 - Departament d’empresa i ocupació {en línia]. Espanya: Diari Oficial de la Generalitat de Catalunya. Disponible en: http://www.aces.es/repositori/documents/convenis/ca/DOGC_taules2010regu laritzades.pdf
68 6. Annexos
69 6.1. Annex 1: Aspectes pràctics Guide. En aquest breu manual es reflectiran aspectes molt pràctics a l’hora de treballar amb aquesta eina. Està pensat per a gent que estigui començant a utilitzar-la i es trobi amb certs problemes amb els quals jo em vaig trobar. Es parteix de la base que se sap iniciar el programa i arrossegar els objectes a la pantalla principal, així que aquest primers aspectes no s’explicaran. Guide és una aplicació de Matlab que et permet crear interfícies gràfiques personalitzades. Les interfícies que elaboris sempre estaran compostes per dos arxius: - .fig: Que serà qui tindrà la informació del objectes creats i la seves dimensions i ubicacions. Si des de la ‘current folder’ es vol obrir l’editor de l’arxiu en qüestió, no fer doble click esquerre, perquè executarà l’arxiu, sinó boto dret i ‘Open in Guide’. - .m: Que serà l’encarregat de donar-li’ls vida a aquests objectes mitjançant codi, en els diferents estats que pot tenir l’objecte en qüestió. Objectes més bàsics: - Push Button: Permet executar codi al prémer el botó. - Radio Button: Permet tenir identificada una opció entre varies. - Check box: Permet tenir identificada varies opcions. - Edit text: Permet a l’usuari entrar dades. - Static text: Permet informar a l’usuari. - Pop-up Menu: Permet a l’usuari seleccionar una opció. - Table: Permet mostrar dades en una taula dimensionable. - Axes: Permet mostrar gràfiques o imatges. - Panel: Permet agrupar objectes. - Button Group: Permet agrupar objectes i que només es quedi seleccionada una opció. Sinergia amb RadioButton. Annex 1
70 Property inspector: Ja sigui fent doble click esquerre en l’objecte o accedint des de les opcions del boto dret, el property inspector és una llista dels paràmetres (a l’esquerra) i el seu valor actual (a la dreta). Aquests paràmetres que apareixen en la llista seran els que tindrà l’objecte a l’inici de l’execució. Mitjançant les funcions get i set, poderm obtenir en el codi els paràmetres que vulguem dels objectes que vulguem. Per fer-ho, serà important assignar-li un nom a l’apartat de ‘tag’, que és el nom amb el que el podrem cridar. Funcions més comunes: - Callback: Executa la part de codi referenciat a l’objecte en qüestió quan a aquest és premut. - Create function: Executa la part de codi referenciat a l’objecte en qüestió a l’inici de l’execució, quan està creant l’objecte. Per poder accedir un objecte, es pot fer de dues maneres: - Handles: Permet cridar a un objecte des de qualsevol part del codi. - hObject: Permet cridar a l’objecte des de la seva funció, és a dir, si premem un botó, s’executarà la part del codi on estigui situat el callback del botó. Get i Set: - Get: Permet obtenir qualsevol paràmetre del objecte que es cridi. Per fer-ho, sempre es fa de la següent manera: get(tag, paràmetre) Per posar el tag del objecte es pot fer com s’ha explicat abans mitjançant handles o hObject. El nom del paràmetre s’ha de posar en format String, per tant entre cometes. Annex 1
71 Ex: Imaginem que tenim un boto amb tag boto_1. Si el botó no està premut, al fer el següent: get(handles.boto_1,’Value’) Ens retornaria ‘0’. En el cas que el premem, i dins del callback tinguem: get(hObject, ‘Value’) Ens retornaria un ‘1’. En aquest cas com es pot observar s’ha pogut posar hObject perquè estaríem treballant des de el callback del mateix objecte. Apart cal tenir en compte que, tot el que la funció get ens retorni, serà un String, així que si el que volem és que sigui un valor numèric, caldrà fer el següent: str2double(get(hObject, ‘Value’)) - Set. Permet modificar un paràmetre d’un objecte. De igual manera que el get, es crida posant el tag, el parametre i a més a més el valor que volem modificar: set(tag,paràmetre,valor) El valor que se li entrarà se li enviarà també com un string. Ex: Suposem que tenim el mateix botó d’abans i volem que quan es premi se li canviï el nom que li apareix escrit a sobre. set(hObject,’String’,’Nou nom’) Axis: Els ‘axis’ es tracten de diferent manera. En aquests objectes les principals finalitats són o mostrar una imatge o plotejar dades. Primer de tot cal dirl-li al codi quin objecte d’aqeust tipus cal que tracti, i es fa de la següent manera: axis(handles.tag) Un cop estem situats es tan sencill com escriture o plot() amb la informació a plotejar o imshow() amb la imatge que vulguem mostrar. La imatge ha de estar en el path del programa perquè la pugui trobar. Annex 1
72 De igual manera que els altres objectes, també es poden obtenir i modificar els seus paràmetres amb el get i set, com per exemple ajustar els eixos en funció dels màxims i mínims del senyal a plotejar. Comunicació amb el Workspace Base: Guide disposa de la seva base de dades personal i no comunicable directament amb el workspace base de matlab. Per tant, per poder comunicar les dues base de dades utilitzarem assignin i evalin dins del codi de la guide. Assignin: Mitjançant aquesta funció podrem enviar les dades de la base de dades de la guide al workspace de la següent manera: assignin(ws,nom,variable) En ws es posarà ‘base’ per especificar el workspace de Matlab i no el workspace de una funció, el segon espai, el nom amb el que voldrem que es guardi la variable (entre cometes ja que ha de ser un String) i finalment la variable que volem enviar. Evalin: Aquesta funció retorna la execució del que se li entri per referència, en altres paraules, el que li entris per paràmetres es el que s’executaria en la ‘command windows’. Per tant, igualant el que retorni l’evalin a una variable de dins de la guide, obtindrem la informació del workspace. Es procedirà de la següent manera: var_guide=evalin(ws,var) Al igual que en l’assignin, seleccionarem el ws ‘base’. Evalin també ens pot servir, per exemple, per netejar la ‘command windows’, ja que si des de la guide s’executa ‘clc’, no pasarà res. Per tant per netejar-la farem: Evalin(‘base’,clc) Annex 1
73 Tot i aquestes dues funcions, existeix la possibilitat de treballar amb variables globals, les quals si que apareixerien en tots dos llocs, però s’han d’instanciar a l’inici de cada funció dels objectes de la guide. Simulink: Per tal d’auto compilar un model per utilitzar la targeta d’adquisicions, es pot fer de la següent manera: if exist (‘nommodel.rtw’,’file’) delete(‘nommodel.rtw’) end rtwgen nommodel while exist(‘nommodel.rtw’,’file’)==0 end tlc nommodel.rtw rtwbuild nomodel set_param(gcs,’SimulationMode’,’External’) set_param(gcs,’SimulationCommand’,’Connect’) set_param(gcs,’SimulationCommand’,’Start’) Annex 1
I1 ToWorkspace Analog Input Analog Input I1on Gain
Step num den Transfer Fcn Scope Kp kP Ki kI 1 s Integrator acciocontrol To Workspace1 simulacio To Workspace2 Transport Delay entradasimulacio To Workspace3
temps_sim To Workspace1 Clock Analog Output Analog Output Analog Input Analog Input Ki Gain acciocontrol_real To Workspace2 sortida_real To Workspace3 K Ts z-1 Discrete-Time Integrator Kp Gain1 Step Saturation entrada_real To Workspace4
cesped logo_upc logo_matlab COMUNICACIÓ IDENTIFICACIÓ CONTROL PFG Nacho Gonzalez
8/06/15 15:51 D:\PFG_programa_final\CIC.m 1 of 3 function varargout = CIC(varargin) %CIC M-file for CIC.fig % CIC, by itself, creates a new CIC or raises the existing % singleton*. % % H = CIC returns the handle to a new CIC or the handle to % the existing singleton*. % % CIC('Property','Value',...) creates a new CIC using the % given property value pairs. Unrecognized properties are passed via % varargin to CIC_OpeningFcn. This calling syntax produces a % warning when there is an existing singleton*. % % CIC('CALLBACK') and CIC('CALLBACK',hObject,...) call the % local function named CALLBACK in CIC.M with the given input % arguments. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help CIC % Last Modified by GUIDE v2.5 03-Jun-2015 23:38:17 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @CIC_OpeningFcn, ... 'gui_OutputFcn', @CIC_OutputFcn, ... 'gui_LayoutFcn', [], ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before CIC is made visible. function CIC_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin unrecognized PropertyName/PropertyValue pairs from the % command line (see VARARGIN)
8/06/15 15:51 D:\PFG_programa_final\CIC.m 2 of 3 % Choose default command line output for CIC handles.output = hObject; % Update handles structure guidata(hObject, handles); warning off; evalin('base','clc'); % UIWAIT makes CIC wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = CIC_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; %msgbox('Mensaje') %errordlg('Se ha producido un error','ERROR') % --- Executes on button press in enviaryrecibir. function enviaryrecibir_Callback(hObject, eventdata, handles) % hObject handle to enviaryrecibir (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) EYR; % --- Executes on button press in identificacion. function identificacion_Callback(hObject, eventdata, handles) % hObject handle to identificacion (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) identif; % --- Executes on button press in control. function control_Callback(hObject, eventdata, handles) % hObject handle to control (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) control; % --- Executes during object creation, after setting all properties. function logo_upc_CreateFcn(hObject, eventdata, handles) % hObject handle to logo_upc (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called imshow('logo_upc.jpg');
8/06/15 15:51 D:\PFG_programa_final\CIC.m 3 of 3 % Hint: place code in OpeningFcn to populate logo_upc % --- Executes during object creation, after setting all properties. function logo_matlab_CreateFcn(hObject, eventdata, handles) % hObject handle to logo_matlab (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called imshow('logo_matlab.jpg'); % Hint: place code in OpeningFcn to populate logo_matlab % --- Executes during object creation, after setting all properties. function cesped_CreateFcn(hObject, eventdata, handles) % hObject handle to cesped (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called imshow('cesped.jpg'); % Hint: place code in OpeningFcn to populate cesped
graph1 graph2 Senyal a enviar: Grao Rampa Valor inicial Generar Temps canvi 1 2 3 4 1 Temps final Periode de mostreig Crea el teu senyal d'entrada Selecciona columna 21 Valor final Senyal 1 1 2 3 4 1 Senyal 2 Enviar i rebre 4 8 3 6 0.01 Mostres 601
8/06/15 15:52 D:\PFG_programa_final\EYR.m 1 of 10 function varargout = EYR(varargin) gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @EYR_OpeningFcn, ... 'gui_OutputFcn', @EYR_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end function EYR_OpeningFcn(hObject, eventdata, handles, varargin) movegui(hObject,'center') handles.output = hObject; guidata(hObject, handles); axes(handles.graph1) hold off axes(handles.graph2) hold off init_taula1=cell(1,1); init_taula1(:,:)={''}; init_taula2=cell(1,1); init_taula2(:,:)={''}; set(handles.tabla1,'Data',init_taula1) set(handles.tabla1,'ColumnEditable',true(1,1)); set(handles.tabla2,'Data',init_taula2) set(handles.tabla2,'ColumnEditable',true(1,1)); warning off; function varargout = EYR_OutputFcn(hObject, eventdata, handles) varargout{1} = handles.output; %open modelo_senal_salida %pendiente modificar a un .m y eliminar línea function pbgenerar_Callback(hObject, eventdata, handles) assignin('base','ValorInicial',str2double(get(handles.etvalorinicial,'String'))); assignin('base','ValorFinal',str2double(get(handles.etvalorfinal,'String')));
8/06/15 15:52 D:\PFG_programa_final\EYR.m 2 of 10 assignin('base','TempsCanvi',str2double(get(handles.et_tempscanvi,'String'))); assignin('base','TempsFinal',str2double(get(handles.et_tempsfinal,'String'))); assignin('base','PeriodeMostreig',str2double(get(handles. et_periodemostreig,'String'))); assignin('base','NumMostres',str2double(get(handles.et_mostres,'String'))); assignin('base','Rampa',get(handles.rbrampa,'Value')); assignin('base','Grao',get(handles.rbescalon,'Value')); tempscanvi=evalin('base','TempsCanvi'); tempsfinal=evalin('base','TempsFinal'); periodemostreig=evalin('base','PeriodeMostreig'); valorinicial=evalin('base','ValorInicial'); valorfinal=evalin('base','ValorFinal'); numeromostrescanvi=tempscanvi/periodemostreig+1; numeromostrestotals=str2double(get(handles.et_mostres,'String')); grao=evalin('base','Grao'); rampa=evalin('base','Rampa'); temps= [0 0]; for i=1:numeromostrestotals-1 temps(i+1)=periodemostreig*i; end assignin('base','temps',temps'); senyal = [0 0]; if grao==1 for i=1:numeromostrescanvi senyal(i)=valorinicial; end for i=numeromostrescanvi+1:numeromostrestotals senyal(i)=valorfinal; end end numeromostresrampa=numeromostrestotals-numeromostrescanvi; incrementrampa=(valorfinal-valorinicial)/numeromostresrampa; cont=1; if rampa==1 for i=1:numeromostrescanvi senyal(i)=valorinicial; end for i=numeromostrescanvi+1:numeromostrestotals cont=cont+1; senyal(i)=(incrementrampa*cont)+valorinicial; end
8/06/15 15:52 D:\PFG_programa_final\EYR.m 9 of 10 % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function et_mostres_Callback(hObject, eventdata, handles) % hObject handle to et_mostres (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of et_mostres as text % str2double(get(hObject,'String')) returns contents of et_mostres as a double if (str2double(get(handles.et_mostres,'String'))<0) |... (isnan(str2double(get(handles.et_tempsfinal,'String')))) warndlg('Mostres no vàlid','Error!') set(handles.et_tempsfinal,'String',str2double(get(handles. et_tempscanvi,'String'))+1); return; end if get(handles.rb_tempsfinal,'Value') set(handles.et_tempsfinal,'String',... str2double(get(handles.et_mostres,'String'))*... str2double(get(handles.et_periodemostreig,'String'))) end if get(handles.rb_periodemostreig,'Value') set(handles.et_periodemostreig,'String',... str2double(get(handles.et_mostres,'String'))/... str2double(get(handles.et_tempsfinal,'String'))) end % --- Executes during object creation, after setting all properties. function et_mostres_CreateFcn(hObject, eventdata, handles) % hObject handle to et_mostres (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes during object creation, after setting all properties. function uipanel6_CreateFcn(hObject, eventdata, handles) % hObject handle to uipanel6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
8/06/15 15:52 D:\PFG_programa_final\EYR.m 10 of 10 % --- Executes when selected object is changed in uipanel6. function uipanel6_SelectionChangeFcn(hObject, eventdata, handles) % hObject handle to the selected object in uipanel6 % eventdata structure with the following fields (see UIBUTTONGROUP) % EventName: string 'SelectionChanged' (read only) % OldValue: handle of the previously selected object or empty if none was selected % NewValue: handle of the currently selected object % handles structure with handles and user data (see GUIDATA) if get(handles.rb_tempsfinal,'Value') set(handles.et_tempsfinal,'Enable','Off'); else set(handles.et_tempsfinal,'Enable','On'); end if get(handles.rb_periodemostreig,'Value') set(handles.et_periodemostreig,'Enable','Off'); else set(handles.et_periodemostreig,'Enable','On'); end if get(handles.rb_mostres,'Value') set(handles.et_mostres,'Enable','Off'); else set(handles.et_mostres,'Enable','On'); end
Columna 1 Output 1 Columna 2 Output 2 Input 1 Input 2 Input 3 Input 4 Enviar Rebre Executar Veure resultats
8/06/15 15:52 D:\PFG_programa_final\preEYRgesvar.m 1 of 7 function varargout = preEYRgesvar(varargin) % PREEYRGESVAR MATLAB code for preEYRgesvar.fig % PREEYRGESVAR, by itself, creates a new PREEYRGESVAR or raises the existing % singleton*. % % H = PREEYRGESVAR returns the handle to a new PREEYRGESVAR or the handle to % the existing singleton*. % % PREEYRGESVAR('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in PREEYRGESVAR.M with the given input arguments. % % PREEYRGESVAR('Property','Value',...) creates a new PREEYRGESVAR or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before preEYRgesvar_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to preEYRgesvar_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help preEYRgesvar % Last Modified by GUIDE v2.5 03-May-2015 20:14:02 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @preEYRgesvar_OpeningFcn, ... 'gui_OutputFcn', @preEYRgesvar_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before preEYRgesvar is made visible. function preEYRgesvar_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to preEYRgesvar (see VARARGIN) % Choose default command line output for preEYRgesvar
8/06/15 15:52 D:\PFG_programa_final\preEYRgesvar.m 2 of 7 handles.output = hObject; % Update handles structure guidata(hObject, handles); evalin('base','clc'); % UIWAIT makes preEYRgesvar wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = preEYRgesvar_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in cboutput1. function cboutput1_Callback(hObject, eventdata, handles) % hObject handle to cboutput1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of cboutput1 % --- Executes on button press in cboutput2. function cboutput2_Callback(hObject, eventdata, handles) % hObject handle to cboutput2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of cboutput2 % --- Executes on button press in cbinput1. function cbinput1_Callback(hObject, eventdata, handles) % hObject handle to cbinput1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of cbinput1 % --- Executes on button press in cbinput2. function cbinput2_Callback(hObject, eventdata, handles) % hObject handle to cbinput2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of cbinput2
8/06/15 15:52 D:\PFG_programa_final\preEYRgesvar.m 3 of 7 % --- Executes on button press in cbinput3. function cbinput3_Callback(hObject, eventdata, handles) % hObject handle to cbinput3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of cbinput3 % --- Executes on button press in cbinput4. function cbinput4_Callback(hObject, eventdata, handles) % hObject handle to cbinput4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of cbinput4 % --- Executes on button press in pbejecutar. function pbejecutar_Callback(hObject, eventdata, handles) % hObject handle to pbejecutar (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) I1on=0; I2on=0; I3on=0; I4on=0; O1on=0; O2on=0; longitud=evalin('base','TempsFinal')/evalin('base','PeriodeMostreig')+1; arr_null=zeros(longitud,1,'double'); if get(handles.cboutput1,'Value')==1 O1on=1; O1=evalin('base','SenyalColumna1'); else O1=arr_null'; end if get(handles.cboutput2,'Value')==1 O2on=1; O2=evalin('base','SenyalColumna2'); else O2=arr_null'; end if get(handles.cbinput1,'Value')==1 I1on=1; end if get(handles.cbinput2,'Value')==1 I2on=1;
8/06/15 15:52 D:\PFG_programa_final\preEYRgesvar.m 4 of 7 end if get(handles.cbinput3,'Value')==1 I3on=1; end if get(handles.cbinput4,'Value')==1 I4on=1; end assignin('base','I1on',I1on); assignin('base','I2on',I2on); assignin('base','I3on',I3on); assignin('base','I4on',I4on); assignin('base','O1on',O1on); assignin('base','O2on',O2on); assignin('base','O1',O1'); assignin('base','O2',O2'); warning off; msgbox('Iniciant i compilant Simulink. Esperi si us plau','Executant'); if exist('test.rtw','file') delete('test.rtw') end rtwgen test while exist('test.rtw', 'file')==0 end tlc test.rtw rtwbuild test set_param(gcs,'SimulationMode','External') set_param(gcs,'SimulationCommand','Connect') set_param(gcs,'SimulationCommand','Start') set(handles.pb_veure_resultats,'enable','on'); % --- Executes on button press in pb_veure_resultats. function pb_veure_resultats_Callback(hObject, eventdata, handles) % hObject handle to pb_veure_resultats (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) toplot; function nomO1_Callback(hObject, eventdata, handles) % hObject handle to nomO1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
8/06/15 15:52 D:\PFG_programa_final\preEYRgesvar.m 5 of 7 set(handles.cboutput1,'Value',1); % Hints: get(hObject,'String') returns contents of nomO1 as text % str2double(get(hObject,'String')) returns contents of nomO1 as a double % --- Executes during object creation, after setting all properties. function nomO1_CreateFcn(hObject, eventdata, handles) % hObject handle to nomO1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function nomO2_Callback(hObject, eventdata, handles) % hObject handle to nomO2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.cboutput2,'Value',1); % Hints: get(hObject,'String') returns contents of nomO2 as text % str2double(get(hObject,'String')) returns contents of nomO2 as a double % --- Executes during object creation, after setting all properties. function nomO2_CreateFcn(hObject, eventdata, handles) % hObject handle to nomO2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function nomI1_Callback(hObject, eventdata, handles) % hObject handle to nomI1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.cbinput1,'Value',1); % Hints: get(hObject,'String') returns contents of nomI1 as text % str2double(get(hObject,'String')) returns contents of nomI1 as a double % --- Executes during object creation, after setting all properties.
8/06/15 15:52 D:\PFG_programa_final\preEYRgesvar.m 6 of 7 function nomI1_CreateFcn(hObject, eventdata, handles) % hObject handle to nomI1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function nomI2_Callback(hObject, eventdata, handles) % hObject handle to nomI2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.cbinput2,'Value',1); % Hints: get(hObject,'String') returns contents of nomI2 as text % str2double(get(hObject,'String')) returns contents of nomI2 as a double % --- Executes during object creation, after setting all properties. function nomI2_CreateFcn(hObject, eventdata, handles) % hObject handle to nomI2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function nomI3_Callback(hObject, eventdata, handles) % hObject handle to nomI3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.cbinput3,'Value',1); % Hints: get(hObject,'String') returns contents of nomI3 as text % str2double(get(hObject,'String')) returns contents of nomI3 as a double % --- Executes during object creation, after setting all properties. function nomI3_CreateFcn(hObject, eventdata, handles) % hObject handle to nomI3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER.
8/06/15 15:52 D:\PFG_programa_final\preEYRgesvar.m 7 of 7 if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function nomI4_Callback(hObject, eventdata, handles) % hObject handle to nomI4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.cbinput4,'Value',1); % Hints: get(hObject,'String') returns contents of nomI4 as text % str2double(get(hObject,'String')) returns contents of nomI4 as a double % --- Executes during object creation, after setting all properties. function nomI4_CreateFcn(hObject, eventdata, handles) % hObject handle to nomI4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
8/06/15 15:52 D:\PFG_programa_final\toplot.m 6 of 37 % hObject handle to edit7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit7 as text % str2double(get(hObject,'String')) returns contents of edit7 as a double % --- Executes during object creation, after setting all properties. function edit7_CreateFcn(hObject, eventdata, handles) % hObject handle to edit7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit8_Callback(hObject, eventdata, handles) % hObject handle to edit8 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit8 as text % str2double(get(hObject,'String')) returns contents of edit8 as a double % --- Executes during object creation, after setting all properties. function edit8_CreateFcn(hObject, eventdata, handles) % hObject handle to edit8 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit9_Callback(hObject, eventdata, handles) % hObject handle to edit9 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit9 as text % str2double(get(hObject,'String')) returns contents of edit9 as a double
8/06/15 15:52 D:\PFG_programa_final\toplot.m 7 of 37 % --- Executes during object creation, after setting all properties. function edit9_CreateFcn(hObject, eventdata, handles) % hObject handle to edit9 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit10_Callback(hObject, eventdata, handles) % hObject handle to edit10 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit10 as text % str2double(get(hObject,'String')) returns contents of edit10 as a double % --- Executes during object creation, after setting all properties. function edit10_CreateFcn(hObject, eventdata, handles) % hObject handle to edit10 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit11_Callback(hObject, eventdata, handles) % hObject handle to edit11 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit11 as text % str2double(get(hObject,'String')) returns contents of edit11 as a double % --- Executes during object creation, after setting all properties. function edit11_CreateFcn(hObject, eventdata, handles) % hObject handle to edit11 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
8/06/15 15:52 D:\PFG_programa_final\toplot.m 8 of 37 % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit12_Callback(hObject, eventdata, handles) % hObject handle to edit12 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit12 as text % str2double(get(hObject,'String')) returns contents of edit12 as a double % --- Executes during object creation, after setting all properties. function edit12_CreateFcn(hObject, eventdata, handles) % hObject handle to edit12 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function et_output1_Callback(hObject, eventdata, handles) % hObject handle to et_output1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of et_output1 as text % str2double(get(hObject,'String')) returns contents of et_output1 as a double set(handles.cbo1,'Value',1); % --- Executes during object creation, after setting all properties. function et_output1_CreateFcn(hObject, eventdata, handles) % hObject handle to et_output1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
8/06/15 15:52 D:\PFG_programa_final\toplot.m 9 of 37 end function et_output2_Callback(hObject, eventdata, handles) % hObject handle to et_output2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of et_output2 as text % str2double(get(hObject,'String')) returns contents of et_output2 as a double set(handles.cbo2,'Value',1); % --- Executes during object creation, after setting all properties. function et_output2_CreateFcn(hObject, eventdata, handles) % hObject handle to et_output2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function et_input1_Callback(hObject, eventdata, handles) % hObject handle to et_input1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of et_input1 as text % str2double(get(hObject,'String')) returns contents of et_input1 as a double set(handles.cbi1,'Value',1); % --- Executes during object creation, after setting all properties. function et_input1_CreateFcn(hObject, eventdata, handles) % hObject handle to et_input1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
8/06/15 15:52 D:\PFG_programa_final\toplot.m 10 of 37 function et_input2_Callback(hObject, eventdata, handles) % hObject handle to et_input2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of et_input2 as text % str2double(get(hObject,'String')) returns contents of et_input2 as a double set(handles.cbi2,'Value',1); % --- Executes during object creation, after setting all properties. function et_input2_CreateFcn(hObject, eventdata, handles) % hObject handle to et_input2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function et_input3_Callback(hObject, eventdata, handles) % hObject handle to et_input3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of et_input3 as text % str2double(get(hObject,'String')) returns contents of et_input3 as a double set(handles.cbi3,'Value',1); % --- Executes during object creation, after setting all properties. function et_input3_CreateFcn(hObject, eventdata, handles) % hObject handle to et_input3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function et_input4_Callback(hObject, eventdata, handles) % hObject handle to et_input4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
8/06/15 15:52 D:\PFG_programa_final\toplot.m 11 of 37 % Hints: get(hObject,'String') returns contents of et_input4 as text % str2double(get(hObject,'String')) returns contents of et_input4 as a double set(handles.cbi4,'Value',1); % --- Executes during object creation, after setting all properties. function et_input4_CreateFcn(hObject, eventdata, handles) % hObject handle to et_input4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function et_coloro1_Callback(hObject, eventdata, handles) % hObject handle to et_coloro1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of et_coloro1 as text % str2double(get(hObject,'String')) returns contents of et_coloro1 as a double set(handles.cbo1,'Value',1); % --- Executes during object creation, after setting all properties. function et_coloro1_CreateFcn(hObject, eventdata, handles) % hObject handle to et_coloro1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function et_coloro2_Callback(hObject, eventdata, handles) % hObject handle to et_coloro2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of et_coloro2 as text % str2double(get(hObject,'String')) returns contents of et_coloro2 as a double set(handles.cbo2,'Value',1);
8/06/15 15:52 D:\PFG_programa_final\toplot.m 12 of 37 % --- Executes during object creation, after setting all properties. function et_coloro2_CreateFcn(hObject, eventdata, handles) % hObject handle to et_coloro2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function et_colori1_Callback(hObject, eventdata, handles) % hObject handle to et_colori1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of et_colori1 as text % str2double(get(hObject,'String')) returns contents of et_colori1 as a double set(handles.cbi1,'Value',1); % --- Executes during object creation, after setting all properties. function et_colori1_CreateFcn(hObject, eventdata, handles) % hObject handle to et_colori1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function et_colori2_Callback(hObject, eventdata, handles) % hObject handle to et_colori2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of et_colori2 as text % str2double(get(hObject,'String')) returns contents of et_colori2 as a double set(handles.cbi2,'Value',1); % --- Executes during object creation, after setting all properties.
8/06/15 15:52 D:\PFG_programa_final\toplot.m 13 of 37 function et_colori2_CreateFcn(hObject, eventdata, handles) % hObject handle to et_colori2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function et_colori3_Callback(hObject, eventdata, handles) % hObject handle to et_colori3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of et_colori3 as text % str2double(get(hObject,'String')) returns contents of et_colori3 as a double set(handles.cbi3,'Value',1); % --- Executes during object creation, after setting all properties. function et_colori3_CreateFcn(hObject, eventdata, handles) % hObject handle to et_colori3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function et_colori4_Callback(hObject, eventdata, handles) % hObject handle to et_colori4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of et_colori4 as text % str2double(get(hObject,'String')) returns contents of et_colori4 as a double set(handles.cbi4,'Value',1); % --- Executes during object creation, after setting all properties. function et_colori4_CreateFcn(hObject, eventdata, handles) % hObject handle to et_colori4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB
8/06/15 15:52 D:\PFG_programa_final\toplot.m 14 of 37 % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in pb_plot. function pb_plot_Callback(hObject, eventdata, handles) % hObject handle to pb_plot (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) temps=evalin('base','temps'); warning off; prelegend=[]; lengpreleg=-1; figure; hold all; redO=evalin('base','O1'); redI=evalin('base','I1'); lonredO=length(redO); lonredI=length(redI); if lonredI>lonredO I1=evalin('base','I1'); I2=evalin('base','I2'); I3=evalin('base','I3'); I4=evalin('base','I4'); aux1=I1; aux2=I2; aux3=I3; aux4=I4; I1=[]; I2=[]; I3=[]; I4=[]; for i=1:lonredO I1(i)=aux1(i); I2(i)=aux2(i); I3(i)=aux3(i); I4(i)=aux4(i); end assignin('base','I1',I1'); assignin('base','I2',I2'); assignin('base','I3',I3'); assignin('base','I4',I4'); else if lonredO>lonredI O1=evalin('base','O1'); O2=evalin('base','O2'); aux1=O1; aux2=O2; O1=[]; O2=[];
8/06/15 15:52 D:\PFG_programa_final\toplot.m 15 of 37 for i=1:lonredO O1(1,i)=aux1(i); O2(1,i)=aux2(i); end assignin('base','O1',O1'); assignin('base','O2',O2'); end end if get(handles.cbo1,'Value')==1 O1=evalin('base','O1'); string_actual=get(handles.et_output1,'String'); if lengpreleg==-1 prelegend=[prelegend; string_actual]; lengpreleg=length(prelegend); else if lengpreleg<length(string_actual) auxprelegend=prelegend; prelegend=[]; for i=1:length(auxprelegend(:,1))%crea el nuevo prelegend singlelegend=auxprelegend(i,:); singlelegend=strcat(auxprelegend(i,:),'·'); for j=1:length(string_actual)-length(singlelegend)%añade espacios singlelegend=strcat(singlelegend,'·'); end prelegend=[prelegend; singlelegend]; end else if (lengpreleg-length(string_actual))~=0 for j=1:lengpreleg-length(string_actual)%añade espacios string_actual=strcat(string_actual,'·'); end end end prelegend=[prelegend; string_actual]; lengpreleg=length(prelegend); end proiedades=-1;%resetejem la variable de propietats que anira per cada %una dels senyals linea=get(handles.estillineaO1,'Value'); switch linea case 1 propiedades='-'; case 2 propiedades='--'; case 3 propiedades=':'; otherwise propiedades='-.'; end color=get(handles.colorO1,'Value'); switch color case 1 propiedades=strcat(propiedades,'b'); case 2
8/06/15 15:52 D:\PFG_programa_final\toplot.m 22 of 37 auxprelegend=prelegend; prelegend=[]; for i=1:length(auxprelegend(:,1))%crea el nuevo prelegend singlelegend=auxprelegend(i,:); singlelegend=strcat(auxprelegend(i,:),'·'); for j=1:length(string_actual)-length(singlelegend)%añade espacios singlelegend=strcat(singlelegend,'·'); end prelegend=[prelegend; singlelegend]; end else if (lengpreleg-length(string_actual))~=0 for j=1:lengpreleg-length(string_actual)%añade espacios string_actual=strcat(string_actual,'·'); end end end prelegend=[prelegend; string_actual]; lengpreleg=length(prelegend); end proiedades=-1; linea=get(handles.estillineaI3,'Value'); switch linea case 1 propiedades='-'; case 2 propiedades='--'; case 3 propiedades=':'; otherwise propiedades='-.'; end color=get(handles.colorI3,'Value'); switch color case 1 propiedades=strcat(propiedades,'b'); case 2 propiedades=strcat(propiedades,'g'); case 3 propiedades=strcat(propiedades,'r'); case 4 propiedades=strcat(propiedades,'c'); case 5 propiedades=strcat(propiedades,'m'); case 6 propiedades=strcat(propiedades,'y'); otherwise propiedades=strcat(propiedades,'k'); end punt=get(handles.estilpuntI3,'Value'); switch punt case 1 case 2 propiedades=strcat(propiedades,'+');
8/06/15 15:52 D:\PFG_programa_final\toplot.m 23 of 37 case 3 propiedades=strcat(propiedades,'o'); case 4 propiedades=strcat(propiedades,'*'); case 5 propiedades=strcat(propiedades,'.'); case 6 propiedades=strcat(propiedades,'x'); case 7 propiedades=strcat(propiedades,'s'); case 8 propiedades=strcat(propiedades,'d'); case 9 propiedades=strcat(propiedades,'^'); case 10 propiedades=strcat(propiedades,'v'); case 11 propiedades=strcat(propiedades,'>'); case 12 propiedades=strcat(propiedades,'<'); case 13 propiedades=strcat(propiedades,'p'); otherwise propiedades=strcat(propiedades,'h'); end plot(temps,I3,propiedades); assignin('base',get(handles.et_input3,'String'),evalin('base','I3')); end if get(handles.cbi4,'Value')==1 I4=evalin('base','I4'); string_actual=get(handles.et_input4,'String'); if lengpreleg==-1 prelegend=[prelegend; string_actual]; lengpreleg=length(prelegend); else if lengpreleg<length(string_actual) auxprelegend=prelegend; prelegend=[]; for i=1:length(auxprelegend(:,1))%crea el nuevo prelegend singlelegend=auxprelegend(i,:); singlelegend=strcat(auxprelegend(i,:),'·'); for j=1:length(string_actual)-length(singlelegend)%añade espacios singlelegend=strcat(singlelegend,'·'); end prelegend=[prelegend; singlelegend]; end else if (lengpreleg-length(string_actual))~=0 for j=1:lengpreleg-length(string_actual)%añade espacios string_actual=strcat(string_actual,'·'); end end end
8/06/15 15:52 D:\PFG_programa_final\toplot.m 24 of 37 prelegend=[prelegend; string_actual]; lengpreleg=length(prelegend); end proiedades=-1; linea=get(handles.estillineaI4,'Value'); switch linea case 1 propiedades='-'; case 2 propiedades='--'; case 3 propiedades=':'; otherwise propiedades='-.'; end color=get(handles.colorI4,'Value'); switch color case 1 propiedades=strcat(propiedades,'b'); case 2 propiedades=strcat(propiedades,'g'); case 3 propiedades=strcat(propiedades,'r'); case 4 propiedades=strcat(propiedades,'c'); case 5 propiedades=strcat(propiedades,'m'); case 6 propiedades=strcat(propiedades,'y'); otherwise propiedades=strcat(propiedades,'k'); end punt=get(handles.estilpuntI4,'Value'); switch punt case 1 case 2 propiedades=strcat(propiedades,'+'); case 3 propiedades=strcat(propiedades,'o'); case 4 propiedades=strcat(propiedades,'*'); case 5 propiedades=strcat(propiedades,'.'); case 6 propiedades=strcat(propiedades,'x'); case 7 propiedades=strcat(propiedades,'s'); case 8 propiedades=strcat(propiedades,'d'); case 9 propiedades=strcat(propiedades,'^'); case 10 propiedades=strcat(propiedades,'v'); case 11 propiedades=strcat(propiedades,'>');
8/06/15 15:52 D:\PFG_programa_final\toplot.m 25 of 37 case 12 propiedades=strcat(propiedades,'<'); case 13 propiedades=strcat(propiedades,'p'); otherwise propiedades=strcat(propiedades,'h'); end plot(temps,I4,propiedades); assignin('base',get(handles.et_input4,'String'),evalin('base','I4')); end assignin('base','prelegend',prelegend); legend(prelegend); % --- Executes on selection change in colorO1. function colorO1_Callback(hObject, eventdata, handles) % hObject handle to colorO1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns colorO1 contents as cell array % contents{get(hObject,'Value')} returns selected item from colorO1 % --- Executes during object creation, after setting all properties. function colorO1_CreateFcn(hObject, eventdata, handles) % hObject handle to colorO1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in popupmenu2. function popupmenu2_Callback(hObject, eventdata, handles) % hObject handle to popupmenu2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu2 % --- Executes during object creation, after setting all properties. function popupmenu2_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
8/06/15 15:52 D:\PFG_programa_final\toplot.m 26 of 37 % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in popupmenu3. function popupmenu3_Callback(hObject, eventdata, handles) % hObject handle to popupmenu3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu3 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu3 % --- Executes during object creation, after setting all properties. function popupmenu3_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in popupmenu4. function popupmenu4_Callback(hObject, eventdata, handles) % hObject handle to popupmenu4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu4 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu4 % --- Executes during object creation, after setting all properties. function popupmenu4_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor'))
8/06/15 15:52 D:\PFG_programa_final\toplot.m 27 of 37 set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in popupmenu5. function popupmenu5_Callback(hObject, eventdata, handles) % hObject handle to popupmenu5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu5 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu5 % --- Executes during object creation, after setting all properties. function popupmenu5_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in popupmenu6. function popupmenu6_Callback(hObject, eventdata, handles) % hObject handle to popupmenu6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu6 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu6 % --- Executes during object creation, after setting all properties. function popupmenu6_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in estillineaO1.
8/06/15 15:52 D:\PFG_programa_final\toplot.m 28 of 37 function estillineaO1_Callback(hObject, eventdata, handles) % hObject handle to estillineaO1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns estillineaO1 contents as cell array % contents{get(hObject,'Value')} returns selected item from estillineaO1 % --- Executes during object creation, after setting all properties. function estillineaO1_CreateFcn(hObject, eventdata, handles) % hObject handle to estillineaO1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in popupmenu8. function popupmenu8_Callback(hObject, eventdata, handles) % hObject handle to popupmenu8 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu8 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu8 % --- Executes during object creation, after setting all properties. function popupmenu8_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu8 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in popupmenu9. function popupmenu9_Callback(hObject, eventdata, handles) % hObject handle to popupmenu9 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
8/06/15 15:52 D:\PFG_programa_final\toplot.m 29 of 37 % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu9 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu9 % --- Executes during object creation, after setting all properties. function popupmenu9_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu9 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in popupmenu10. function popupmenu10_Callback(hObject, eventdata, handles) % hObject handle to popupmenu10 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu10 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu10 % --- Executes during object creation, after setting all properties. function popupmenu10_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu10 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in popupmenu11. function popupmenu11_Callback(hObject, eventdata, handles) % hObject handle to popupmenu11 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu11 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu11
8/06/15 15:52 D:\PFG_programa_final\toplot.m 30 of 37 % --- Executes during object creation, after setting all properties. function popupmenu11_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu11 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in popupmenu12. function popupmenu12_Callback(hObject, eventdata, handles) % hObject handle to popupmenu12 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu12 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu12 % --- Executes during object creation, after setting all properties. function popupmenu12_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu12 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in colorO2. function colorO2_Callback(hObject, eventdata, handles) % hObject handle to colorO2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns colorO2 contents as cell array % contents{get(hObject,'Value')} returns selected item from colorO2 % --- Executes during object creation, after setting all properties. function colorO2_CreateFcn(hObject, eventdata, handles) % hObject handle to colorO2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
8/06/15 15:52 D:\PFG_programa_final\toplot.m 31 of 37 % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in colorI1. function colorI1_Callback(hObject, eventdata, handles) % hObject handle to colorI1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns colorI1 contents as cell array % contents{get(hObject,'Value')} returns selected item from colorI1 % --- Executes during object creation, after setting all properties. function colorI1_CreateFcn(hObject, eventdata, handles) % hObject handle to colorI1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in colorI2. function colorI2_Callback(hObject, eventdata, handles) % hObject handle to colorI2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns colorI2 contents as cell array % contents{get(hObject,'Value')} returns selected item from colorI2 % --- Executes during object creation, after setting all properties. function colorI2_CreateFcn(hObject, eventdata, handles) % hObject handle to colorI2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor'))
eq_continu eq_discreta Mostrar dades Amplitud Kp: 1 Variable: Continu: Discret: b0: b1: 2 Zero Tz: Retard Td: b2: a0: a1: a2: Retard: mostres Reset 3 Equació continu Equació discreta
8/06/15 15:52 D:\PFG_programa_final\identif.m 1 of 7 function varargout = identif(varargin) % IDENTIF MATLAB code for identif.fig % IDENTIF, by itself, creates a new IDENTIF or raises the existing % singleton*. % % H = IDENTIF returns the handle to a new IDENTIF or the handle to % the existing singleton*. % % IDENTIF('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in IDENTIF.M with the given input arguments. % % IDENTIF('Property','Value',...) creates a new IDENTIF or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before identif_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to identif_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help identif % Last Modified by GUIDE v2.5 06-Jun-2015 15:46:10 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @identif_OpeningFcn, ... 'gui_OutputFcn', @identif_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before identif is made visible. function identif_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to identif (see VARARGIN) % Choose default command line output for identif
8/06/15 15:52 D:\PFG_programa_final\identif.m 2 of 7 handles.output = hObject; evalin('base','clc'); ident; axes(handles.eq_discreta); imshow('Discrete_transfere_function.PNG'); % Update handles structure guidata(hObject, handles); % UIWAIT makes identif wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = identif_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in start. function start_Callback(hObject, eventdata, handles) % hObject handle to start (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in pb_mostrar. function pb_mostrar_Callback(hObject, eventdata, handles) % hObject handle to pb_mostrar (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) evalin('base','clc'); try var=get(handles.et_variable,'String'); existe=evalin('base',var); catch msgbox('Aquesta variable no existeig en el Workspace','Error!') ; return; end var=strcat(var,'.Kp'); K=evalin('base',var); K=str2double(sprintf('%.3f',K)); assignin('base','K',K); set(handles.dt_k,'String',K); var=get(handles.et_variable,'String'); var=strcat(var,'.Td'); Retard=evalin('base',var); Retard=str2double(sprintf('%.3f',Retard)); assignin('base','Retard',Retard);
8/06/15 15:52 D:\PFG_programa_final\identif.m 3 of 7 set(handles.dt_retard,'String',Retard); var=get(handles.et_variable,'String'); var=strcat(var,'.Tz'); Zero=evalin('base',var); Zero=str2double(sprintf('%.3f',Zero)); assignin('base','Zero',Zero); set(handles.dt_zero,'String',Zero); var=get(handles.et_variable,'String'); var=strcat(var,'.Tp1'); tipus=evalin('base',var); if tipus==0 axes(handles.eq_continu); imshow('Underdamped.PNG'); set(handles.st_1,'Visible','on'); set(handles.dt_1,'Visible','on'); set(handles.st_2,'Visible','on'); set(handles.dt_2,'Visible','on'); set(handles.st_3,'Visible','off'); set(handles.dt_3,'Visible','off'); var=get(handles.et_variable,'String'); var=strcat(var,'.Zeta'); Xi=evalin('base',var); Xi=str2double(sprintf('%.3f',Xi)); assignin('base','Xi',Xi); set(handles.dt_1,'String',Xi); set(handles.st_1,'String','Xi Zeta:'); var=get(handles.et_variable,'String'); var=strcat(var,'.Tw'); Wn=evalin('base',var); Wn=str2double(sprintf('%.3f',Wn)); assignin('base','Wn',Wn); set(handles.dt_2,'String',Wn); set(handles.st_2,'String','Wn Tw:'); den=[Wn^2 Xi*Wn*2 1]; assignin('base','den',den); else axes(handles.eq_continu); imshow('AllReal.PNG'); set(handles.st_1,'Visible','on'); set(handles.dt_1,'Visible','on'); set(handles.st_2,'Visible','on'); set(handles.dt_2,'Visible','on'); set(handles.st_3,'Visible','on');
8/06/15 15:52 D:\PFG_programa_final\identif.m 4 of 7 set(handles.dt_3,'Visible','on'); var=get(handles.et_variable,'String'); var=strcat(var,'.Tp1'); Tau1=evalin('base',var); Tau1=str2double(sprintf('%.3f',Tau1)); assignin('base','Tau1',Tau1); set(handles.dt_1,'String',Tau1); set(handles.st_1,'String','Tau1 Tp1:'); var=get(handles.et_variable,'String'); var=strcat(var,'.Tp2'); Tau2=evalin('base',var); Tau2=str2double(sprintf('%.3f',Tau2)); assignin('base','Tau2',Tau2); set(handles.dt_2,'String',Tau2); set(handles.st_2,'String','Tau2 Tp2:'); var=get(handles.et_variable,'String'); var=strcat(var,'.Tp3'); Tau3=evalin('base',var); Tau3=str2double(sprintf('%.3f',Tau3)); assignin('base','Tau3',Tau3); set(handles.dt_3,'String',Tau3); set(handles.st_3,'String','Tau3 Tp3:'); den=[Tau1*Tau2*Tau3 (Tau1*Tau2)+(Tau2+Tau1)*Tau3 Tau2+Tau1+Tau3 1]; assignin('base','den',den); end num=[0 K*Zero K]; assignin('base','num',num); delay=Retard; assignin('base','delay',delay); G=tf(num,den,'IoDelay',delay) var=get(handles.et_variable,'String'); var_s=strcat(var,'_Gs'); assignin('base',var_s,G); PeriodeMostreig=evalin('base','PeriodeMostreig'); Gd=c2d(G,PeriodeMostreig) var_d=strcat(var,'_Gd'); assignin('base',var_d,Gd); lengnum=length(Gd.num{1,1}); lengden=length(Gd.den{1,1}); num1=Gd.num{1,1}(1); num1=str2double(sprintf('%.3f',num1)); if lengnum>2 num2=Gd.num{1,1}(2); num2=str2double(sprintf('%.3f',num2));
8/06/15 15:52 D:\PFG_programa_final\identif.m 5 of 7 else num2=0; end if lengnum>3 num3=Gd.num{1,1}(3); num3=str2double(sprintf('%.3f',num3)); else num3=0; end den1=Gd.den{1,1}(1); den1=str2double(sprintf('%.3f',den1)); if lengden>2 den2=Gd.den{1,1}(2); den2=str2double(sprintf('%.3f',den2)); else den2=0; end if lengden>3 den3=Gd.den{1,1}(3); den3=str2double(sprintf('%.3f',den3)); else den3=0; end set(handles.dt_b0,'String',num1); set(handles.dt_b1,'String',num2); set(handles.dt_b2,'String',num3); set(handles.dt_a0,'String',den1); set(handles.dt_a1,'String',den2); set(handles.dt_a2,'String',den3); set(handles.dt_retardm,'String',Gd.ioDelay); set(handles.text_avis,'String','A la "comand windows" teniu les funcions de transferencia'); set(handles.text_avis,'BackgroundColor',[1 1 0]); function et_variable_Callback(hObject, eventdata, handles) % hObject handle to et_variable (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of et_variable as text % str2double(get(hObject,'String')) returns contents of et_variable as a double % --- Executes during object creation, after setting all properties. function et_variable_CreateFcn(hObject, eventdata, handles)
8/06/15 15:52 D:\PFG_programa_final\identif.m 6 of 7 % hObject handle to et_variable (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get (0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in pb_clear. function pb_clear_Callback(hObject, eventdata, handles) % hObject handle to pb_clear (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.et_variable,'String',''); set(handles.dt_k,'String',''); set(handles.dt_retard,'String',''); set(handles.dt_zero,'String',''); set(handles.dt_1,'String',''); set(handles.dt_2,'String',''); set(handles.dt_3,'String',''); set(handles.dt_1,'Visible','off'); set(handles.dt_2,'Visible','off'); set(handles.dt_3,'Visible','off'); set(handles.st_1,'Visible','off'); set(handles.st_2,'Visible','off'); set(handles.st_3,'Visible','off'); set(handles.dt_b0,'String',''); set(handles.dt_b1,'String',''); set(handles.dt_b2,'String',''); set(handles.dt_a0,'String',''); set(handles.dt_a1,'String',''); set(handles.dt_a2,'String',''); set(handles.dt_retardm,'String',''); set(handles.text_avis,'String',''); set(handles.text_avis,'BackgroundColor',[0.941 0.941 0.941]); axes(handles.eq_continu); cla; evalin('base','clc'); % --- Executes during object creation, after setting all properties. function eq_discreta_CreateFcn(hObject, eventdata, handles) % hObject handle to eq_discreta (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB
8/06/15 15:52 D:\PFG_programa_final\identif.m 7 of 7 % handles empty - handles not created until after all CreateFcns called imshow('Discrete_transfere_function.PNG'); % Hint: place code in OpeningFcn to populate eq_discreta
sortida acciocontrol sortida_real acciocontrol_real Kp: Ki: 0 0 Simulacio Asumeixes els valor com correctes? Sortida Accio de control Control Real Sortida Accio de control Mostrar dades En una figura externa Valor máxim:
8/06/15 15:52 D:\PFG_programa_final\control.m 1 of 9 function varargout = control(varargin) % CONTROL MATLAB code for control.fig % CONTROL, by itself, creates a new CONTROL or raises the existing % singleton*. % % H = CONTROL returns the handle to a new CONTROL or the handle to % the existing singleton*. % % CONTROL('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in CONTROL.M with the given input arguments. % % CONTROL('Property','Value',...) creates a new CONTROL or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before control_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to control_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help control % Last Modified by GUIDE v2.5 06-Jun-2015 15:29:24 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @control_OpeningFcn, ... 'gui_OutputFcn', @control_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before control is made visible. function control_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to control (see VARARGIN) % Choose default command line output for control