Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stationen.h"
- /******************************* Kommentare und Änderungen ***********************************/
- // Änderungen FB1:
- // Übergang aus Standby bei count > 0 statt count == 1
- // "statepulse" entfernt
- // hatKiste = 1 schon einen State früher (state 2)
- // Änderungen DT1:
- // Übergang aus Standby bei fbi.typ > 0 gelöscht (tritt nie ein wegen hatKiste)
- // Änderungen Waage:
- // waage.bereit = 0 wird später gesetzt (state 5)
- // timer_info gelöscht
- // In case 9 springt er immer zurück auf "Standby" statt auf "Hole Kiste".
- // (Einheitlicher) Ist dt1.typ > 0 springt er dann direkt weiter.
- // Hab noch eine Filterung reingebaut, die extreme Werte raushaut
- // Änderungen DT2:
- // dt2.bereit = 0 wird später gesetzt (state 5)
- // Änderungen Mixer:
- // Timer_1_def gelöscht
- // Timer_0 und Timer_1 zusammengefasst und umbennant in timer
- // mixer.bereit = 1 wird früher gesetzt (state 8)
- // Rücksprung aus Rausholen nur nach Standby (wie bei Waage)
- // Änderungen TempReg:
- // irgendwo ein temp < temp_max ersetzt durch temp <= temp_max
- // Änderungen Ofen:
- // ofenzeit umbenannt in timer
- // bei case 3 if-Bedingung geändert: ofen.SIO == 0 statt ofen.SIO == 1
- // (sonst springt er immer direkt weiter)
- // bei case 4 if-Bedingung geändert: ofen.SIO == 1 statt ofen.SIO == 0
- // (kann sein dass invertierte Logik?? -> umändern! / erledigt)
- // ofen.bereit = 0 erst bei state 5
- //
- // Ansonsten habe ich alle "Typ" durch "typ" und "Z" durch "z"s ersetzt.
- // Alle restlichen printfs durch idsci_printfs ersetzt.
- // -Mathias-
- //
- //
- //
- //
- //
- /******************************** Zähler **************************************************/
- void f_zaehler(void){
- static char state;
- //init:
- if (erster_aufruf)
- { state = 2;
- fb1.count = 0;
- if (states) {idsci_printf("Zaehler: Lichtschranke frei\n");}
- }
- switch (state) {
- case 1: //blockiert
- if (fb1.SLE == 0)
- { state = 2;
- if (states) {idsci_printf("Zaehler: Lichtschranke frei\n");}
- }
- break;
- case 2: //frei
- if (fb1.SLE == 1)
- { fb1.count++;
- state = 1;
- if (states) {idsci_printf("Zaehler: Lichtschranke blockiert\n");}
- }
- break;
- }
- }
- /********************************* FB1 ***************************************************/
- void f_FB1(void){
- static char state;
- static char pulse;
- static int timer;
- //idsci_printf("fb1 timer:%i\n",timer);
- //init:
- if (erster_aufruf)
- { fb1.typ = 0;
- fb1.hatKiste = 0;
- state = 0;
- pulse = 1;
- timer = 0;
- if (states) {idsci_printf("FB: Warte auf Kiste\n");}
- }
- switch (state){
- case 0: //standby
- fb1.MFB1 = 0;
- if (fb1.count > 0)
- { state = 1;
- if (states) {idsci_printf("FB: Transpotiere\n");}
- }
- break;
- case 1: //fährt
- fb1.MFB1 = 1;
- if (fb1.SIF1 == 1)
- { state = 2;
- //if (states) {idsci_printf("FB1: Kiste am Ende\n");}
- }
- break;
- case 2:
- fb1.MFB1 = 1;
- if (fb1.SIF1 == 0)
- { state = 3;
- fb1.hatKiste = 1;
- if (states) {idsci_printf("FB: Kiste bereit\n");}
- }
- break;
- case 3: //Drehtisch bereit?
- fb1.MFB1 = 0;
- if (dt1.bereit == 1)
- { timer = 500 * 1000/T_syst; // Beim Zählen Xms warten
- pulse = 1;
- state = 4;
- if (states) {idsci_printf("FB: Zaehle Pulse\n");}
- }
- break;
- case 4: //zähle Pulse
- fb1.MFB1 = 1;
- timer--;
- if (timer < 0)
- { timer = 2000 *1000/T_syst; // Beim Rausschieben Xms warten
- fb1.typ = 1;
- fb1.count--;
- state = 6;
- if (states) {idsci_printf("FB: Schiebe raus, Typ: %i\n",fb1.typ);}
- }
- if (fb1.SIF1 == 1)
- { timer = 750 *1000/T_syst;
- fb1.typ = 2;
- fb1.count--;
- state = 5;
- if (states) {idsci_printf("FB: Schiebe raus, Typ: %i\n",fb1.typ);}
- }
- break;
- case 5:
- fb1.MFB1 = 1;
- timer--;
- if (timer < 0)
- { timer = 2000 *1000/T_syst; // Beim Rausschieben Xms warten
- state = 6;
- }
- break;
- case 6: //Rausschieben
- fb1.MFB1 = 1;
- timer--;
- if (fb1.SIF1 == 1)
- { fb1.typ = 0;
- state = 2;
- fb1.hatKiste = 0;
- //if (states) {idsci_printf("FB1: Kiste am Ende\n");}
- }
- if (timer < 0)
- { fb1.typ = 0;
- state = 0;
- fb1.hatKiste = 0;
- if (states) {idsci_printf("FB: Warte auf Kiste\n");}
- }
- }
- }
- /********************************* DT1 ***************************************************/
- void f_DT1(void){
- static char state;
- static char typ;
- static char z;
- static int timer;
- //init
- if (erster_aufruf)
- { dt1.typ = 0;
- dt1.bereit = 0;
- state = 0;
- typ = 0;
- z = 0;
- timer = 0;
- if (states) {idsci_printf("DT1: Drehe zum Band\n");}
- }
- switch (state){
- case 0: //Turn left
- if (dt1.STD1B == 1)
- { dt1.bereit = 1;
- state = 1;
- if (states) {idsci_printf("DT1: Bin bereit\n");}
- }else{
- dt1.MD1F = 1;
- dt1.MD1W = 0;
- dt1.MFBD1 = 0;
- break;
- }
- case 1: //Standby
- dt1.MD1F = 0;
- dt1.MD1W = 0;
- dt1.MFBD1 = 0;
- if(fb1.hatKiste){
- state = 99;
- dt1.MFBD1 = 1;
- if (states) {idsci_printf("DT1: Hole Kiste\n");}
- }
- break;
- case 99: // Hole Kiste bevor Typ bekannt
- if (fb1.typ)
- { typ = fb1.typ;
- z = typ;
- dt1.bereit = 0;
- state = 2;
- dt1.MFBD1 = 1;
- }
- break;
- case 2: //Hole Kiste
- dt1.MD1F = 0;
- dt1.MD1W = 0;
- dt1.MFBD1 = 1;
- if (dt1.SID1 == 1)
- { z--;
- state = 3;
- }
- break;
- case 3: //Unterscheide Typ
- dt1.MD1F = 0;
- dt1.MD1W = 0;
- dt1.MFBD1 = 1;
- if (z == 1) {state = 4;}
- if (z == 0)
- { state = 5;
- if (states) {idsci_printf("DT1: Drehe zur Waage\n");}
- }
- break;
- case 4:
- dt1.MD1F = 0;
- dt1.MD1W = 0;
- dt1.MFBD1 = 1;
- if (dt1.SID1 == 0) {state = 2;}
- break;
- case 5: //Turn rightt.elf
- if (dt1.STD1W == 1)
- { dt1.typ = typ;
- state = 6;
- if (states) {idsci_printf("DT1: Warte auf Waage\n");}
- }else{
- dt1.MD1F = 0;
- dt1.MD1W = 1;
- dt1.MFBD1 = 0;
- break;
- }
- case 6: //Warte auf Waage
- dt1.MD1F = 0;
- dt1.MD1W = 0;
- dt1.MFBD1 = 0;
- if (waage.bereit)
- { timer = 2000 * 1000/T_syst; // Beim Rausschieben 2000ms warten
- state = 7;
- if (states) {idsci_printf("DT1: Schiebe raus\n");}
- }
- break;
- case 7: //Rausschieben
- dt1.MD1F = 0;
- dt1.MD1W = 0;
- dt1.MFBD1 = 1;
- timer--;
- if (timer < 0)
- { dt1.typ = 0;
- typ = 0;
- z = 0;
- timer = 0;
- state = 0;
- if (states) {idsci_printf("DT1: Drehe zum Band\n");}
- }
- }
- }
- /******************************** Waage **************************************************/
- void f_Waage(void){
- static char state;
- static char typ;
- static char z;
- static int timer;
- static int n0;
- int n;
- static int ntief;
- //init
- if (erster_aufruf)
- { waage.bereit = 1;
- waage.typ = 0;
- typ = 0;
- z = 0;
- n0 = 0;
- ntief = TPU_GetPPWACount(0); //44000;
- //f = 0;
- timer = 0;
- state = 0;
- if (states) {idsci_printf("Waage: Warte auf DT1\n");}
- }
- n = TPU_GetPPWACount(0);
- if ((n>ntief*0.99) && (n<ntief*1.01))
- {
- ntief = (ntief*49 + TPU_GetPPWACount(0))/50; // Holt letzten gültigen Wert, wird dann alles tiefpassgefiltert
- }
- //f = 255 * 2083750 / ntief; // f0 = N * fTCR / n ; mit fTCR = Systemfrequenz * 1/8
- //idsci_printf("ntief = %i\n",ntief);
- switch (state) {
- case 0: //Standby
- waage.MFS1 = 0;
- waage.MFS2 = 0;
- waage.MFS3 = 0;
- waage.MFBW = 0;
- if (dt1.typ > 0) {
- state = 1;
- typ = dt1.typ;
- z = typ;
- if (states) {idsci_printf("Waage: Hole Kiste\n");}
- }
- break;
- case 1: //Hole Kiste
- waage.MFS1 = 0;
- waage.MFS2 = 0;
- waage.MFS3 = 0;
- waage.MFBW = 1;
- if (waage.SIFW == 1) {
- z--;
- state = 2;
- }
- break;
- case 2:
- waage.MFS1 = 0;
- waage.MFS2 = 0;
- waage.MFS3 = 0;
- waage.MFBW = 1;
- if (z == 0) {
- state = 3;
- waage.bereit = 0;
- if (states) {idsci_printf("Waage: Silos checken\n");}
- }
- if (waage.SIFW == 0) {
- state = 1;
- }
- break;
- case 3: //Silos gefüllt?
- waage.MFS1 = 0;
- waage.MFS2 = 0;
- waage.MFS3 = 0;
- waage.MFBW = 0;
- if (waage.SLS1*waage.SLS2*waage.SLS3 == 1) {
- state = 4;
- timer = 1000 * 1000/T_syst; //Kalibriere 1s lang
- if (states) {idsci_printf("Waage: Kalibriere\n");}
- }else{
- //idsci_printf("Silos prüfen und nachfüllen!\n");
- }
- break;
- case 4: //Kalibriere
- waage.MFS1 = 0;
- waage.MFS2 = 0;
- waage.MFS3 = 0;
- waage.MFBW = 0;
- if (timer-- < 0) {
- n0 = ntief;
- state = 5;
- if (states) {idsci_printf("Waage: Einfüllen Zutat 1\n");}
- }
- break;
- case 5: //Fülle Zutat 1
- waage.MFS1 = 1;
- waage.MFS2 = 0;
- waage.MFS3 = 0;
- waage.MFBW = 0;
- if ((n0-ntief)>=rezept[typ-1].menge1 *10) {
- state = 10;
- timer = 1000 * 1000/T_syst; //Warte
- if (states) {idsci_printf("Waage: Einfüllen Zutat 2\n");}
- }
- break;
- case 10: //Kalibriere
- waage.MFS1 = 0;
- waage.MFS2 = 0;
- waage.MFS3 = 0;
- waage.MFBW = 0;
- if (timer-- < 0) {
- n0 = ntief;
- state = 6;
- }
- break;
- case 6: //Fülle Zutat 2
- waage.MFS1 = 0;
- waage.MFS2 = 1;
- waage.MFS3 = 0;
- waage.MFBW = 0;
- if ((n0-ntief)>=rezept[typ-1].menge2 *10) {
- state = 11;
- timer = 1000 * 1000/T_syst; //Warte
- if (states) {idsci_printf("Waage: Einfüllen Zutat 3\n");}
- }
- break;
- case 11: //Kalibriere
- waage.MFS1 = 0;
- waage.MFS2 = 0;
- waage.MFS3 = 0;
- waage.MFBW = 0;
- if (timer-- < 0) {
- n0 = ntief;
- state = 7;
- }
- break;
- case 7: //Fülle Zutat 3
- waage.MFS1 = 0;
- waage.MFS2 = 0;
- waage.MFS3 = 1;
- waage.MFBW = 0;
- if ((n0-ntief)>=rezept[typ-1].menge3 *10) {
- state = 8;
- waage.typ = typ;
- if (states) {idsci_printf("Waage: Warte auf DT2\n");}
- }
- break;
- case 8: //Warte auf DT2
- waage.MFS1 = 0;
- waage.MFS2 = 0;
- waage.MFS3 = 0;
- waage.MFBW = 0;
- if ( dt2.bereit ) {
- state = 9;
- waage.bereit = 1;
- timer = 2000 * 1000/T_syst; //Rausschieben: 2s
- if (states) {idsci_printf("Waage: Kiste rausschieben\n");}
- }
- break;
- case 9: //Kiste rausschieben
- waage.MFS1 = 0;
- waage.MFS2 = 0;
- waage.MFS3 = 0;
- waage.MFBW = 1;
- timer--;
- if( dt1.typ == 0 ) {
- if ( timer < 0 ) {
- state = 0;
- waage.typ = 0;
- if (states) {idsci_printf("Waage: Warte auf DT1\n");}
- }
- }
- else {
- if( timer < 1500 * 1000/T_syst ) {
- state = 0;
- waage.typ = 0;
- }
- }
- break;
- }
- }
- /*********************************** DT2 **************************************************/
- void f_DT2(void){
- static char state;
- static char typ;
- static char z;
- static int timer;
- //init
- if (erster_aufruf)
- { dt2.typ = 0;
- dt2.bereit = 0;
- state = 0;
- typ = 0;
- z = 0;
- timer = 0;
- if (states) {idsci_printf("DT2: Drehe zur Waage\n");}
- }
- switch (state){
- case 0: //Turn left
- if (dt2.STD2W == 1)
- { dt2.bereit = 1;
- state = 1;
- if (states) {idsci_printf("DT2: Bin bereit\n");}
- }else{
- dt2.MD2W = 1;
- dt2.MD2M = 0;
- dt2.MFBD2 = 0;
- break;
- }
- case 1: //Standby
- dt2.MD2W = 0;
- dt2.MD2M = 0;
- dt2.MFBD2 = 0;
- if (waage.typ)
- { typ = waage.typ;
- z = typ;
- state = 2;
- dt2.MFBD2 = 1;
- if (states) {idsci_printf("DT2: Hole Kiste\n");}
- }
- break;
- case 2: //Hole Kiste
- dt2.MD2W = 0;
- dt2.MD2M = 0;
- dt2.MFBD2 = 1;
- if (dt2.SID2 == 1)
- { z--;
- state = 3;
- }
- break;
- case 3: //Unterscheide Typ
- dt2.MD2W = 0;
- dt2.MD2M = 0;
- dt2.MFBD2 = 1;
- if (z == 1) {state = 4;}
- if (z == 0)
- { state = 5;
- dt2.bereit = 0;
- if (states) {idsci_printf("DT2: Drehe zum Mixer\n");}
- }
- break;
- case 4:
- dt2.MD2W = 0;
- dt2.MD2M = 0;
- dt2.MFBD2 = 1;
- if (dt2.SID2 == 0) {state = 2;}
- break;
- case 5: //Turn right
- if (dt2.STD2M == 1)
- { dt2.typ = typ;
- state = 6;
- if (states) {idsci_printf("DT2: Warte auf Mixer\n");}
- }else{
- dt2.MD2W = 0;
- dt2.MD2M = 1;
- dt2.MFBD2 = 0;
- break;
- }
- case 6: //Warte auf Mixer
- dt2.MD2W = 0;
- dt2.MD2M = 0;
- dt2.MFBD2 = 0;
- if (mixer.bereit == 1)
- { timer = 2000 * 1000/T_syst; // Beim Rausschieben 2000ms warten
- state = 7;
- if (states) {idsci_printf("DT2: Schiebe raus\n");}
- }
- break;
- case 7: //Rausschieben
- dt2.MD2W = 0;
- dt2.MD2M = 0;
- dt2.MFBD2 = 1;
- timer--;
- if (timer < 0)
- { dt2.typ = 0;
- state = 0;
- typ = 0;
- z = 0;
- timer = 0;
- if (states) {idsci_printf("DT2: Drehe zur Waage\n");}
- }
- }
- }
- /*********************************** Mixer **************************************************/
- void f_Mixer(void){
- // lokale Variablen:
- static char state; // Zustand der state machine
- static char typ; // Art der Kiste die gerade im Mixer ist
- static char z; // Zähler für den Kistentyp
- static int timer; // Zählvariable für Timeouts
- if (erster_aufruf)
- { state = 0;
- mixer.bereit = 0;
- mixer.typ = 0;
- if (states) {idsci_printf("Mixer: Mixer hochfahren\n");}
- }
- /* globale Variablen auf die zugegriffen wird:
- INPUT:
- SENSOREN:
- STMG Sensor Taster Mixer Grundposition
- STMA Sensor Taster Mixer Arbeitsposition
- SIFM Sensor Induktion F rderband Mixer
- int DT2_typ
- int O_bereit
- int mixzeit() legt die Zeit fest die gebacken werden soll, Array über Kistentyp
- OUTPUT:
- AKTOREN:
- MFBM Motor Förderband Mixer
- MMAN Motor Mixer AN
- MMAP Motor Mixer Arbeitsposition -> runter
- MMG rezept[typ - 1].mixzeit *1000/T_syst; Motor Mixer Grundposition -> hoch
- int M_bereit
- int M_typ
- */
- // state machine
- switch (state) {
- // HOCHFAHREN
- case 0:
- mixer.MFBM = 0;
- mixer.MMAN = 0;
- mixer.MMAP = 0;
- mixer.MMG = 1;
- mixer.typ = 0;
- if (mixer.STMG == 0) {}
- else {
- mixer.bereit = 1;
- state = 1;
- if (states) {idsci_printf("Mixer: Warte auf Drehtisch\n");}
- }
- break;
- // STAND BY
- case 1:
- mixer.MFBM = 0;
- mixer.MMAN = 0;
- mixer.MMAP = 0;
- mixer.MMG = 0;
- if (dt2.typ == 0) {}
- else {
- typ = dt2.typ;
- z = dt2.typ;
- tempregelung.vorheizen_typ = dt2.typ;
- state = 2;
- if (states) {idsci_printf("Mixer: Hole Kiste\n");}
- }
- break;
- // HOLE KISTE
- case 2:
- mixer.MFBM = 1;
- mixer.MMAN = 0;
- mixer.MMAP = 0;
- mixer.MMG = 0;
- if (mixer.SIFM == 1) {
- z--;
- if (z == 0) {
- state = 4;
- mixer.bereit = 0;
- if (states) {idsci_printf("Mixer: Mixer runterfahren\n");}
- }
- else {
- state = 3; }
- }
- else {
- state = 2;
- }
- break;
- // KISTE WEITERFAHREN
- case 3:
- mixer.MFBM = 1;
- mixer.MMAN = 0;
- mixer.MMAP = 0;
- mixer.MMG = 0;
- if (mixer.SIFM == 0) {
- state = 2;
- }
- else {
- state = 3;
- }
- break;
- // MIXER RUNTERFAHREN
- case 4:
- mixer.MFBM = 0;
- mixer.MMAN = 0;
- mixer.MMAP = 1;
- mixer.MMG = 0;
- if (mixer.STMA == 0) {
- state = 4;
- }
- else {
- state = 5;
- timer = rezept[typ - 1].mixzeit *1000/T_syst;
- if (states) {idsci_printf("Mixer: Mixen\n");}
- }
- break;
- // MIXEN
- case 5:
- mixer.MFBM = 0;
- mixer.MMAN = 1;
- mixer.MMAP = 0;
- mixer.MMG = 0;
- timer--;
- if (timer < 0) {
- state = 6;
- if (states) {idsci_printf("Mixer: Mixer hochfahren\n");}
- }
- else {
- state = 5;
- }
- break;
- // MIXER HOCHFAHREN
- case 6:
- mixer.MFBM = 0;
- mixer.MMAN = 0;
- mixer.MMAP = 0;
- mixer.MMG = 1;
- if (mixer.STMG == 0) {
- state = 6;
- }
- else {
- mixer.MMG = 0;
- mixer.typ = typ;
- state = 7;
- if (states) {
- idsci_printf("Mixer: Warte auf Ofen\n");
- }
- }
- break;
- // WARTE AUF OFEN
- case 7:
- mixer.MFBM = 0;
- mixer.MMAN = 0;
- mixer.MMAP = 0;
- mixer.MMG = 0;
- if (ofen.bereit == 0) {
- state = 7;
- }
- else {
- state = 8;
- mixer.bereit = 1;
- timer = 2000 *1000/T_syst;
- if (states) {idsci_printf("Mixer: Kiste rausfahren\n");}
- }
- break;
- // KISTE RAUSFAHREN
- case 8:
- mixer.MFBM = 1;
- mixer.MMAN = 0;
- mixer.MMAP = 0;
- mixer.MMG = 0;
- timer--;
- if (timer < 0) { // Rücksprung in Stand By
- state = 1;
- mixer.typ = 0;
- tempregelung.vorheizen_typ = 0;
- if (states) {idsci_printf("Mixer: Warte auf Drehtisch\n");}
- }
- else if ((timer < 1500*1000/T_syst) && (dt2.typ > 0)) { // Rücksprung in Hole Kiste
- state = 1;
- mixer.typ = 0;
- }
- else {
- state = 8;
- }
- break;
- }
- }
- /*********************************** TemperaturRegelung **************************************************/
- // Temperature Lookup Table
- char getvaloftemp(char temp){
- char TempLUT[][2] = {
- {27, 59},
- {28, 65},
- {29, 69},
- {30, 73},
- {31, 78},
- {32, 81},
- {33, 85},
- {34, 88},
- {35, 91},
- {36, 94},
- {37, 97},
- {38, 99},
- {39, 101},
- {40, 104}
- };
- if(temp < 27){
- return 59;
- }
- else if(temp > 40){
- return 104;
- }else{
- return TempLUT[temp-27][1];
- }
- }
- void f_TempO (void) {
- // steuert die Temperatur des Ofens
- // lokale Variablen:
- static int temp; // digitalgewandelte Temperatur des Ofens
- static char state; // Zustand der state machine
- static int temp_max;
- static int temp_min;
- static int temp_tolH;
- static int temp_tolL;
- /* globale Variablen auf die zugegriffen wird:
- INPUT:
- int backen startet den Backvorgang
- int temp_max maximale Temperatur bei der gebacken wird
- int temp_min minimale Temperatur bei der gebacken wird
- OUTPUT:
- int temp_ok zeigt an ob der Ofen im zulässigen Temperaturbereich zum backen ist
- */
- // state machine
- if (erster_aufruf){
- state = 0;
- tempregelung.temp_ok = 0;
- tempregelung.vorheizen_typ = 0;
- temp_tolH = 2;
- temp_tolL = 1;
- if (states) {idsci_printf("TempRegelung: Abgeschaltet\n");}
- }
- temp = tempregelung.PT1000/256;//ftemp();
- //idsci_printf("%i\n",temp); //AD-wandler wert ausgeben
- //if (states) {idsci_printf("temp = %i\n",temp);}
- switch (state) {
- // Standby
- case 0:
- tempregelung.Lampe = 0;
- if (tempregelung.vorheizen_typ > 0) {
- state = 1;
- temp_max = getvaloftemp(rezept[tempregelung.vorheizen_typ-1].temp) + temp_tolH;
- temp_min = getvaloftemp(rezept[tempregelung.vorheizen_typ-1].temp) - temp_tolL;
- if (states) {idsci_printf("TempRegelung: Heize vor\n");}
- }
- break;
- // Vorheizen (Licht an)
- case 1:
- tempregelung.Lampe = 1;
- if (temp >= temp_max) {
- state = 2;
- if (states) {idsci_printf("TempRegelung: Vorheizen, Ofen heiss\n");}
- }
- break;
- // Vorheizen Temp stimmt (Licht aus)
- case 2:
- tempregelung.Lampe = 0;
- if(temp <= temp_max) {
- tempregelung.temp_ok = 1;
- if (ofen.backen > 0) {
- state = 3;
- if (states) {idsci_printf("TempRegelung: Backen, Temperatur stimmt\n");}
- }
- if (temp <= temp_min) {
- tempregelung.temp_ok = 0;
- state = 1;
- if (states) {idsci_printf("TempRegelung: Heize Vor\n");}
- }
- }
- break;
- // Backen Licht aus
- case 3:
- tempregelung.Lampe = 0;
- if (ofen.backen == 0) {
- tempregelung.temp_ok = 0;
- state = 0;
- if (states) {idsci_printf("TempRegelung: Abgeschaltet\n");}
- }
- if (temp <= temp_min) {
- state = 4;
- if (states) {idsci_printf("TempRegelung: Backen, anheizen\n");}
- }
- break;
- // Backen Licht an
- case 4:
- tempregelung.Lampe = 1;
- if (ofen.backen == 0) {
- tempregelung.temp_ok = 0;
- state = 0;
- if (states) {idsci_printf("TempRegelung: Abgeschaltet\n");}
- }
- if (temp >= temp_max) {
- state = 3;
- if (states) {idsci_printf("TempRegelung: Backen, Temperatur stimmt\n");}
- }
- break;
- }
- }
- /*********************************** Ofen **************************************************/
- void f_Ofen (void) {
- // steuert das Förderband des Ofens
- //-----------------------------------------------------------------------------------------------------
- // lokale Variablen:
- static char state; // Zustand der state machine
- static char typ; // Kistentyp im Ofen
- static char z; // Zähler für den Kistentyp
- static int timer; // Zähler der die Zeit im Ofen misst
- /* globale Variablen auf die zugegriffen wird:
- INPUT:
- int backzeit() legt die Zeit fest die gebacken werden soll, Array über Kistentyp
- int temp_ok zeigt an ob der Ofen im zulässigen Temperaturbereich zum backen ist
- int M_typ Typ der Kiste die aus dem Mixer kommt
- SENSOR DATEN:
- int SLA Lichtschranke Ablageplatz
- int SIO Initiator Ofen
- OUTPUT:
- int backen startet den Backvorgang
- int O_bereit signalisiert (dem Mixer) dass der Ofen bereit zum backen ist
- AKTOR DATEN:
- int MFBO Motor Förderband Ofen
- */
- // state machine
- //idsci_printf("ofen.SIO: %i\n", ofen.SIO);
- if (erster_aufruf){
- state = 0;
- typ = 0;
- z = 0;
- timer = 0;
- ofen.bereit = 0;
- if (states){idsci_printf("Ofen: Ausgang frei?\n");}
- }
- switch (state) {
- // Ausgang frei?
- case 0:
- ofen.MFBO = 0;
- if (ofen.SLA == 0) {
- state = 1;
- if (states){idsci_printf("Ofen: Warte auf Mixer\n");}
- }
- break;
- // STAND BY (Warte auf Mixer)
- case 1:
- ofen.MFBO = 0;
- if (ofen.SLA == 1){
- state = 0;
- if (states){idsci_printf("Ofen: Ausgang blockiert\n");}
- }
- if (mixer.typ > 0) {
- state = 2;
- if (states){idsci_printf("Ofen: Warte auf richtige Temperatur\n");}
- }
- break;
- // WARTE AUF TempRegelung
- case 2:
- ofen.MFBO = 0;
- if (ofen.SLA == 1){
- state = 0;
- if (states){idsci_printf("Ofen: Ausgang blockiert\n");}
- }
- if (tempregelung.temp_ok > 0) {
- z = mixer.typ;
- typ = mixer.typ;
- ofen.bereit = 1;
- ofen.backen = 1;
- state = 3;
- if (states){idsci_printf("Ofen: Temperatur ok, hole Kiste\n");}
- }
- break;
- // HOLE KISTE
- case 3:
- ofen.MFBO = 1;
- if (ofen.SIO == 0) {
- state = 3; }
- else {
- z--;
- state = 4; }
- break;
- // FÖRDERBAND AN
- case 4:
- ofen.MFBO = 1;
- if (z <= 0) {
- state = 5;
- ofen.bereit = 0;
- timer = rezept[typ - 1].backzeit *1000/T_syst;
- if (states){idsci_printf("Ofen: Backen\n");}
- }
- else {
- if (ofen.SIO == 1) {
- state = 4; }
- else {
- state = 3; }
- }
- break;
- // BACKEN
- case 5:
- ofen.MFBO = 0;
- // Timeout:
- if (timer-- > 0) {
- state = 5; }
- else {
- ofen.backen = 0;
- state = 6;
- timer = 3000 *1000/T_syst;
- if (states){idsci_printf("Ofen: Kiste rausfahren\n");}
- }
- break;
- // KISTE RAUSFAHREN
- case 6:
- ofen.MFBO = 1;
- if (timer-- < 0) {
- state = 0;
- if (states){idsci_printf("Ofen: Ausgang blockiert\n");}
- }
- break;
- } // end of switch state
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement