main.c File Reference

#include "V24Control.h"
#include "I2c.h"
#include "Environment.h"
#include "SensorOnlyMode.h"
Include dependency graph for main.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int main (void)

Variables

volatile int softwareMode = ROBOT_STANDALONE

Function Documentation

int main ( void   ) 

the main function

Definition at line 11 of file main.c.

References BoardController::blinkLED(), BoardController::disableV24Interrupt(), Environment::doAction(), ValueIteration::doNextAction(), DOWN, BoardController::enableSerialV24Interface(), BoardController::enableV24Interrupt(), ValueIteration::env, ValueIteration::exploreAllFeedbacks(), V24Control::getNewMainMode(), BoardController::getSwitchState(), BoardController::initPorts(), LED_EXPLORATION, LED_LEARN, LED_WALK, LEFT, MAIN_MODE_EXPLORE_FEEDBACK, MAIN_MODE_LEARN, MAIN_MODE_STOP, MAIN_MODE_WALK_POLICY, BoardController::msDelay(), V24Control::newDataReceived(), BoardController::powerOnLED(), V24Control::processCommand(), V24Control::receive(), RIGHT, ROBOT_STANDALONE, RTS, SENSOR_MODE, sensorMain(), softwareMode, SWITCH_FULL_EXP_AT_START, SWITCH_WALK, V24Control::transmit(), UP, ValueIteration::valueIterateAllStates(), and V24Control::vi.

00012 {    
00013 
00014 
00015 
00016      // initialize ports+LEDs
00017      BoardController::initPorts();
00018 
00019      // software mode
00020      if (0) {
00021           softwareMode = SENSOR_MODE;
00022           sensorMain();  
00023      } else {
00024           softwareMode = ROBOT_STANDALONE;
00025      }
00026 
00027 
00028      // initialize serial communication class with standard VI agent
00029      V24Control *v24 = new V24Control();
00030      ValueIteration *vi = v24->vi;
00031 
00032 #ifdef TESTMODE
00033 #warning compiled TESTMODE!
00034 
00035 
00036 
00037      //BoardController::blinkLED((1<<LED_POWER)|(1<<LED_WALK)|(1<<LED_LEARN)|(1<<LED_EXPLORATION), 20, 200);
00038 
00039      // initialize serial communication class with standard VI agent
00040      //V24Control *v24 = new V24Control();
00041      //ValueIteration *vi = v24->vi;
00042 
00043 
00044 
00045      /******************************************
00046      * Test Mode
00047      ******************************************/
00048 
00049 
00050      BoardController::enableSerialV24Interface();
00051 
00052      ACTION_RETURN aRet;
00053 
00054      while (1) {
00055           for (unsigned char i=48; i<55; i++) {
00056                v24->transmit(i);
00057                BoardController::msDelay(500);
00058           }
00059      }
00060 
00061      unsigned char sByte=0;
00062      while (1) {
00063           if (v24->newDataReceived()) {
00064 
00065                BoardController::powerOnLED(LED_LEARN, true);
00066                //BoardController::msDelay(1000);  
00067 
00068                v24->receive(&sByte);
00069                //PORTC |= (1<<RTS);
00070 
00071                //sByte++;
00072                //PORTC |= (1<<RTS);
00073                //v24->transmit(sByte);
00074 
00075                // LEFT
00076                if (sByte == 'a') {
00077                     vi->env->doAction(LEFT, 1000, &aRet);
00078                     v24->transmit('b');
00079                // RIGHT
00080                } else if (sByte == 's') {
00081                     vi->env->doAction(RIGHT, 1000, &aRet);
00082                     v24->transmit('t');
00083                // UP
00084                } else if (sByte == 'd') {
00085                     vi->env->doAction(UP, 1000, &aRet);
00086                     v24->transmit('e');
00087                // DOWN
00088                } else if (sByte == 'f') {
00089                     vi->env->doAction(DOWN, 1000, &aRet);
00090                     v24->transmit('g');
00091                }
00092 
00093                // indicate that controller is again ready for reception
00094 
00095                BoardController::powerOnLED(LED_LEARN, false);
00096           }
00097 
00098           
00099           /*
00100           for (unsigned char i=33; i<125; i++) {
00101                v24->transmit(i);
00102           }
00103           
00104           v24->transmit(0x30);
00105           BoardController::msDelay(1000);
00106           */
00107 
00108           /*
00109           BoardController::blinkLED (
00110                (1<<LED_WALK)|(1<<LED_LEARN)|(1<<LED_EXPLORATION), 1, 500
00111           );
00112           */
00113 
00114           //PORTC |= (1<<RTS);
00115           //v24->transmit(0x30);
00116           //BoardController::msDelay(1000);
00117           PORTC &= ~(1<<RTS);
00118 
00119      }
00120 
00121 #else 
00122 
00123      /******************************************
00124      * NORMAL Mode
00125      ******************************************/
00126 
00127 
00128      // initialize auto start counter 
00129      unsigned char autoStartCounter = 0;
00130      bool autoStart = 1;
00131 
00132      int mainMode = MAIN_MODE_WALK_POLICY;
00133      int newMainMode = MAIN_MODE_WALK_POLICY;
00134 
00135      while ( 1 ) {  
00136 
00137           // set new mode in case of interrupt
00138           mainMode = newMainMode;
00139 
00140           // only walk when PAUSE 
00141           if (BoardController::getSwitchState(SWITCH_WALK)) {
00142 
00143                // Check for new serial data
00144                if (v24->newDataReceived()) {
00145 
00146                     // stop robot
00147                     BoardController::disableV24Interrupt();
00148                     cli();
00149                     newMainMode = MAIN_MODE_STOP; 
00150      
00151                     v24->processCommand();
00152                     autoStart = 0;
00153 
00154                     newMainMode = v24->getNewMainMode(newMainMode);
00155                     
00156           
00157                // Autostart-Routine
00158                } else if (autoStart) {
00159 
00160                     // delay for at least 5 seconds
00161                     if (autoStartCounter < 5) {
00162 
00163                          autoStartCounter++;
00164      
00165                          BoardController::blinkLED (
00166                            (1<<LED_WALK)|(1<<LED_LEARN)|(1<<LED_EXPLORATION), 1, 500);
00167                
00168                     // start after 5 seconds
00169                     } else {
00170 
00171                          // disable auto-start
00172                          autoStart = false;
00173                          
00174                          // explore environment if SWITCH_FULL_EXP_AT_START is enabled
00175                          if (BoardController::getSwitchState(SWITCH_FULL_EXP_AT_START)) {
00176                               vi->exploreAllFeedbacks(false);
00177                          }
00178                          BoardController::enableV24Interrupt();
00179                                    
00180                          newMainMode = MAIN_MODE_WALK_POLICY;
00181                     }
00182 
00183                // do next action
00184                } else if (mainMode == MAIN_MODE_WALK_POLICY) {
00185 
00186                     vi->doNextAction();
00187 
00188                // explore environment
00189                } else if (mainMode == MAIN_MODE_EXPLORE_FEEDBACK) {
00190      
00191                     vi->exploreAllFeedbacks(true);
00192      
00193                     // perform value-iteration to learn the modell
00194                     newMainMode = MAIN_MODE_LEARN;
00195      
00196                // learning-only mode
00197                } else if (mainMode == MAIN_MODE_LEARN) {
00198 
00199                     // value iterate all states
00200                     vi->valueIterateAllStates();  
00201                     
00202                // pause
00203                } else if (mainMode == MAIN_MODE_STOP) {
00204      
00205                     // dummy
00206                }
00207 
00208           // if robot is in PAUSE-mode, only check for new serial data
00209           } else {
00210                // check for new serial data
00211                if (v24->newDataReceived()) {
00212 
00213                     // stop robot
00214                     newMainMode = MAIN_MODE_STOP; 
00215      
00216                     // process serial command
00217                     v24->processCommand();
00218      
00219                     // update main mode
00220                     newMainMode = v24->getNewMainMode(mainMode);
00221 
00222                // otherwise perform value-iteration
00223                } else if (mainMode == MAIN_MODE_LEARN) {
00224                     vi->valueIterateAllStates();
00225                }
00226           }
00227      }
00228 #endif
00229 
00230 
00231 }

Here is the call graph for this function:


Variable Documentation

volatile int softwareMode = ROBOT_STANDALONE

Definition at line 8 of file main.c.

Referenced by main(), and SIGNAL().

Generated on Fri Oct 8 17:10:09 2010 for Crawling Robot Microcontroller Software by  doxygen 1.6.3