Richard Sewell
/
ucam
This is the code we showed at Uncraftivism
Diff: MotionFinder.cpp
- Revision:
- 2:01115080f6da
- Parent:
- 1:70d90598d2e7
--- a/MotionFinder.cpp Thu Dec 10 21:16:57 2009 +0000 +++ b/MotionFinder.cpp Mon Dec 14 08:28:21 2009 +0000 @@ -7,10 +7,12 @@ #include "ServoMinder.h" +#include "Blinker.h" extern Logger pcSerial; +extern Blinker *blinker; // Motion detection for the mbed @@ -29,7 +31,7 @@ - +/* m_xServoMinder->moveTo( 1.0 ); wait( 1 ); m_xServoMinder->moveTo( 0.0 ); @@ -38,12 +40,13 @@ wait( 1 ); - m_yServoMinder->moveTo( 1.0 ); + m_yServoMinder->moveTo( 0.7 ); wait( 1 ); m_yServoMinder->moveTo( 0.0 ); - wait( 1 ); + wait( 2 ); m_yServoMinder->moveTo( 0.5 ); - wait( 1 ); + wait( 2 ); + */ } @@ -151,18 +154,36 @@ if( percentage < 3 ) // no real target, no COG { pcSerial.printf("No COG\r\n"); + + m_xServoMinder->setSpeed( 0.02 ); + m_yServoMinder->setSpeed( 0.02 ); + + blinker->setBoredom( 1 ); + m_attentionX = m_attentionX + (((0.5 - m_attentionX))/20); + m_attentionY = m_attentionY + (((0.7 - m_attentionY))/20); // could implement some looking-around in this state + + } else if( sumN > 0 ) { + m_xServoMinder->setSpeed( 0.25 ); + m_yServoMinder->setSpeed( 0.25 ); + cogX = sumX / sumN; cogY = sumY / sumN; m_attentionX = ((float)cogX / frame->m_width); m_attentionY = ((float)cogY / frame->m_width); // use the larger dimension so x & y get the same scaling + //blinker->setBoredom( 0 ); + float boredom = (2*percentage)/100.0; + if(boredom > 1) boredom = 1; + blinker->setBoredom( boredom ); + + pcSerial.printf("COG is %d, %d\r\n", (int) cogX, (int) cogY); }