Fixed Sonar

Dependencies:   C12832 Servo mbed-rtos-edited mbed

Fork of NervousPuppy by Sean Doyle

Committer:
SeanDoyle
Date:
Wed Jan 14 16:57:41 2015 +0000
Revision:
3:74dfce05dd99
Parent:
2:8415bea33a95
Child:
4:2b47356f4b7d
Tidied code, fixed issue for no optimal angle

Who changed what in which revision?

UserRevisionLine numberNew 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 calculateAngle(string axis);
SeanDoyle 2:8415bea33a95 24 void changePosition(string servo,float angle);
SeanDoyle 2:8415bea33a95 25
SeanDoyle 0:f71b200c2f4d 26 private:
SeanDoyle 2:8415bea33a95 27 //Servo tilt();
SeanDoyle 2:8415bea33a95 28 //Servo rotate();
SeanDoyle 2:8415bea33a95 29
SeanDoyle 2:8415bea33a95 30 Mutex lockForDistance; //Not sure why needed
SeanDoyle 2:8415bea33a95 31 float playerDistance, playerError;
SeanDoyle 2:8415bea33a95 32 bool scared, lonely;
SeanDoyle 2:8415bea33a95 33 const float LONELY = 10.0f; //Placeholder number
SeanDoyle 2:8415bea33a95 34 const float SCARED = 3.0f; //Placeholder number
SeanDoyle 2:8415bea33a95 35 const float RADIUS = 2.0f; //Placeholder number
SeanDoyle 2:8415bea33a95 36 const float SHUTDOWN = 1.0f; //Placeholder number
SeanDoyle 2:8415bea33a95 37 const float PULSE_RATE = 10; //Placeholder number - Pulses per second
SeanDoyle 2:8415bea33a95 38 const float SERVO_TILT_LIMIT = 45; //Placeholder number - max angle servo can tilt by
SeanDoyle 2:8415bea33a95 39 const float SERVO_ROTATE_LIMIT = 45; //Placeholder number - max angle servo can rotate by
SeanDoyle 0:f71b200c2f4d 40 };