![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Slow version
Fork of SunflowerMach1 by
main.cpp@1:2e7d4aa6e79e, 2013-11-08 (annotated)
- Committer:
- cvitas
- Date:
- Fri Nov 08 22:33:31 2013 +0000
- Revision:
- 1:2e7d4aa6e79e
- Parent:
- 0:7447b8021b33
Version 1a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mdraganic | 0:7447b8021b33 | 1 | #include "mbed.h" |
mdraganic | 0:7447b8021b33 | 2 | #include "Motor.h" |
mdraganic | 0:7447b8021b33 | 3 | |
mdraganic | 0:7447b8021b33 | 4 | AnalogIn ainSensA(p17); |
mdraganic | 0:7447b8021b33 | 5 | AnalogIn ainSensB(p18); |
mdraganic | 0:7447b8021b33 | 6 | AnalogIn ainSensC(p19); |
mdraganic | 0:7447b8021b33 | 7 | AnalogIn ainSensD(p20); |
mdraganic | 0:7447b8021b33 | 8 | |
mdraganic | 0:7447b8021b33 | 9 | int valAzimut = 0; |
mdraganic | 0:7447b8021b33 | 10 | int valElevacija = 0; |
cvitas | 1:2e7d4aa6e79e | 11 | float SensA, SensB, SensC, SensD; |
mdraganic | 0:7447b8021b33 | 12 | |
mdraganic | 0:7447b8021b33 | 13 | int main() { |
mdraganic | 0:7447b8021b33 | 14 | |
cvitas | 1:2e7d4aa6e79e | 15 | Motor *motorEl = new Motor(p25, p26, p24); |
cvitas | 1:2e7d4aa6e79e | 16 | Motor *motorAz = new Motor(p22, p21, p23); |
cvitas | 1:2e7d4aa6e79e | 17 | |
cvitas | 1:2e7d4aa6e79e | 18 | (*motorAz).stop(); |
cvitas | 1:2e7d4aa6e79e | 19 | (*motorEl).stop(); |
mdraganic | 0:7447b8021b33 | 20 | |
cvitas | 1:2e7d4aa6e79e | 21 | while(1) { |
cvitas | 1:2e7d4aa6e79e | 22 | SensA= 0; // initiate values before averaging |
cvitas | 1:2e7d4aa6e79e | 23 | SensB= 0; |
cvitas | 1:2e7d4aa6e79e | 24 | SensC= 0; |
cvitas | 1:2e7d4aa6e79e | 25 | SensD= 0; |
cvitas | 1:2e7d4aa6e79e | 26 | for (int i=0; i<=9; i++) { |
cvitas | 1:2e7d4aa6e79e | 27 | SensA= SensA + ainSensA; //get 10 samples of sensors values |
cvitas | 1:2e7d4aa6e79e | 28 | SensB= SensB + ainSensB; |
cvitas | 1:2e7d4aa6e79e | 29 | SensC= SensC + ainSensC; |
cvitas | 1:2e7d4aa6e79e | 30 | SensD= SensD + ainSensD; |
cvitas | 1:2e7d4aa6e79e | 31 | } |
cvitas | 1:2e7d4aa6e79e | 32 | SensA= SensA/10; |
cvitas | 1:2e7d4aa6e79e | 33 | SensB= SensB/10; |
cvitas | 1:2e7d4aa6e79e | 34 | SensC= SensC/10; |
cvitas | 1:2e7d4aa6e79e | 35 | SensD= SensD/10; |
cvitas | 1:2e7d4aa6e79e | 36 | |
cvitas | 1:2e7d4aa6e79e | 37 | valAzimut = (SensA + SensB) - (SensC + SensD); |
cvitas | 1:2e7d4aa6e79e | 38 | valElevacija = (SensB + SensC) - (SensA + SensD); |
cvitas | 1:2e7d4aa6e79e | 39 | |
cvitas | 1:2e7d4aa6e79e | 40 | if (valAzimut > 0.2){ |
cvitas | 1:2e7d4aa6e79e | 41 | // positive azimuth deviation |
cvitas | 1:2e7d4aa6e79e | 42 | (*motorAz).movePositiveSlow(); |
cvitas | 1:2e7d4aa6e79e | 43 | } |
cvitas | 1:2e7d4aa6e79e | 44 | else if (valAzimut < -0.2) { |
cvitas | 1:2e7d4aa6e79e | 45 | // negative azimuth deviation |
cvitas | 1:2e7d4aa6e79e | 46 | (*motorAz).moveNegativeSlow(); |
cvitas | 1:2e7d4aa6e79e | 47 | } |
cvitas | 1:2e7d4aa6e79e | 48 | (*motorAz).stopslow(); |
cvitas | 1:2e7d4aa6e79e | 49 | |
cvitas | 1:2e7d4aa6e79e | 50 | if (valElevacija > 0.2){ |
cvitas | 1:2e7d4aa6e79e | 51 | // positive azimuth deviation |
cvitas | 1:2e7d4aa6e79e | 52 | (*motorEl).movePositiveSlow(); |
cvitas | 1:2e7d4aa6e79e | 53 | } |
cvitas | 1:2e7d4aa6e79e | 54 | else if (valElevacija < -0.2) { |
cvitas | 1:2e7d4aa6e79e | 55 | // negative azimuth deviation |
cvitas | 1:2e7d4aa6e79e | 56 | (*motorEl).moveNegativeSlow(); |
cvitas | 1:2e7d4aa6e79e | 57 | } |
cvitas | 1:2e7d4aa6e79e | 58 | (*motorEl).stopslow(); |
cvitas | 1:2e7d4aa6e79e | 59 | |
cvitas | 1:2e7d4aa6e79e | 60 | /* |
mdraganic | 0:7447b8021b33 | 61 | (*motorEl).stop(); |
mdraganic | 0:7447b8021b33 | 62 | (*motorEl).movePositive(); |
mdraganic | 0:7447b8021b33 | 63 | (*motorEl).moveNegative(); |
cvitas | 1:2e7d4aa6e79e | 64 | */ |
mdraganic | 0:7447b8021b33 | 65 | |
mdraganic | 0:7447b8021b33 | 66 | } |
mdraganic | 0:7447b8021b33 | 67 | } |