main.c
Go to the documentation of this file.00001 #include "V24Control.h"
00002 #include "SensorOnlyMode.h"
00003
00004
00005
00006
00007
00008 volatile int softwareMode = ROBOT_STANDALONE;
00009
00011 int main( void )
00012 {
00013
00014
00015
00016
00017 BoardController::initPorts();
00018
00019
00020 if (0) {
00021 softwareMode = SENSOR_MODE;
00022 sensorMain();
00023 } else {
00024 softwareMode = ROBOT_STANDALONE;
00025 }
00026
00027
00028
00029 V24Control *v24 = new V24Control();
00030 ValueIteration *vi = v24->vi;
00031
00032 #ifdef TESTMODE
00033 #warning compiled TESTMODE!
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
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
00067
00068 v24->receive(&sByte);
00069
00070
00071
00072
00073
00074
00075
00076 if (sByte == 'a') {
00077 vi->env->doAction(LEFT, 1000, &aRet);
00078 v24->transmit('b');
00079
00080 } else if (sByte == 's') {
00081 vi->env->doAction(RIGHT, 1000, &aRet);
00082 v24->transmit('t');
00083
00084 } else if (sByte == 'd') {
00085 vi->env->doAction(UP, 1000, &aRet);
00086 v24->transmit('e');
00087
00088 } else if (sByte == 'f') {
00089 vi->env->doAction(DOWN, 1000, &aRet);
00090 v24->transmit('g');
00091 }
00092
00093
00094
00095 BoardController::powerOnLED(LED_LEARN, false);
00096 }
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 PORTC &= ~(1<<RTS);
00118
00119 }
00120
00121 #else
00122
00123
00124
00125
00126
00127
00128
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
00138 mainMode = newMainMode;
00139
00140
00141 if (BoardController::getSwitchState(SWITCH_WALK)) {
00142
00143
00144 if (v24->newDataReceived()) {
00145
00146
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
00158 } else if (autoStart) {
00159
00160
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
00169 } else {
00170
00171
00172 autoStart = false;
00173
00174
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
00184 } else if (mainMode == MAIN_MODE_WALK_POLICY) {
00185
00186 vi->doNextAction();
00187
00188
00189 } else if (mainMode == MAIN_MODE_EXPLORE_FEEDBACK) {
00190
00191 vi->exploreAllFeedbacks(true);
00192
00193
00194 newMainMode = MAIN_MODE_LEARN;
00195
00196
00197 } else if (mainMode == MAIN_MODE_LEARN) {
00198
00199
00200 vi->valueIterateAllStates();
00201
00202
00203 } else if (mainMode == MAIN_MODE_STOP) {
00204
00205
00206 }
00207
00208
00209 } else {
00210
00211 if (v24->newDataReceived()) {
00212
00213
00214 newMainMode = MAIN_MODE_STOP;
00215
00216
00217 v24->processCommand();
00218
00219
00220 newMainMode = v24->getNewMainMode(mainMode);
00221
00222
00223 } else if (mainMode == MAIN_MODE_LEARN) {
00224 vi->valueIterateAllStates();
00225 }
00226 }
00227 }
00228 #endif
00229
00230
00231 }
00232
00233