Biorobotics
/
piano_robot
newest version,
Diff: update.cpp
- Revision:
- 0:fc6fa085d591
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/update.cpp Fri Oct 23 13:14:57 2015 +0000 @@ -0,0 +1,100 @@ +/* + * update.cpp + * + * Created on: Oct 16, 2015 + * Author: User + */ + + +#include <iostream> +#include <string> +#include "move_motor.h"; +/* + * takes state and num_on_inputs as input variables, if num_on_inputs means been in one state for 0.25s + * it calls the motor movement function according to the state (left/right or key press) +*/ +void update(std::string state, int &num_on_inputs) +{ + //check if system has been in one state long enough to move + if (num_on_inputs == 250) + { + //reset the number of on inputs so that once function finishes robot is 'reinitialised' + num_on_inputs = 0; + //run left/right motor, key press motor or do nothing depending on the state + if (state == "left" or state == "right" or state == "keypress") + { + //function to be created and included as h file + move_motor(state); + //std::cout << "left or right \n"; + } + + else if (state == "rest") + { + //if at rest do nothing + //std::cout << "rest "; + } + else + { + //throw an error somehow + //std::cout << "error \n "; + } + } + else if (num_on_inputs > 250) + { + //std::cout << "error \n "; + } +} + +/* +void update(std::string state, int &num_on_inputs) +{ + //check if system has been in one state long enough to move + if (num_on_inputs == 250) + { + //reset the number of on inputs so that once function finishes robot is 'reinitialised' + num_on_inputs = 0; + //run left/right motor, key press motor or do nothing depending on the state + if (state == "left" or state == "right") + { + //function to be created and included as h file + //move_horizontal_motor(state) + std::cout << "left or right \n"; + } + else if (state == "keypress") + { + //function to be created and its h file included + //move_keypress_motor() + std::cout << "keypress \n "; + } + else if (state == "rest") + { + //if at rest do nothing + std::cout << "rest "; + } + else + { + //throw an error somehow + std::cout << "error \n "; + } + } + else if (num_on_inputs > 250) + { + std::cout << "error \n "; + } +} + +int main() +{ + std::string state = "left"; + int num_on_inputs = 250; + + update(state, num_on_inputs); + + std::cout << num_on_inputs << "!\n"; + + return 0; +} + */ + + +