Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- papaco
- Date:
- 2019-02-20
- Revision:
- 4:379e05b2fc0d
- Parent:
- 3:dd5c9690ed0d
- Child:
- 5:fe1e88d6b0cb
File content as of revision 4:379e05b2fc0d:
#include "mbed.h"
#include "pinout.h"
#include "CUTTER.h"
#include "EXTRUDER.h"
#include "GRIDDLE.h"
#include "INTERFACE.h"
#include "MACHINE.h"
#include "OVEN.h"
#include "TORTILLA.h"
Ticker timer;
INTERFACE interface(StartStopPin,StartStopRPin,StartStopGPin,StartStopBPin,TortillaPin,TempReadyPin);
EXTRUDER extruder(ExtruderStartPin,ExtruderPWMPin);
CUTTER cutter(CutterUpPin,CutterDownPin,CutterMotorDirectionPin,CutterMotorEnablePin);
GRIDDLE griddle(GriddlePWMPin,GriddleUpPin,GriddleDownPin,GriddleHomePin);
OVEN oven(OvenPWMPin);
MACHINE Lupe(BandPWMPin,TempPin,CapsuleDoorPin,CartridgePin,CuttedPin);
TORTILLA tortilla;
#if defined(DEBUG_MODE)
static Serial pc(USBTX, USBRX);
int DebugTimer=0;
#endif
void MANAGER(void);
void init(void);
void checkUp(void);
void ExtruderProduction(void);
void CutterProduction(void);
void GriddleProduction(void);
void OvenProduction(void);
int STATUS=-1;
int GENERAL_TIME=-1;
int main(){
#if defined(DEBUG_MODE)
pc.printf("\n\n***************************\nMCU variable init OK!\r\n");
#endif
init();
while(1);
}//main
void MANAGER(void){
GENERAL_TIME++;
/******************************STATUS CONTROL******************************/
if(STATUS==HOME){/****************************************************HOME*/
if(GENERAL_TIME==0){
#if defined(DEBUG_MODE)
pc.printf("\nHOME rutine start...\r\n");
#endif
interface.setLED(1,1,0);
interface.setFlash(true);
cutter.down();
extruder.Init();
griddle.Home();
oven.Home();
}//if
if(cutter.available()&&griddle.isFree()){//falta temperatura
#if defined(DEBUG_MODE)
pc.printf("\nHOME rutine end...\r\n");
#endif
GENERAL_TIME=-1;
STATUS=IDLE;
interface.setLED(0,1,0);
}//if
}else if(STATUS==IDLE){/**********************************************IDLE*/
if(IDLE_TIMER==GENERAL_TIME){
GENERAL_TIME=0;
if((Lupe.StartCheck())&&(interface.getFlash()))
interface.setFlash(false);
if((!Lupe.StartCheck())&&(!interface.getFlash()))
interface.setFlash(true);
if(interface.getStart()&&(!interface.getFlash())){
#if defined(DEBUG_MODE)
pc.printf("\nIDLE Done\r\n");
#endif
STATUS=INIT_PRODUCTION;
GENERAL_TIME=-1;
interface.setLED(1,1,1);
interface.setFlash(true);
}//if
}//if
}else if(STATUS==INIT_PRODUCTION){/*************************INIT_PRODUCTION*/
if(GENERAL_TIME==0){//INIT
#if defined(DEBUG_MODE)
pc.printf("\nFinding producton start point................r\n");
#endif
}//if
if(extruder.getSwitch()){//No dough detected
if(extruder.getTimer()>=1000){//Check every 1s
extruder.setTimer(0);
extruder.GetHome();
#if defined(DEBUG_MODE)
pc.printf("\nExtruder finding home on:%f\r\n",extruder.getPosition());
#endif
if(extruder.getPosition()>=0.1){
GENERAL_TIME=-1;
STATUS=HOME;
interface.setLED(1,1,0);
interface.setFlash(true);
}//if
}//if
}else{
extruder.setTimer(EXTRUDER_CYCLE);
cutter.setTimer(-CUTTER_FIRST_TIME);
griddle.setTimer(-GRIDDLE_FIRST_TIME-CUTTER_WAIT_TIMER);
oven.setTimer(-OVEN_FIRST_TIME-GRIDDLE_WAIT_TIMER-CUTTER_WAIT_TIMER);
STATUS=PRODUCTION;
GENERAL_TIME=-1;
tortilla.setDP(interface.getTortilla());
#if defined(DEBUG_MODE)
pc.printf("\nProduction of %d Tortillas...\r\n",interface.getTortilla());
#endif
}//else
}else if(STATUS==PRODUCTION){/**********************************PRODUCTION*/
if(GENERAL_TIME==0){//INIT
#if defined(DEBUG_MODE)
pc.printf("\nProducton started!\r\n");
#endif
}//if
if(tortilla.getExtruder()){ExtruderProduction();}
if(tortilla.getCutter()){CutterProduction();}
if(tortilla.getGriddle()){GriddleProduction();}
if(tortilla.getOven()){OvenProduction();}
if(!tortilla.getTortilla()){
GENERAL_TIME=-1;
STATUS=HOME;
interface.setLED(1,1,0);
interface.setFlash(true);
}//if
}//else if
checkUp();
return;
}//MANAGER
void init(void){
#if defined(DEBUG_MODE)
pc.printf("\nMachine modules is starting...\r\n");
#endif
interface.Init();
#if defined(DEBUG_MODE)
pc.printf("INTERFACE OK!\r\n");
#endif
Lupe.Init();
#if defined(DEBUG_MODE)
pc.printf("MACHINE OK!\r\n");
#endif
cutter.Init();
#if defined(DEBUG_MODE)
pc.printf("CUTTER OK!\r\n");
#endif
extruder.Init();
#if defined(DEBUG_MODE)
pc.printf("EXTRUDER OK!\r\n");
#endif
griddle.Init();
#if defined(DEBUG_MODE)
pc.printf("GRIDDLE OK!\r\n");
#endif
oven.Init();
#if defined(DEBUG_MODE)
pc.printf("OVEN OK!\r\n");
#endif
timer.attach(&MANAGER,0.001);
#if defined(DEBUG_MODE)
pc.printf("Time Manager OK!\r\n");
#endif
wait(5);
#if defined(DEBUG_MODE)
pc.printf("\nInit process done...\r\n");
#endif
STATUS=HOME;
GENERAL_TIME=0;
return;
}//init
void checkUp(void){
/*************************GENERAL INTERFACE CONTROL************************/
interface.check(); //Flash_control; Update_start_button_latch_each 50ms
/*************************GENERAL MACHINE CONTROL**************************/
if(Lupe.check()&&(STATUS==PRODUCTION)){ //Error at the machine
interface.setLED(1,0,0);
interface.setFlash(true);
tortilla.setExtruder(false);
}//if
/*************************GENERAL CUTTER CONTROL***************************/
cutter.check(); //Add_production_timer; Check_cutt_status;
//Manage_cutting_process
/*************************GENERAL EXTRUDER CONTROL*************************/
extruder.check(); //Add_timer
/*************************GENERAL GRIDDLE CONTROL**************************/
griddle.check(); //Add_timer; Manage_Griddle_press
/*************************GENERAL OVEN CONTROL*****************************/
oven.check();
/***********************GENERAL TORITLLA CONTROL***************************/
#if defined(DEBUG_MODE)
bool latchExtruder=tortilla.getExtruder();
bool latchCutter=tortilla.getCutter();
bool latchGriddle=tortilla.getGriddle();
bool latchOven=tortilla.getOven();
bool latchProduction=tortilla.getTortilla();
int END=tortilla.check();
if((END==1)&&(latchExtruder!=tortilla.getExtruder()))
pc.printf("\n..........Extruder END..........\r\n");
else if((END==2)&&(latchCutter!=tortilla.getCutter()))
pc.printf("\n..........Cutter END..........\r\n");
else if((END==3)&&(latchGriddle!=tortilla.getGriddle()))
pc.printf("\n..........Griddle END..........\r\n");
else if((END==4)&&(latchOven!=tortilla.getOven()))
pc.printf("\n..........Oven END..........\r\n");
else if((END==5)&&(latchProduction!=tortilla.getTortilla()))
pc.printf("\n!!..........FULL PRODUCTION END..........!!\r\n");
#else
tortilla.check();
#endif
return;
}//checkUp
void ExtruderProduction(void){
if((extruder.getTimer()>=EXTRUDER_CYCLE)&&(extruder.getPosition()<0.1)){//Check every 5s
extruder.setTimer(0);
extruder.Step();
tortilla.addExtruder();
cutter.setTimer(0);
#if defined(DEBUG_MODE)
pc.printf("Extruded dough number %d in position:%f\r\n",tortilla.getExtruderCount(),extruder.getPosition());
#endif
}//if
if(extruder.getPosition()>=0.1){
tortilla.setExtruder(false);
#if defined(DEBUG_MODE)
pc.printf("Extruder reached end position\r\n");
#endif
}//if
return;
}//ExtruderProduction
void CutterProduction(void){
if((cutter.getTimer()==5000)&&(interface.getTortilla()>tortilla.getCutterCount())){
cutter.cutt();
tortilla.addCutter();
griddle.setTimer(0);
#if defined(DEBUG_MODE)
pc.printf("Cutted tortilla number:%d\r\n",tortilla.getCutterCount());
#endif
}//if
return;
}//CutterProduction
void GriddleProduction(void){
if((griddle.getTimer()==5000)&&(interface.getTortilla()>tortilla.getGriddleCount())){
griddle.press();
tortilla.addGriddle();
oven.setTimer(0);
#if defined(DEBUG_MODE)
pc.printf("Griddled dough process number:%d\r\n",tortilla.getGriddleCount());
#endif
}//if
return;
}//GriddleProduction
void OvenProduction(void){
if((oven.getTimer()==5000)&&(interface.getTortilla()>tortilla.getOvenCount())){
oven.open();
tortilla.addOven();
#if defined(DEBUG_MODE)
pc.printf("Oven passing tortilla number:%d\r\n",tortilla.getOvenCount());
#endif
}//if
return;
}//OvenProduction