This is the code we showed at Uncraftivism

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
jarkman
Date:
Thu Dec 10 21:16:57 2009 +0000
Parent:
0:57f4fdadc97f
Child:
2:01115080f6da
Commit message:

Changed in this revision

MotionFinder.cpp Show annotated file Show diff for this revision Revisions of this file
ServoMinder.cpp Show annotated file Show diff for this revision Revisions of this file
ServoMinder.h Show annotated file Show diff for this revision Revisions of this file
ucam.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/MotionFinder.cpp	Fri Nov 20 14:40:48 2009 +0000
+++ b/MotionFinder.cpp	Thu Dec 10 21:16:57 2009 +0000
@@ -27,6 +27,9 @@
     m_xServoMinder = xServoMinder;
     m_yServoMinder = yServoMinder;
     
+   
+    
+
     m_xServoMinder->moveTo( 1.0 );
     wait( 1 );
     m_xServoMinder->moveTo( 0.0 );
@@ -34,6 +37,7 @@
     m_xServoMinder->moveTo( 0.5 );
     wait( 1 );
 
+    
     m_yServoMinder->moveTo( 1.0 );
     wait( 1 );
     m_yServoMinder->moveTo( 0.0 );
@@ -65,7 +69,7 @@
     if( frame == NULL || frame->m_bad )
     {
         if( m_resultFrame != NULL )
-			m_resultFrame->m_bad = false;
+            m_resultFrame->m_bad = false;
         return;
     }
 
@@ -164,7 +168,7 @@
     }
 
     m_xServoMinder->moveTo( 1 - m_attentionX );
-    m_yServoMinder->moveTo( 1 - m_attentionY ); 
+    m_yServoMinder->moveTo(  m_attentionY ); 
 
 
     Frame::releaseFrame( &frame );
--- a/ServoMinder.cpp	Fri Nov 20 14:40:48 2009 +0000
+++ b/ServoMinder.cpp	Thu Dec 10 21:16:57 2009 +0000
@@ -19,9 +19,19 @@
     m_ticker.attach( this, &ServoMinder::tick, m_tickTime );
 }
 
+void ServoMinder::moveToAndWait( float target )
+{
+    moveTo( target );
+    
+    while( fabs( m_servo->read() - m_target) > m_delta )
+       wait( 0.001 ) ;
+ }
+        
 void ServoMinder::moveTo( float target )
 {
+
     m_target = target;
+
     
     
 }
--- a/ServoMinder.h	Fri Nov 20 14:40:48 2009 +0000
+++ b/ServoMinder.h	Thu Dec 10 21:16:57 2009 +0000
@@ -4,21 +4,23 @@
 class ServoMinder
 {
 public:
-	ServoMinder( Servo *servo );
+    ServoMinder( Servo *servo );
 
-	void moveTo( float target );
-
+    void moveTo( float target );
+    void moveToAndWait( float target );
+     void setSpeed( float speed );
+     
 private:
-	void setSpeed( float speed );
+   
 
-	Servo *m_servo;
-	float m_target;
-	float m_speed;
+    Servo *m_servo;
+    float m_target;
+    float m_speed;
 
-	float m_delta;
-	float m_tickTime;
-	Ticker m_ticker;
+    float m_delta;
+    float m_tickTime;
+    Ticker m_ticker;
 
-	void tick();
+    void tick();
 
 };
\ No newline at end of file
--- a/ucam.cpp	Fri Nov 20 14:40:48 2009 +0000
+++ b/ucam.cpp	Thu Dec 10 21:16:57 2009 +0000
@@ -31,19 +31,42 @@
 
 Servo xServo (p21);
 Servo yServo (p22);
+Servo eyelidServo (p23); 
+#define EYE_CLOSED 0.15
+#define EYE_OPEN 0.8 
 
 MotionFinder *motionFinder = NULL;
 
 
+void testEyelid()
+{
+ ServoMinder *eyelidMinder = new ServoMinder( &eyelidServo );
 
+    eyelidMinder->setSpeed( 1 );
+      eyelidMinder->moveToAndWait( EYE_CLOSED );
+  
+      eyelidMinder->setSpeed( 0.1 );
+      eyelidMinder->moveToAndWait( EYE_OPEN );
+      eyelidMinder->setSpeed( 2 );
+      eyelidMinder->moveToAndWait( EYE_CLOSED );
+      eyelidMinder->moveToAndWait( EYE_OPEN );
+}
+      
 void UCamInit() {
    
+    
+      
     ucam.doStartup();
     Frame::initFrames();
+    
+     
+    testEyelid();
+  
     motionFinder = new MotionFinder( new ServoMinder(&xServo), new ServoMinder(&yServo) );
     
 }
 
+
 void UCamGetJpeg()
 {
     ucam.doConfig( false, UCAM_COLOUR_JPEG, UCAM_JPEG_SIZE_640x480 ); 
@@ -58,6 +81,7 @@
 }
 
 Frame* UCamGetRaw( )
+
 {
     ucam.doConfig( true, UCAM_COLOUR_4_BIT_GREY, UCAM_RAW_SIZE_80x60);