a simple library to control an animatronic head
Alex.cpp@2:3920d79c79b1, 2010-12-15 (annotated)
- Committer:
- mxjac
- Date:
- Wed Dec 15 15:39:53 2010 +0000
- Revision:
- 2:3920d79c79b1
- Parent:
- 1:c5edd3b18b79
- Child:
- 3:5271cc1a527b
display distance
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 | 1:c5edd3b18b79 | 54 | void Alex::Simulate_Talking(int length) |
mxjac | 1:c5edd3b18b79 | 55 | { |
mxjac | 1:c5edd3b18b79 | 56 | for(int i=0; i<length; i++) |
mxjac | 1:c5edd3b18b79 | 57 | { |
mxjac | 1:c5edd3b18b79 | 58 | Move_mouth(100); |
mxjac | 1:c5edd3b18b79 | 59 | wait(0.01); |
mxjac | 1:c5edd3b18b79 | 60 | } |
mxjac | 1:c5edd3b18b79 | 61 | } |
mxjac | 1:c5edd3b18b79 | 62 | |
mxjac | 1:c5edd3b18b79 | 63 | void Alex::Presence_too_far() |
mxjac | 1:c5edd3b18b79 | 64 | { |
mxjac | 1:c5edd3b18b79 | 65 | pc.printf("You are too far, I can't see you !"); |
mxjac | 1:c5edd3b18b79 | 66 | Simulate_Talking(4); |
mxjac | 1:c5edd3b18b79 | 67 | wait(3); |
mxjac | 1:c5edd3b18b79 | 68 | pc.printf("Is there somebody ?"); |
mxjac | 1:c5edd3b18b79 | 69 | Simulate_Talking(4); |
mxjac | 1:c5edd3b18b79 | 70 | wait(3); |
mxjac | 2:3920d79c79b1 | 71 | } |
mxjac | 2:3920d79c79b1 | 72 | void Alex::displaydistance() |
mxjac | 2:3920d79c79b1 | 73 | { |
mxjac | 2:3920d79c79b1 | 74 | pc.printf("Distance : %4i\r\n", S.read()); |
mxjac | 0:8474cbec06bd | 75 | } |