Goal: Simulate the reactions of a nervous / lonely puppy using servo's + the mbed LPC1768.
Dependencies: mbed-rtos-edited mbed Servo C12832
Diff: nervousPuppy.cpp
- Revision:
- 3:74dfce05dd99
- Parent:
- 2:8415bea33a95
- Child:
- 4:2b47356f4b7d
--- a/nervousPuppy.cpp Tue Jan 13 16:08:22 2015 +0000 +++ b/nervousPuppy.cpp Wed Jan 14 16:57:41 2015 +0000 @@ -12,35 +12,25 @@ scared = true; playerError = playerDistance - SCARED; - if(calculateVerticalAdjustment() != 0)changePosition("tilt",calculateVerticalAdjustment()); - else changePosition("rotate",calculateHorizontalAdjustment()); + 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; - if(calculateVerticalAdjustment() !=0)changePosition("tilt",calculateVerticalAdjustment()); - else changePosition("rotate",calculateHorizontalAdjustment()); + if(calculateAngle("Vertical") !=0)changePosition("tilt",calculateAngle("Vertical")); + else if(calculateAngle("Horizontal") != 0)changePosition("rotate",calculateAngle("Horizontal")); + else isRunning = false; + lonely = false; } } } /** - * Returns the vertical adjustment - */ -float nervousPuppy::calculateVerticalAdjustment(){ - return calculateAngle("Vertical"); -} - -/** - * Returns the horizontal adjustment - */ -float nervousPuppy::calculateHorizontalAdjustment(){ - return calculateAngle("Horizontal"); -} - -/** * Calculates the angle required to bring the 'puppy' to a 'safe distance' * Returns 0 if it cannot find a 'safe distance' */