a simple library to control an animatronic head
Alex.cpp@4:45d466252fb6, 2011-05-10 (annotated)
- Committer:
- mxjac
- Date:
- Tue May 10 08:46:15 2011 +0000
- Revision:
- 4:45d466252fb6
- Parent:
- 3:5271cc1a527b
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mxjac | 0:8474cbec06bd | 1 | #include "Alex.h" |
mxjac | 0:8474cbec06bd | 2 | |
mxjac | 1:c5edd3b18b79 | 3 | Alex::Alex(SRF05 s, Servo e, Servo m, Servo l, Servo r):S(s), E(e), M(m), L(l), R(r), Led(LED1), pc(USBTX, USBRX) |
mxjac | 0:8474cbec06bd | 4 | { |
mxjac | 0:8474cbec06bd | 5 | } |
mxjac | 0:8474cbec06bd | 6 | Alex::~Alex() |
mxjac | 0:8474cbec06bd | 7 | { |
mxjac | 0:8474cbec06bd | 8 | } |
mxjac | 0:8474cbec06bd | 9 | void Alex::TestHead() |
mxjac | 0:8474cbec06bd | 10 | { |
mxjac | 0:8474cbec06bd | 11 | Led=1; |
mxjac | 0:8474cbec06bd | 12 | wait(0.02); |
mxjac | 0:8474cbec06bd | 13 | Led=0; |
mxjac | 0:8474cbec06bd | 14 | } |
mxjac | 0:8474cbec06bd | 15 | int Alex::Testpresence() |
mxjac | 0:8474cbec06bd | 16 | { |
mxjac | 0:8474cbec06bd | 17 | if((S.read()==0)||(S.read()>=500)){return 0;}//if presence is too close, return 0 |
mxjac | 0:8474cbec06bd | 18 | if(S.read()>=40){return 1;}//if presence is too far, return 1 |
mxjac | 0:8474cbec06bd | 19 | if((S.read()>=0)&&(S.read()<=40)){return 2;}//if presence is between O and 40cm, return 2 |
mxjac | 0:8474cbec06bd | 20 | return 0; |
mxjac | 0:8474cbec06bd | 21 | } |
mxjac | 0:8474cbec06bd | 22 | void Alex::Move_eyes(int valuee) |
mxjac | 0:8474cbec06bd | 23 | { |
mxjac | 0:8474cbec06bd | 24 | for(int i=0; i<valuee; i++) |
mxjac | 0:8474cbec06bd | 25 | { |
mxjac | 0:8474cbec06bd | 26 | E=i; |
mxjac | 0:8474cbec06bd | 27 | wait(0.1); |
mxjac | 0:8474cbec06bd | 28 | } |
mxjac | 0:8474cbec06bd | 29 | } |
mxjac | 0:8474cbec06bd | 30 | void Alex::Move_mouth(int valuem) |
mxjac | 0:8474cbec06bd | 31 | { |
mxjac | 0:8474cbec06bd | 32 | for(int i=0; i<valuem; i++) |
mxjac | 0:8474cbec06bd | 33 | { |
mxjac | 0:8474cbec06bd | 34 | M=i; |
mxjac | 0:8474cbec06bd | 35 | wait(0.1); |
mxjac | 0:8474cbec06bd | 36 | } |
mxjac | 0:8474cbec06bd | 37 | } |
mxjac | 0:8474cbec06bd | 38 | void Alex::Move_leaning(int valuel) |
mxjac | 0:8474cbec06bd | 39 | { |
mxjac | 0:8474cbec06bd | 40 | for(int i=0; i<valuel; i++) |
mxjac | 0:8474cbec06bd | 41 | { |
mxjac | 0:8474cbec06bd | 42 | L=i; |
mxjac | 0:8474cbec06bd | 43 | wait(0.1); |
mxjac | 0:8474cbec06bd | 44 | } |
mxjac | 0:8474cbec06bd | 45 | } |
mxjac | 0:8474cbec06bd | 46 | void Alex::Move_rotation(int valuer) |
mxjac | 0:8474cbec06bd | 47 | { |
mxjac | 0:8474cbec06bd | 48 | for(int i=0; i<valuer; i++) |
mxjac | 0:8474cbec06bd | 49 | { |
mxjac | 0:8474cbec06bd | 50 | R=i; |
mxjac | 0:8474cbec06bd | 51 | wait(0.1); |
mxjac | 0:8474cbec06bd | 52 | } |
mxjac | 1:c5edd3b18b79 | 53 | } |
mxjac | 4:45d466252fb6 | 54 | /* |
mxjac | 4:45d466252fb6 | 55 | //void Alex::Simulate_Talking(int length) |
mxjac | 1:c5edd3b18b79 | 56 | { |
mxjac | 4:45d466252fb6 | 57 | //for(int i=0; i<length; i++) |
mxjac | 1:c5edd3b18b79 | 58 | { |
mxjac | 4:45d466252fb6 | 59 | // Move_mouth(100); |
mxjac | 4:45d466252fb6 | 60 | // wait(0.01); |
mxjac | 1:c5edd3b18b79 | 61 | } |
mxjac | 1:c5edd3b18b79 | 62 | } |
mxjac | 1:c5edd3b18b79 | 63 | |
mxjac | 4:45d466252fb6 | 64 | //void Alex::Presence_too_far() |
mxjac | 1:c5edd3b18b79 | 65 | { |
mxjac | 4:45d466252fb6 | 66 | // pc.printf("You are too far, I can't see you !"); |
mxjac | 4:45d466252fb6 | 67 | // Simulate_Talking(4); |
mxjac | 4:45d466252fb6 | 68 | //wait(3); |
mxjac | 4:45d466252fb6 | 69 | // pc.printf("Is there somebody ?"); |
mxjac | 4:45d466252fb6 | 70 | // Simulate_Talking(4); |
mxjac | 4:45d466252fb6 | 71 | // wait(3); |
mxjac | 2:3920d79c79b1 | 72 | } |
mxjac | 4:45d466252fb6 | 73 | //void Alex::displaydistance() |
mxjac | 2:3920d79c79b1 | 74 | { |
mxjac | 4:45d466252fb6 | 75 | // pc.printf("Distance : %4i\r\n", S.read()); |
mxjac | 3:5271cc1a527b | 76 | } |
mxjac | 3:5271cc1a527b | 77 | |
mxjac | 4:45d466252fb6 | 78 | //void Alex::Presence_too_close() |
mxjac | 3:5271cc1a527b | 79 | { |
mxjac | 4:45d466252fb6 | 80 | //pc.printf("You are too close, please move back"); |
mxjac | 4:45d466252fb6 | 81 | //Simulate_Talking(4); |
mxjac | 4:45d466252fb6 | 82 | // wait(3); |
mxjac | 4:45d466252fb6 | 83 | }*/ |