newest version,

Dependencies:   QEI mbed

Committer:
roosbulthuis
Date:
Mon Oct 26 11:42:17 2015 +0000
Revision:
3:11c2175b4478
Parent:
0:fc6fa085d591
New file for filters without classes, check if input and output are correct. Should be pasted into main code.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NickDGreg 0:fc6fa085d591 1 /*
NickDGreg 0:fc6fa085d591 2 * update.cpp
NickDGreg 0:fc6fa085d591 3 *
NickDGreg 0:fc6fa085d591 4 * Created on: Oct 16, 2015
NickDGreg 0:fc6fa085d591 5 * Author: User
NickDGreg 0:fc6fa085d591 6 */
NickDGreg 0:fc6fa085d591 7
NickDGreg 0:fc6fa085d591 8
NickDGreg 0:fc6fa085d591 9 #include <iostream>
NickDGreg 0:fc6fa085d591 10 #include <string>
NickDGreg 0:fc6fa085d591 11 #include "move_motor.h";
NickDGreg 0:fc6fa085d591 12 /*
NickDGreg 0:fc6fa085d591 13 * takes state and num_on_inputs as input variables, if num_on_inputs means been in one state for 0.25s
NickDGreg 0:fc6fa085d591 14 * it calls the motor movement function according to the state (left/right or key press)
NickDGreg 0:fc6fa085d591 15 */
NickDGreg 0:fc6fa085d591 16 void update(std::string state, int &num_on_inputs)
NickDGreg 0:fc6fa085d591 17 {
NickDGreg 0:fc6fa085d591 18 //check if system has been in one state long enough to move
NickDGreg 0:fc6fa085d591 19 if (num_on_inputs == 250)
NickDGreg 0:fc6fa085d591 20 {
NickDGreg 0:fc6fa085d591 21 //reset the number of on inputs so that once function finishes robot is 'reinitialised'
NickDGreg 0:fc6fa085d591 22 num_on_inputs = 0;
NickDGreg 0:fc6fa085d591 23 //run left/right motor, key press motor or do nothing depending on the state
NickDGreg 0:fc6fa085d591 24 if (state == "left" or state == "right" or state == "keypress")
NickDGreg 0:fc6fa085d591 25 {
NickDGreg 0:fc6fa085d591 26 //function to be created and included as h file
NickDGreg 0:fc6fa085d591 27 move_motor(state);
NickDGreg 0:fc6fa085d591 28 //std::cout << "left or right \n";
NickDGreg 0:fc6fa085d591 29 }
NickDGreg 0:fc6fa085d591 30
NickDGreg 0:fc6fa085d591 31 else if (state == "rest")
NickDGreg 0:fc6fa085d591 32 {
NickDGreg 0:fc6fa085d591 33 //if at rest do nothing
NickDGreg 0:fc6fa085d591 34 //std::cout << "rest ";
NickDGreg 0:fc6fa085d591 35 }
NickDGreg 0:fc6fa085d591 36 else
NickDGreg 0:fc6fa085d591 37 {
NickDGreg 0:fc6fa085d591 38 //throw an error somehow
NickDGreg 0:fc6fa085d591 39 //std::cout << "error \n ";
NickDGreg 0:fc6fa085d591 40 }
NickDGreg 0:fc6fa085d591 41 }
NickDGreg 0:fc6fa085d591 42 else if (num_on_inputs > 250)
NickDGreg 0:fc6fa085d591 43 {
NickDGreg 0:fc6fa085d591 44 //std::cout << "error \n ";
NickDGreg 0:fc6fa085d591 45 }
NickDGreg 0:fc6fa085d591 46 }
NickDGreg 0:fc6fa085d591 47
NickDGreg 0:fc6fa085d591 48 /*
NickDGreg 0:fc6fa085d591 49 void update(std::string state, int &num_on_inputs)
NickDGreg 0:fc6fa085d591 50 {
NickDGreg 0:fc6fa085d591 51 //check if system has been in one state long enough to move
NickDGreg 0:fc6fa085d591 52 if (num_on_inputs == 250)
NickDGreg 0:fc6fa085d591 53 {
NickDGreg 0:fc6fa085d591 54 //reset the number of on inputs so that once function finishes robot is 'reinitialised'
NickDGreg 0:fc6fa085d591 55 num_on_inputs = 0;
NickDGreg 0:fc6fa085d591 56 //run left/right motor, key press motor or do nothing depending on the state
NickDGreg 0:fc6fa085d591 57 if (state == "left" or state == "right")
NickDGreg 0:fc6fa085d591 58 {
NickDGreg 0:fc6fa085d591 59 //function to be created and included as h file
NickDGreg 0:fc6fa085d591 60 //move_horizontal_motor(state)
NickDGreg 0:fc6fa085d591 61 std::cout << "left or right \n";
NickDGreg 0:fc6fa085d591 62 }
NickDGreg 0:fc6fa085d591 63 else if (state == "keypress")
NickDGreg 0:fc6fa085d591 64 {
NickDGreg 0:fc6fa085d591 65 //function to be created and its h file included
NickDGreg 0:fc6fa085d591 66 //move_keypress_motor()
NickDGreg 0:fc6fa085d591 67 std::cout << "keypress \n ";
NickDGreg 0:fc6fa085d591 68 }
NickDGreg 0:fc6fa085d591 69 else if (state == "rest")
NickDGreg 0:fc6fa085d591 70 {
NickDGreg 0:fc6fa085d591 71 //if at rest do nothing
NickDGreg 0:fc6fa085d591 72 std::cout << "rest ";
NickDGreg 0:fc6fa085d591 73 }
NickDGreg 0:fc6fa085d591 74 else
NickDGreg 0:fc6fa085d591 75 {
NickDGreg 0:fc6fa085d591 76 //throw an error somehow
NickDGreg 0:fc6fa085d591 77 std::cout << "error \n ";
NickDGreg 0:fc6fa085d591 78 }
NickDGreg 0:fc6fa085d591 79 }
NickDGreg 0:fc6fa085d591 80 else if (num_on_inputs > 250)
NickDGreg 0:fc6fa085d591 81 {
NickDGreg 0:fc6fa085d591 82 std::cout << "error \n ";
NickDGreg 0:fc6fa085d591 83 }
NickDGreg 0:fc6fa085d591 84 }
NickDGreg 0:fc6fa085d591 85
NickDGreg 0:fc6fa085d591 86 int main()
NickDGreg 0:fc6fa085d591 87 {
NickDGreg 0:fc6fa085d591 88 std::string state = "left";
NickDGreg 0:fc6fa085d591 89 int num_on_inputs = 250;
NickDGreg 0:fc6fa085d591 90
NickDGreg 0:fc6fa085d591 91 update(state, num_on_inputs);
NickDGreg 0:fc6fa085d591 92
NickDGreg 0:fc6fa085d591 93 std::cout << num_on_inputs << "!\n";
NickDGreg 0:fc6fa085d591 94
NickDGreg 0:fc6fa085d591 95 return 0;
NickDGreg 0:fc6fa085d591 96 }
NickDGreg 0:fc6fa085d591 97 */
NickDGreg 0:fc6fa085d591 98
NickDGreg 0:fc6fa085d591 99
NickDGreg 0:fc6fa085d591 100