Goal: Simulate the reactions of a nervous / lonely puppy using servo's + the mbed LPC1768.
Dependencies: mbed-rtos-edited mbed Servo C12832
nervousPuppy.h@2:8415bea33a95, 2015-01-13 (annotated)
- Committer:
- SeanDoyle
- Date:
- Tue Jan 13 16:08:22 2015 +0000
- Revision:
- 2:8415bea33a95
- Parent:
- 1:8fe6802d6971
- Child:
- 3:74dfce05dd99
Implemented some logic for changing position.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SeanDoyle | 0:f71b200c2f4d | 1 | #include "mbed.h" |
SeanDoyle | 2:8415bea33a95 | 2 | #include "rtos.h" |
SeanDoyle | 2:8415bea33a95 | 3 | #include "Servo.h" |
SeanDoyle | 2:8415bea33a95 | 4 | #include <math.h> |
SeanDoyle | 2:8415bea33a95 | 5 | #include <string> |
SeanDoyle | 0:f71b200c2f4d | 6 | |
SeanDoyle | 0:f71b200c2f4d | 7 | #define Cos(a) cos(PI/180*(a)) |
SeanDoyle | 0:f71b200c2f4d | 8 | #define Sin(a) sin(PI/180*(a)) |
SeanDoyle | 0:f71b200c2f4d | 9 | #define PI 3.1415926 |
SeanDoyle | 0:f71b200c2f4d | 10 | |
SeanDoyle | 0:f71b200c2f4d | 11 | class nervousPuppy{ |
SeanDoyle | 0:f71b200c2f4d | 12 | public: |
SeanDoyle | 0:f71b200c2f4d | 13 | nervousPuppy(); |
SeanDoyle | 0:f71b200c2f4d | 14 | |
SeanDoyle | 0:f71b200c2f4d | 15 | bool isLonely(); |
SeanDoyle | 0:f71b200c2f4d | 16 | bool isScared(); |
SeanDoyle | 2:8415bea33a95 | 17 | bool shutdown(); |
SeanDoyle | 0:f71b200c2f4d | 18 | |
SeanDoyle | 2:8415bea33a95 | 19 | void detectPlayer(); |
SeanDoyle | 0:f71b200c2f4d | 20 | float getPlayerDistance(); |
SeanDoyle | 1:8fe6802d6971 | 21 | void setPlayerDistance(float dist); |
SeanDoyle | 2:8415bea33a95 | 22 | |
SeanDoyle | 2:8415bea33a95 | 23 | float calculateVerticalAdjustment(); |
SeanDoyle | 2:8415bea33a95 | 24 | float calculateHorizontalAdjustment(); |
SeanDoyle | 2:8415bea33a95 | 25 | float calculateAngle(string axis); |
SeanDoyle | 2:8415bea33a95 | 26 | void changePosition(string servo,float angle); |
SeanDoyle | 2:8415bea33a95 | 27 | |
SeanDoyle | 0:f71b200c2f4d | 28 | private: |
SeanDoyle | 2:8415bea33a95 | 29 | //Servo tilt(); |
SeanDoyle | 2:8415bea33a95 | 30 | //Servo rotate(); |
SeanDoyle | 2:8415bea33a95 | 31 | |
SeanDoyle | 2:8415bea33a95 | 32 | Mutex lockForDistance; //Not sure why needed |
SeanDoyle | 2:8415bea33a95 | 33 | float playerDistance, playerError; |
SeanDoyle | 2:8415bea33a95 | 34 | bool scared, lonely; |
SeanDoyle | 2:8415bea33a95 | 35 | const float LONELY = 10.0f; //Placeholder number |
SeanDoyle | 2:8415bea33a95 | 36 | const float SCARED = 3.0f; //Placeholder number |
SeanDoyle | 2:8415bea33a95 | 37 | const float RADIUS = 2.0f; //Placeholder number |
SeanDoyle | 2:8415bea33a95 | 38 | const float SHUTDOWN = 1.0f; //Placeholder number |
SeanDoyle | 2:8415bea33a95 | 39 | const float PULSE_RATE = 10; //Placeholder number - Pulses per second |
SeanDoyle | 2:8415bea33a95 | 40 | const float SERVO_TILT_LIMIT = 45; //Placeholder number - max angle servo can tilt by |
SeanDoyle | 2:8415bea33a95 | 41 | const float SERVO_ROTATE_LIMIT = 45; //Placeholder number - max angle servo can rotate by |
SeanDoyle | 0:f71b200c2f4d | 42 | }; |