GDP 4
/
mbed_transferfunction
Steering Servo Step responses
main.cpp@0:4a3f069b314a, 2016-11-24 (annotated)
- Committer:
- oj3g13
- Date:
- Thu Nov 24 10:39:45 2016 +0000
- Revision:
- 0:4a3f069b314a
Mbed initialises servos, waits 3 seconds, moves servo to different PWM values at random time intervals
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
oj3g13 | 0:4a3f069b314a | 1 | #include "mbed.h" |
oj3g13 | 0:4a3f069b314a | 2 | #include "TFC.h" |
oj3g13 | 0:4a3f069b314a | 3 | #define MULTIPLIER 0.25 |
oj3g13 | 0:4a3f069b314a | 4 | |
oj3g13 | 0:4a3f069b314a | 5 | DigitalOut gpo(D0); |
oj3g13 | 0:4a3f069b314a | 6 | |
oj3g13 | 0:4a3f069b314a | 7 | int main() |
oj3g13 | 0:4a3f069b314a | 8 | { |
oj3g13 | 0:4a3f069b314a | 9 | TFC_Init(); |
oj3g13 | 0:4a3f069b314a | 10 | TFC_InitServos(0.00052,0.00122,0.02); |
oj3g13 | 0:4a3f069b314a | 11 | float i; |
oj3g13 | 0:4a3f069b314a | 12 | wait(3); |
oj3g13 | 0:4a3f069b314a | 13 | float rand_max=RAND_MAX; |
oj3g13 | 0:4a3f069b314a | 14 | while(true) |
oj3g13 | 0:4a3f069b314a | 15 | { |
oj3g13 | 0:4a3f069b314a | 16 | i = (rand()/rand_max)*MULTIPLIER; |
oj3g13 | 0:4a3f069b314a | 17 | |
oj3g13 | 0:4a3f069b314a | 18 | |
oj3g13 | 0:4a3f069b314a | 19 | |
oj3g13 | 0:4a3f069b314a | 20 | |
oj3g13 | 0:4a3f069b314a | 21 | gpo = !gpo; // toggle pin |
oj3g13 | 0:4a3f069b314a | 22 | TFC_SetServo(0,-1.0); |
oj3g13 | 0:4a3f069b314a | 23 | wait(i); |
oj3g13 | 0:4a3f069b314a | 24 | i = (rand()/rand_max)*MULTIPLIER; |
oj3g13 | 0:4a3f069b314a | 25 | |
oj3g13 | 0:4a3f069b314a | 26 | gpo = !gpo; |
oj3g13 | 0:4a3f069b314a | 27 | TFC_SetServo(0,0.4); |
oj3g13 | 0:4a3f069b314a | 28 | wait(i); |
oj3g13 | 0:4a3f069b314a | 29 | i = (rand()/rand_max)*MULTIPLIER; |
oj3g13 | 0:4a3f069b314a | 30 | |
oj3g13 | 0:4a3f069b314a | 31 | gpo = !gpo; |
oj3g13 | 0:4a3f069b314a | 32 | TFC_SetServo(0,0); |
oj3g13 | 0:4a3f069b314a | 33 | wait(i); |
oj3g13 | 0:4a3f069b314a | 34 | i = (rand()/rand_max)*MULTIPLIER; |
oj3g13 | 0:4a3f069b314a | 35 | |
oj3g13 | 0:4a3f069b314a | 36 | gpo = !gpo; |
oj3g13 | 0:4a3f069b314a | 37 | TFC_SetServo(0,-0.6); |
oj3g13 | 0:4a3f069b314a | 38 | wait(i); |
oj3g13 | 0:4a3f069b314a | 39 | i = (rand()/rand_max)*MULTIPLIER; |
oj3g13 | 0:4a3f069b314a | 40 | |
oj3g13 | 0:4a3f069b314a | 41 | gpo = !gpo; |
oj3g13 | 0:4a3f069b314a | 42 | TFC_SetServo(0,-0.5); |
oj3g13 | 0:4a3f069b314a | 43 | wait(i); |
oj3g13 | 0:4a3f069b314a | 44 | i = (rand()/rand_max)*MULTIPLIER; |
oj3g13 | 0:4a3f069b314a | 45 | |
oj3g13 | 0:4a3f069b314a | 46 | gpo = !gpo; |
oj3g13 | 0:4a3f069b314a | 47 | TFC_SetServo(0,-0.7); |
oj3g13 | 0:4a3f069b314a | 48 | wait(i); |
oj3g13 | 0:4a3f069b314a | 49 | i = (rand()/rand_max)*MULTIPLIER; |
oj3g13 | 0:4a3f069b314a | 50 | |
oj3g13 | 0:4a3f069b314a | 51 | gpo = !gpo; |
oj3g13 | 0:4a3f069b314a | 52 | TFC_SetServo(0,0.9); |
oj3g13 | 0:4a3f069b314a | 53 | wait(i); |
oj3g13 | 0:4a3f069b314a | 54 | i = (rand()/rand_max)*MULTIPLIER; |
oj3g13 | 0:4a3f069b314a | 55 | |
oj3g13 | 0:4a3f069b314a | 56 | gpo = !gpo; |
oj3g13 | 0:4a3f069b314a | 57 | TFC_SetServo(0,0.5); |
oj3g13 | 0:4a3f069b314a | 58 | wait(i); |
oj3g13 | 0:4a3f069b314a | 59 | i = (rand()/rand_max)*MULTIPLIER; |
oj3g13 | 0:4a3f069b314a | 60 | |
oj3g13 | 0:4a3f069b314a | 61 | } |
oj3g13 | 0:4a3f069b314a | 62 | } |