Created
August 21, 2016 07:12
-
-
Save Tutorgaming/4a3b12c0a73734bb6229cfb6d7c086bc to your computer and use it in GitHub Desktop.
Simple State Machine for Robot Controlling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
char user_input; | |
char state; | |
void getInput(){ | |
std::cout << "please insert input : "; | |
std::cin >> user_input; | |
// Interpret Input as an states | |
state = user_input; | |
} | |
void action(){ | |
switch (state) { | |
case "w": | |
//forward command | |
std::cout << "[State]Forwarding" <<std::endl; | |
break; | |
case "s": | |
//stop command | |
std::cout << "[State]Stopping" << std::endl; | |
break; | |
case "x": | |
//backward command | |
std::cout << "[State]Backward" << std::endl; | |
break; | |
case "a": | |
//turn left command | |
std::cout << "[State]Turning Left" <<std::endl; | |
break; | |
case "d": | |
//turn right command | |
std::cout << "[State]Turning Right" <<std::endl; | |
break; | |
default: | |
//default routine | |
std::cout << "[State]Default Routine = Stopping" <<std::endl; | |
break; | |
} | |
} | |
void nextState(){ | |
} | |
int main(int argc, char const *argv[]) { | |
// Assign initial state | |
// Begin Machine | |
while(true){ | |
getInput(); // Move to the latched thread callback input | |
action(); | |
nextState(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment