Fixed Sonar
Dependencies: C12832 Servo mbed-rtos-edited mbed
Fork of NervousPuppy by
Revision 4:2b47356f4b7d, committed 2015-01-15
- Comitter:
- SeanDoyle
- Date:
- Thu Jan 15 17:01:47 2015 +0000
- Parent:
- 3:74dfce05dd99
- Child:
- 5:cbb5d7460309
- Commit message:
- Sonar working;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/C12832.lib Thu Jan 15 17:01:47 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/chris/code/C12832/#7de323fa46fe
--- a/nervousPuppy.cpp Wed Jan 14 16:57:41 2015 +0000 +++ b/nervousPuppy.cpp Thu Jan 15 17:01:47 2015 +0000 @@ -3,27 +3,41 @@ /** * Constructor - contains running loop */ + +Servo tilt(p21); +Servo rotate(p22); +AnalogIn ain(p20); + +C12832 lcd(p5, p7, p6, p8, p11); + + nervousPuppy::nervousPuppy(){ bool isRunning = true; while(isRunning){ + playerDistance = ain.read(); + + lcd.cls(); + lcd.locate(0,3); + lcd.printf("%f",playerDistance); + if(shutdown()){//TurnOff - isRunning = !isRunning; + //isRunning = !isRunning; } else if(isScared()){//MoveBack scared = true; playerError = playerDistance - SCARED; - + lcd.printf(" TOO CLOSE"); + wait(2.0); if(calculateAngle("Vertical") != 0)changePosition("tilt",calculateAngle("Vertical")); else if(calculateAngle("Horizontal") != 0)changePosition("rotate",calculateAngle("Horizontal")); - else isRunning = false; - + scared = false; } else if(isLonely()){// MoveForward lonely = true; playerError = playerDistance - LONELY; - + lcd.printf(" TOO FAR"); + wait(2.0); if(calculateAngle("Vertical") !=0)changePosition("tilt",calculateAngle("Vertical")); else if(calculateAngle("Horizontal") != 0)changePosition("rotate",calculateAngle("Horizontal")); - else isRunning = false; lonely = false; } @@ -56,10 +70,12 @@ * Move 'puppy' to the calculated 'safe' point */ void nervousPuppy::changePosition(string servo,float angle){ - if(servo == "tilt"){} - else if(servo == "rotate"){} + if(servo == "tilt"){ + tilt.position(angle); + } else if(servo == "rotate"){ + rotate.position(angle); + } } - /** * Thread -> Running sonar to detect player */
--- a/nervousPuppy.h Wed Jan 14 16:57:41 2015 +0000 +++ b/nervousPuppy.h Thu Jan 15 17:01:47 2015 +0000 @@ -1,6 +1,7 @@ #include "mbed.h" #include "rtos.h" #include "Servo.h" +#include "C12832.h" #include <math.h> #include <string> @@ -10,6 +11,7 @@ class nervousPuppy{ public: + nervousPuppy(); bool isLonely(); @@ -24,16 +26,14 @@ void changePosition(string servo,float angle); private: - //Servo tilt(); - //Servo rotate(); Mutex lockForDistance; //Not sure why needed float playerDistance, playerError; bool scared, lonely; - const float LONELY = 10.0f; //Placeholder number - const float SCARED = 3.0f; //Placeholder number + const float LONELY = 0.10f; //Placeholder number + const float SCARED = 0.088f; //Placeholder number const float RADIUS = 2.0f; //Placeholder number - const float SHUTDOWN = 1.0f; //Placeholder number + const float SHUTDOWN = 0.0f; //Placeholder number const float PULSE_RATE = 10; //Placeholder number - Pulses per second const float SERVO_TILT_LIMIT = 45; //Placeholder number - max angle servo can tilt by const float SERVO_ROTATE_LIMIT = 45; //Placeholder number - max angle servo can rotate by