TVZ2020 / Mbed 2 deprecated ConfigurationVerifier

Dependencies:   mbed MonitoringExecutor MonitoringStrategy ObjectPosition SRF05 Configuration ManualController

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include <string>
00002 #include <vector>
00003 #include <map>
00004 #include "mbed.h"
00005 #include "SRF05.h"
00006 #include "configuration.h"
00007 #include "configurationVerifier.h"
00008 #include "monitoringExecutor.h"
00009 #include "manualController.h"
00010 
00011 using namespace std;
00012 
00013 DigitalIn protectionOnOff(D3);
00014 AnalogIn controlSensor(A0);
00015 Timer controlSensorTimer;
00016 PwmOut buzzer(D10);
00017 
00018 DigitalIn autoModeOnOf(D6);
00019 int controllMode = 0;
00020 
00021 Ticker inputsControlTicker;
00022 
00023 Serial* pc = new Serial(USBTX, USBRX);
00024 SRF05* ranger = new SRF05(D8, D12);
00025 PwmOut* rangerServo = new PwmOut(D5);
00026 PwmOut* fan = new PwmOut(D11);
00027 PwmOut* fanServo = new PwmOut(D9);
00028 DigitalOut* greenLed = new DigitalOut(D4);
00029 DigitalOut* redLed = new DigitalOut(D2);
00030 
00031 void executeInputControll();
00032 void controlSensorStateCheck();
00033 bool checkIsAutoModeEnabled();
00034 
00035 int main()
00036 {   
00037     Configuration* config;
00038     vector<Configuration*> configsVec;
00039     
00040     protectionOnOff.mode(PullDown);
00041     autoModeOnOf.mode(PullDown); 
00042     inputsControlTicker.attach(&executeInputControll, 0.5);
00043     
00044     rangerServo->period_ms(20);
00045     fan->period_ms(20);
00046     fanServo->period_ms(20);
00047     
00048     MonitoringExecutor* executor;
00049     ManualController* manualController;
00050     
00051     char tmp;
00052     pc->printf("Welcome\n\r");
00053     pc->printf("For auto control choose 1, for manual control choose 2.\n\r");
00054     tmp = pc->getc();
00055     
00056     if(tmp == '1') {
00057         bool warningPrinted = false;
00058         while(!checkIsAutoModeEnabled()) {
00059             if(warningPrinted == false) {
00060                 pc->printf("Auto mode should be enabled by switch 4.\n\r");
00061                 warningPrinted = true;
00062                 }
00063             wait(1);
00064             } 
00065         bool configCheck = false;
00066         pc->printf("Set configuration for auto controll:\n\r");
00067         config = new Configuration;
00068         while(configCheck == false) {
00069             pc->printf("For circle mode choose 0, for squere mode choose 1.\n\r");
00070             tmp = pc->getc();
00071             if(tmp == '0') {
00072                 config->setMode(0);
00073             }
00074             else if(tmp == '1') {
00075                 config->setMode(1);
00076             }
00077             else {
00078                 config->setMode(2); 
00079             }
00080             configCheck = ConfigurationVerifier::verifyConfiguration(pc, config);
00081         }
00082         config->setDistance(15);
00083         config->setMonitoringDuration(180);
00084         config->setFanWorkingDuration(5);
00085         config->setFanYCoordinate(3);
00086         configsVec.push_back(config);
00087         executor = new MonitoringExecutor(configsVec[0], pc, ranger, rangerServo, fan, fanServo, greenLed, redLed);
00088         controllMode = 1;
00089         pc->printf("Manual controll started.\n\r");
00090         executor->startMonitoring();
00091     }
00092     else if(tmp == '2') {
00093         manualController = new ManualController(D7, pc, ranger, rangerServo, fan, fanServo, greenLed, redLed);
00094         controllMode = 2;
00095         pc->printf("Manual controll started.\n\r");
00096         manualController->executeManualControll();
00097         }
00098     else{
00099         pc->printf("Option %c is not supported. By!\n\r", tmp);
00100         }
00101     return 0;
00102 }
00103 
00104 
00105 void executeInputControll() {
00106     controlSensorStateCheck();
00107     if(checkIsAutoModeEnabled() == false && controllMode == 1) {
00108         pc->printf("Auto control mode is not enabled on switch 4. Monitoring execution stopped!\n\r");
00109         rangerServo->pulsewidth_us(0);
00110         fanServo->pulsewidth_us(0);
00111         fan->pulsewidth_us(0);
00112         wait(600);
00113     }
00114 }
00115 
00116 void controlSensorStateCheck(){
00117     if(protectionOnOff == 0) {
00118         buzzer = 0;
00119         return;
00120         }
00121     
00122     if(controlSensor >= 0.7) {
00123         if(controlSensorTimer.read() == 0){
00124             controlSensorTimer.start();
00125             buzzer = 0;
00126             }
00127         if(controlSensorTimer.read() >= 2){
00128             buzzer = 0.5;
00129         }
00130     }
00131     else{
00132         buzzer = 0;
00133         controlSensorTimer.reset();
00134         }    
00135 }
00136 
00137 bool checkIsAutoModeEnabled(){
00138     if(autoModeOnOf == 0) {
00139         return false;
00140     }
00141     return true;
00142 }