Code with mutex and threads
Dependencies: C12832 Servo mbed-rtos-edited mbed
Fork of NervousPuppySprintOne by
nervousPuppy.h@8:921bd8c81549, 2015-02-26 (annotated)
- Committer:
- davidqpinho
- Date:
- Thu Feb 26 17:21:09 2015 +0000
- Revision:
- 8:921bd8c81549
- Parent:
- 6:f854aa2f41e2
Version 26.02
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 | 4:2b47356f4b7d | 4 | #include "C12832.h" |
SeanDoyle | 2:8415bea33a95 | 5 | #include <math.h> |
SeanDoyle | 2:8415bea33a95 | 6 | #include <string> |
SeanDoyle | 0:f71b200c2f4d | 7 | |
SeanDoyle | 0:f71b200c2f4d | 8 | #define Cos(a) cos(PI/180*(a)) |
SeanDoyle | 0:f71b200c2f4d | 9 | #define Sin(a) sin(PI/180*(a)) |
SeanDoyle | 0:f71b200c2f4d | 10 | #define PI 3.1415926 |
SeanDoyle | 0:f71b200c2f4d | 11 | |
davidqpinho | 8:921bd8c81549 | 12 | |
davidqpinho | 8:921bd8c81549 | 13 | Mutex s1_thread; |
davidqpinho | 8:921bd8c81549 | 14 | Mutex s2_thread; |
davidqpinho | 8:921bd8c81549 | 15 | Mutex lcdmutex_thread; |
davidqpinho | 8:921bd8c81549 | 16 | |
davidqpinho | 8:921bd8c81549 | 17 | float x,y; |
davidqpinho | 8:921bd8c81549 | 18 | |
SeanDoyle | 0:f71b200c2f4d | 19 | class nervousPuppy{ |
SeanDoyle | 0:f71b200c2f4d | 20 | public: |
SeanDoyle | 4:2b47356f4b7d | 21 | |
SeanDoyle | 0:f71b200c2f4d | 22 | nervousPuppy(); |
davidqpinho | 8:921bd8c81549 | 23 | |
SeanDoyle | 0:f71b200c2f4d | 24 | bool isLonely(); |
SeanDoyle | 0:f71b200c2f4d | 25 | bool isScared(); |
SeanDoyle | 2:8415bea33a95 | 26 | bool shutdown(); |
SeanDoyle | 0:f71b200c2f4d | 27 | |
SeanDoyle | 2:8415bea33a95 | 28 | void detectPlayer(); |
SeanDoyle | 0:f71b200c2f4d | 29 | float getPlayerDistance(); |
SeanDoyle | 1:8fe6802d6971 | 30 | void setPlayerDistance(float dist); |
SeanDoyle | 2:8415bea33a95 | 31 | |
SeanDoyle | 5:cbb5d7460309 | 32 | float calculateAngle(string issue); |
SeanDoyle | 2:8415bea33a95 | 33 | void changePosition(string servo,float angle); |
SeanDoyle | 2:8415bea33a95 | 34 | |
SeanDoyle | 0:f71b200c2f4d | 35 | private: |
SeanDoyle | 2:8415bea33a95 | 36 | |
SeanDoyle | 2:8415bea33a95 | 37 | Mutex lockForDistance; //Not sure why needed |
SeanDoyle | 2:8415bea33a95 | 38 | float playerDistance, playerError; |
SeanDoyle | 2:8415bea33a95 | 39 | bool scared, lonely; |
SeanDoyle | 6:f854aa2f41e2 | 40 | const float LONELY = 22.0f; //Placeholder number |
SeanDoyle | 6:f854aa2f41e2 | 41 | const float SCARED = 24.0f; //Placeholder number |
SeanDoyle | 5:cbb5d7460309 | 42 | const float RADIUS = 1.75f; //Placeholder number |
SeanDoyle | 4:2b47356f4b7d | 43 | const float SHUTDOWN = 0.0f; //Placeholder number |
SeanDoyle | 2:8415bea33a95 | 44 | const float PULSE_RATE = 10; //Placeholder number - Pulses per second |
SeanDoyle | 2:8415bea33a95 | 45 | const float SERVO_TILT_LIMIT = 45; //Placeholder number - max angle servo can tilt by |
SeanDoyle | 2:8415bea33a95 | 46 | const float SERVO_ROTATE_LIMIT = 45; //Placeholder number - max angle servo can rotate by |
SeanDoyle | 0:f71b200c2f4d | 47 | }; |