Biorobotics
/
piano_robot
newest version,
check_state_change.cpp@3:11c2175b4478, 2015-10-26 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
NickDGreg | 0:fc6fa085d591 | 1 | /* |
NickDGreg | 0:fc6fa085d591 | 2 | * check_state_change.cpp |
NickDGreg | 0:fc6fa085d591 | 3 | * |
NickDGreg | 0:fc6fa085d591 | 4 | * Created on: Oct 20, 2015 |
NickDGreg | 0:fc6fa085d591 | 5 | * Author: User |
NickDGreg | 0:fc6fa085d591 | 6 | */ |
NickDGreg | 0:fc6fa085d591 | 7 | |
NickDGreg | 0:fc6fa085d591 | 8 | #include "mbed.h" |
NickDGreg | 0:fc6fa085d591 | 9 | #include <iostream> |
NickDGreg | 0:fc6fa085d591 | 10 | |
NickDGreg | 0:fc6fa085d591 | 11 | //threashold to turn on the system if it is off |
NickDGreg | 0:fc6fa085d591 | 12 | double threashold_turn_on = 10; |
NickDGreg | 0:fc6fa085d591 | 13 | |
NickDGreg | 0:fc6fa085d591 | 14 | //threashold to turn of the system if it is on |
NickDGreg | 0:fc6fa085d591 | 15 | double threashold_turn_off = 9; |
NickDGreg | 0:fc6fa085d591 | 16 | |
NickDGreg | 0:fc6fa085d591 | 17 | void check_state_change(std::string &state, std::string newState, int &num_on_inputs, double &threashold) |
NickDGreg | 0:fc6fa085d591 | 18 | { |
NickDGreg | 0:fc6fa085d591 | 19 | if (state == newState) |
NickDGreg | 0:fc6fa085d591 | 20 | { |
NickDGreg | 0:fc6fa085d591 | 21 | //add one to the count to track how long the muscle is tense for (update() moves motor if tensed for 0.25s) |
NickDGreg | 0:fc6fa085d591 | 22 | //if at rest then still tracked but update function will not move the motor only reset num_on_inputs |
NickDGreg | 0:fc6fa085d591 | 23 | num_on_inputs++; |
NickDGreg | 0:fc6fa085d591 | 24 | |
NickDGreg | 0:fc6fa085d591 | 25 | } |
NickDGreg | 0:fc6fa085d591 | 26 | else |
NickDGreg | 0:fc6fa085d591 | 27 | { |
NickDGreg | 0:fc6fa085d591 | 28 | //state change so reset the values of on inputs |
NickDGreg | 0:fc6fa085d591 | 29 | num_on_inputs = 0; |
NickDGreg | 0:fc6fa085d591 | 30 | //change state to newState |
NickDGreg | 0:fc6fa085d591 | 31 | state = newState; |
NickDGreg | 0:fc6fa085d591 | 32 | |
NickDGreg | 0:fc6fa085d591 | 33 | //change the threashold as there has been a change of state |
NickDGreg | 0:fc6fa085d591 | 34 | if (newState == "rest") |
NickDGreg | 0:fc6fa085d591 | 35 | { |
NickDGreg | 0:fc6fa085d591 | 36 | //we know the system has switched from on to off so set threashold to turn on threashold |
NickDGreg | 0:fc6fa085d591 | 37 | threashold = threashold_turn_on; |
NickDGreg | 0:fc6fa085d591 | 38 | } |
NickDGreg | 0:fc6fa085d591 | 39 | |
NickDGreg | 0:fc6fa085d591 | 40 | else |
NickDGreg | 0:fc6fa085d591 | 41 | { |
NickDGreg | 0:fc6fa085d591 | 42 | //we know the system has switched from rest to left, right, or keypress i.e. off to on |
NickDGreg | 0:fc6fa085d591 | 43 | threashold = threashold_turn_off; |
NickDGreg | 0:fc6fa085d591 | 44 | } |
NickDGreg | 0:fc6fa085d591 | 45 | } |
NickDGreg | 0:fc6fa085d591 | 46 | } |
NickDGreg | 0:fc6fa085d591 | 47 | |
NickDGreg | 0:fc6fa085d591 | 48 | |
NickDGreg | 0:fc6fa085d591 | 49 | |
NickDGreg | 0:fc6fa085d591 | 50 | |
NickDGreg | 0:fc6fa085d591 | 51 |