#include <StateSpace.h>
Public Member Functions | |
unsigned char | getBestAction (unsigned char _row, unsigned char _column) |
char | getFeedback (unsigned char _row, unsigned char _column, unsigned char _action) |
unsigned int | getMemorySize () |
void | getState (unsigned char _row, unsigned char _column, STATE *_state) |
double | getValue (unsigned char _row, unsigned char _column) |
void | init () |
void | ramtestReadBytes (unsigned int _addr, unsigned char *data, unsigned char _length) |
void | ramtestSaveBytes (unsigned int _addr, unsigned char *data, unsigned char _length) |
void | setBestAction (unsigned char _row, unsigned char _column, unsigned char _action) |
void | setFeedback (unsigned char _row, unsigned char _column, unsigned char _action, char _fb) |
void | setState (unsigned char _row, unsigned char _column, STATE *_state) |
void | setValue (unsigned char _row, unsigned char _column, float _value) |
Data Fields | |
unsigned char | scalX |
unsigned char | scalY |
bool | useInternalRAM |
Private Attributes | |
unsigned char | internStateSpace [sizeof(State)*200] |
Ram | ram1 |
STATE | tmpState |
Definition at line 6 of file StateSpace.h.
unsigned char StateSpace::getBestAction | ( | unsigned char | _row, | |
unsigned char | _column | |||
) |
char StateSpace::getFeedback | ( | unsigned char | _row, | |
unsigned char | _column, | |||
unsigned char | _action | |||
) |
returns r(s,a) from state (_row, _column)
Definition at line 93 of file StateSpace.c.
References DOWN, State::feedback_down, State::feedback_left, State::feedback_right, State::feedback_up, getState(), LEFT, RIGHT, and UP.
Referenced by ValueIteration::evaluateAction().
00093 { 00094 00095 STATE _s; 00096 this->getState (_row, _column, &_s); 00097 00098 if (_action == UP) { 00099 return _s.feedback_up; 00100 } else if (_action == DOWN) { 00101 return _s.feedback_down; 00102 } else if (_action == LEFT) { 00103 return _s.feedback_left; 00104 } else if (_action == RIGHT) { 00105 return _s.feedback_right; 00106 } 00107 }
unsigned int StateSpace::getMemorySize | ( | ) |
returns the memory-size of the state-space
Definition at line 143 of file StateSpace.c.
References internStateSpace, and useInternalRAM.
00143 { 00144 00145 // Interner RAM 00146 if (this->useInternalRAM) { 00147 return sizeof(internStateSpace); 00148 00149 // SPI RAM 00150 } else { 00151 return 65535; 00152 } 00153 }
void StateSpace::getState | ( | unsigned char | _row, | |
unsigned char | _column, | |||
STATE * | _state | |||
) |
returns a state into _state
Definition at line 14 of file StateSpace.c.
References internStateSpace, ram1, Ram::readBytes(), scalX, STATESIZE, and useInternalRAM.
Referenced by getFeedback(), getValue(), ValueIteration::moveAndSaveFeedback(), V24Control::processGetState(), setFeedback(), and setValue().
00014 { 00015 00016 unsigned int _addr; 00017 unsigned char i; 00018 unsigned char* _bytes = (unsigned char*)_state; 00019 00020 // compute memory address 00021 _addr = ((_row * scalX) + _column)*STATESIZE; 00022 00023 // internal RAM 00024 if (this->useInternalRAM) { 00025 for (i=0; i<STATESIZE; i++) { 00026 _bytes[i] = internStateSpace[(_addr + i)]; 00027 } 00028 00029 // SPI memory 00030 } else { 00031 ram1.readBytes(_addr, (unsigned char*)&_state[0], STATESIZE); 00032 } 00033 }
double StateSpace::getValue | ( | unsigned char | _row, | |
unsigned char | _column | |||
) |
returns the Value from state (_row, _column)
Definition at line 86 of file StateSpace.c.
References getState(), and State::value.
Referenced by ValueIteration::evaluateAction(), and main().
void StateSpace::init | ( | void | ) |
init function.
Definition at line 4 of file StateSpace.c.
References Ram::init(), ram1, and useInternalRAM.
Referenced by Controller::init().
00004 { 00005 00006 // use internal memory instead of FM24C256 00007 this->useInternalRAM = true; 00008 00009 // init ram 00010 ram1.init(); 00011 }
void StateSpace::ramtestReadBytes | ( | unsigned int | _addr, | |
unsigned char * | data, | |||
unsigned char | _length | |||
) |
RAM-Test function (e.g. reads random numbers into *data from memory)
Definition at line 127 of file StateSpace.c.
References internStateSpace, ram1, Ram::readBytes(), and useInternalRAM.
Referenced by V24Control::processCommand().
00127 { 00128 00129 unsigned char* statesPtr = (unsigned char*)&internStateSpace[0]; 00130 unsigned char i; 00131 00132 if (this->useInternalRAM) { 00133 for (i=0; i<_length; i++) { 00134 data[i] = statesPtr[_addr + i]; 00135 } 00136 00137 } else { 00138 ram1.readBytes(_addr, data, _length); 00139 } 00140 }
void StateSpace::ramtestSaveBytes | ( | unsigned int | _addr, | |
unsigned char * | data, | |||
unsigned char | _length | |||
) |
RAM-Test function (e.g. writes random numbers from *data to memory)
Definition at line 111 of file StateSpace.c.
References internStateSpace, ram1, useInternalRAM, and Ram::writeBytes().
Referenced by V24Control::processCommand().
00111 { 00112 00113 unsigned char* statesPtr = (unsigned char*)&internStateSpace[0]; 00114 unsigned char i; 00115 00116 if (this->useInternalRAM) { 00117 for (i=0; i<_length; i++) { 00118 statesPtr[_addr + i] = data[i]; 00119 } 00120 00121 } else { 00122 ram1.writeBytes(_addr, data, _length); 00123 } 00124 }
void StateSpace::setBestAction | ( | unsigned char | _row, | |
unsigned char | _column, | |||
unsigned char | _action | |||
) |
void StateSpace::setFeedback | ( | unsigned char | _row, | |
unsigned char | _column, | |||
unsigned char | _action, | |||
char | _fb | |||
) |
set reward r(s,_action)=_fb in state (_row, _column)
Definition at line 67 of file StateSpace.c.
References DOWN, State::feedback_down, State::feedback_left, State::feedback_right, State::feedback_up, getState(), LEFT, RIGHT, setState(), and UP.
Referenced by ValueIteration::moveAndSaveFeedback().
00067 { 00068 00069 STATE _s; 00070 this->getState (_row, _column, &_s); 00071 00072 if (_action == UP) { 00073 _s.feedback_up = _fb; 00074 } else if (_action == DOWN) { 00075 _s.feedback_down = _fb; 00076 } else if (_action == LEFT) { 00077 _s.feedback_left = _fb; 00078 } else if (_action == RIGHT) { 00079 _s.feedback_right = _fb; 00080 } 00081 00082 this->setState (_row, _column, &_s); 00083 }
void StateSpace::setState | ( | unsigned char | _row, | |
unsigned char | _column, | |||
STATE * | _state | |||
) |
update state (_row, _column) with _state
Definition at line 36 of file StateSpace.c.
References internStateSpace, ram1, scalX, STATESIZE, useInternalRAM, and Ram::writeBytes().
Referenced by V24Control::processSetState(), Controller::setDefaultPolicy(), setFeedback(), and setValue().
00036 { 00037 00038 unsigned int _addr; 00039 unsigned char i; 00040 unsigned char* _bytes = (unsigned char*)_state; 00041 00042 // compute memory address 00043 _addr = ((_row * scalX) + _column)*STATESIZE; 00044 00045 // internal RAM 00046 if (this->useInternalRAM) { 00047 for (i=0; i<STATESIZE; i++) { 00048 internStateSpace[_addr + i] = _bytes[i]; 00049 } 00050 00051 // SPI Memory 00052 } else { 00053 ram1.writeBytes(_addr, (unsigned char*)&_state[0], STATESIZE); 00054 } 00055 }
void StateSpace::setValue | ( | unsigned char | _row, | |
unsigned char | _column, | |||
float | _value | |||
) |
set Value in state (_row, _column)
Definition at line 58 of file StateSpace.c.
References getState(), setState(), and State::value.
Referenced by ValueIteration::valueIterateAllStates().
00058 { 00059 00060 STATE _s; 00061 this->getState ( _row, _column, &_s ); 00062 _s.value = _value; 00063 this->setState ( _row, _column, &_s ); 00064 }
unsigned char StateSpace::internStateSpace[sizeof(State)*200] [private] |
Definition at line 33 of file StateSpace.h.
Referenced by getMemorySize(), getState(), ramtestReadBytes(), ramtestSaveBytes(), and setState().
Ram StateSpace::ram1 [private] |
Definition at line 36 of file StateSpace.h.
Referenced by getState(), init(), ramtestReadBytes(), ramtestSaveBytes(), and setState().
unsigned char StateSpace::scalX |
Definition at line 26 of file StateSpace.h.
Referenced by ValueIteration::exploreAllFeedbacks(), getState(), ValueIteration::gotoRandomState(), Controller::gotoStateWithoutSavingFeedback(), ValueIteration::isValidAction(), ValueIteration::moveAndSaveFeedback(), V24Control::processCommand(), V24Control::processGetGridsize(), V24Control::processGetState(), V24Control::processSetGridsize(), V24Control::processSetState(), Controller::setDefaultPolicy(), setState(), and ValueIteration::valueIterateAllStates().
unsigned char StateSpace::scalY |
Definition at line 26 of file StateSpace.h.
Referenced by ValueIteration::exploreAllFeedbacks(), ValueIteration::gotoRandomState(), Controller::gotoStateWithoutSavingFeedback(), ValueIteration::isValidAction(), ValueIteration::moveAndSaveFeedback(), V24Control::processCommand(), V24Control::processGetGridsize(), V24Control::processGetState(), V24Control::processSetGridsize(), V24Control::processSetState(), Controller::setDefaultPolicy(), and ValueIteration::valueIterateAllStates().
STATE StateSpace::tmpState [private] |
Definition at line 30 of file StateSpace.h.
Definition at line 27 of file StateSpace.h.
Referenced by getMemorySize(), getState(), init(), ramtestReadBytes(), ramtestSaveBytes(), and setState().