der Roboter
/
VariablesGradient
Explanation of Variables
Fork of BlueToothStuff by
main.cpp@2:acc52907bcce, 2014-06-06 (annotated)
- Committer:
- bayagich
- Date:
- Fri Jun 06 09:46:32 2014 +0000
- Revision:
- 2:acc52907bcce
- Parent:
- 1:6402638c6f6d
- Child:
- 3:ac07a11318f9
Has explanation of all the variables that will be used
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bayagich | 2:acc52907bcce | 1 | //This will define all variables needed for the gradient equation |
bayagich | 2:acc52907bcce | 2 | // EQUATION: w(new) = a*w*cost(w*t) + c*sensor2*sin(wt) - d*(sensor2^2)*sin(wt) |
bayagich | 2:acc52907bcce | 3 | //u is modified by the w found, u = cos(wt) |
bayagich | 2:acc52907bcce | 4 | //leftspeed = left + u |
bayagich | 2:acc52907bcce | 5 | //rightspeed = right - u |
bayagich | 2:acc52907bcce | 6 | |
mmpeter | 0:386c250325ce | 7 | #include "mbed.h" |
mmpeter | 0:386c250325ce | 8 | #include "m3pi_ng.h" |
mmpeter | 0:386c250325ce | 9 | #include "cmath" |
mmpeter | 0:386c250325ce | 10 | #include "iostream" |
satyson | 1:6402638c6f6d | 11 | #include "btbee.h" |
mmpeter | 0:386c250325ce | 12 | |
mmpeter | 0:386c250325ce | 13 | using namespace std; |
mmpeter | 0:386c250325ce | 14 | |
mmpeter | 0:386c250325ce | 15 | m3pi thinggy; |
satyson | 1:6402638c6f6d | 16 | btbee btbee; |
mmpeter | 0:386c250325ce | 17 | |
mmpeter | 0:386c250325ce | 18 | int main() { |
bayagich | 2:acc52907bcce | 19 | |
bayagich | 2:acc52907bcce | 20 | int sensor[5]; |
bayagich | 2:acc52907bcce | 21 | |
bayagich | 2:acc52907bcce | 22 | //w = angular frequency, which is modified after you take each time |
bayagich | 2:acc52907bcce | 23 | int w = 0.5; |
bayagich | 2:acc52907bcce | 24 | |
bayagich | 2:acc52907bcce | 25 | //t = how frequently you change w |
bayagich | 2:acc52907bcce | 26 | //should be between 0.001 and 0.01 |
bayagich | 2:acc52907bcce | 27 | int t = 0.001; |
bayagich | 2:acc52907bcce | 28 | |
bayagich | 2:acc52907bcce | 29 | //variables in the equation to calculate angular frequency |
bayagich | 2:acc52907bcce | 30 | int a = 1; |
bayagich | 2:acc52907bcce | 31 | int c = 1; |
bayagich | 2:acc52907bcce | 32 | int d = 1; |
bayagich | 2:acc52907bcce | 33 | |
bayagich | 2:acc52907bcce | 34 | //the middle sensor value you take every t seconds |
bayagich | 2:acc52907bcce | 35 | int sensor2; |
bayagich | 2:acc52907bcce | 36 | |
bayagich | 2:acc52907bcce | 37 | //NOT DONE need variables for an equation that filters out noise |
mmpeter | 0:386c250325ce | 38 | |
bayagich | 2:acc52907bcce | 39 | //this u alters left speed and right speed |
bayagich | 2:acc52907bcce | 40 | int u; |
bayagich | 2:acc52907bcce | 41 | int leftspeed = .01; |
bayagich | 2:acc52907bcce | 42 | int right speed = .01; |
bayagich | 2:acc52907bcce | 43 | |
bayagich | 2:acc52907bcce | 44 | //read in sensor value |
bayagich | 2:acc52907bcce | 45 | thinggy.raw_sensor(sensor); |
bayagich | 2:acc52907bcce | 46 | sensor2 = sensor[2]; |
mmpeter | 0:386c250325ce | 47 | |
bayagich | 2:acc52907bcce | 48 | //variable if the best point is found |
bayagich | 2:acc52907bcce | 49 | int found = 0; |
bayagich | 2:acc52907bcce | 50 | |
bayagich | 2:acc52907bcce | 51 | //loop to change w as it picks up values |
bayagich | 2:acc52907bcce | 52 | while(!found){ |
bayagich | 2:acc52907bcce | 53 | |
bayagich | 2:acc52907bcce | 54 | |
bayagich | 2:acc52907bcce | 55 | |
bayagich | 2:acc52907bcce | 56 | }//while(!found) |
bayagich | 2:acc52907bcce | 57 | |
bayagich | 2:acc52907bcce | 58 | |
mmpeter | 0:386c250325ce | 59 | |
mmpeter | 0:386c250325ce | 60 | |
mmpeter | 0:386c250325ce | 61 | } |
mmpeter | 0:386c250325ce | 62 | |
mmpeter | 0:386c250325ce | 63 |