513
edits
No edit summary |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 46: | Line 46: | ||
—> if sleeping and getting hungry -> looking for food, if looking for food and food has been found -> eating, .. | —> if sleeping and getting hungry -> looking for food, if looking for food and food has been found -> eating, .. | ||
* a list that includes every situation (state) in connection to one specific action (output) that is carried out as soon as the corresponding state arrives | |||
—> looking for food / move around, eating / stop, .. | —> looking for food / move around, eating / stop, .. | ||
| Line 106: | Line 106: | ||
First of all we need a variable that saves the current state. It represents our State Machines memory. <br> | First of all we need a variable that saves the current state. It represents our State Machines memory. <br> | ||
The most suitable type for such a variable is in this case an | The most suitable type for such a variable is in this case an "[https://en.wikipedia.org/wiki/Enumerated_type enum]".<br> | ||
This enum assigns different names to values: | This enum assigns different names to values: | ||
| Line 130: | Line 130: | ||
The internal structure of these functions is always the same: | The internal structure of these functions is always the same: | ||
1) conduct actions that fit to the particular state. (turn motors on / off, start a timer, ..) | 1) conduct actions that fit to the particular state. (turn motors on / off, start a timer, ..)<br> | ||
2) read input data (sensors, timer, ..) that provides information about the next possible state | 2) read input data (sensors, timer, ..) that provides information about the next possible state<br> | ||
3) decide the next state | 3) decide the next state | ||
The third part can be done quite comfortably by giving back the new | The third part can be done quite comfortably by giving back the new "state" - value in form of the functions "return" - value into the main loop. | ||
This is an example of how the | This is an example of how the "standby"-state could look like: | ||
[[File:robot_standbyfunc.jpg]] | [[File:robot_standbyfunc.jpg]] | ||
edits