Files at this revision

API Documentation at this revision

Comitter:
kagyroy
Date:
Sat Dec 10 10:58:29 2011 +0000
Child:
1:0a67babd7786
Commit message:

Changed in this revision

Motordriver.lib Show annotated file Show diff for this revision Revisions of this file
QEI.lib Show annotated file Show diff for this revision Revisions of this file
include_file.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motordriver.lib	Sat Dec 10 10:58:29 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/littlexc/code/Motordriver/#3110b9209d3c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QEI.lib	Sat Dec 10 10:58:29 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/aberk/code/QEI/#5c2ad81551aa
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include_file.h	Sat Dec 10 10:58:29 2011 +0000
@@ -0,0 +1,20 @@
+#include "mbed.h"
+#include "QEI.h"
+
+//Serial  device( USBTX, USBRX );
+Serial  device( p28, p27 );
+QEI enco_right(  p5,  p6,  NC, 6 , QEI :: X4_ENCODING );
+QEI  enco_left( p17, p18,  NC, 6 , QEI :: X4_ENCODING );
+PwmOut   right_pwm( p22 );
+DigitalOut right_P( p7 );
+DigitalOut right_N( p8 );
+PwmOut    left_pwm( p21 );
+DigitalOut  left_P( p15 );
+DigitalOut  left_N( p16 );
+DigitalOut  enable( p19 );
+
+void move_f( float );
+void move_b( float );
+void turn_r( float );
+void turn_l( float );
+void   stop( void );
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Dec 10 10:58:29 2011 +0000
@@ -0,0 +1,173 @@
+#include "include_file.h"
+
+int main( int argc, char **argv )
+{
+    char key;
+    float d = 0.5;
+    int width,height,color;
+    
+    device.baud( 115200 );
+    right_pwm.period_us( 10 );
+    left_pwm.period_us( 10 );
+    enable.write( 1 );
+    
+  //  device.putc('s');$$$
+    
+    device.printf("f:forward, b:back, r:turn_right\n"
+                  "l:turn_left, a:duty+=0.01, m:duty-=0.01\n");
+                  
+    width = 0;
+    
+    
+    
+    
+    
+    
+ //testing area 
+wait( 5 );
+
+//   while( 1 )
+//   {
+       ++width;
+       device.printf("%d\n",width);
+       if(width==255) width = 0;
+       wait_ms( 50 );
+//   }
+ 
+ 
+   int frame[200][200][3];
+
+   for(int i=0; i<200; i++)
+   {
+       for(int j=0; j<200; j++)
+       {
+           frame[i][j][0] = 100;
+           frame[i][j][1] = 100;
+           frame[i][j][2] = 100;
+       }
+   }    
+ 
+    while(1)
+    {       
+       for(int i=0; i<200; i++)
+       {
+           for(int j=0; j<200; j++)
+           {
+               device.printf("%d\n",frame[i][j][0]);
+
+               wait_ms( 50 );
+           }
+       }
+    }
+
+   
+
+   
+   
+/*
+   device.printf("s");  //start chara
+   for(int i=0; i<200; i++)
+   {
+       for(int j=0; j<200; j++)
+       {
+            device.printf("%d\n",frame[i][j][0]);
+       }
+       device.printf("h");  //horizontal transition
+   }
+   device.printf("e");  //vertical end
+ */  
+ //testing area       
+
+  
+  while(1)
+  {
+        key = device.getc();
+        switch( key )
+        {
+            case 'f':
+                move_f( d );
+                break;
+            case 'b':
+                move_b( d );
+                break;
+            case 'r':
+                turn_r( d );
+                break;
+            case 'l':
+                turn_l( d );
+                break;
+            case 's':
+                stop();
+                break;
+            case 'a':
+                d += 0.01;
+                break;
+            case 'm':
+                d -= 0.01;
+                break;
+            default:
+                break;
+        }
+       
+//        device.printf("duty = %1.2f\r", d);
+        
+    }   
+}
+
+void move_f( float d )
+{
+    right_P.write( 0 );
+    right_N.write( 1 );
+    left_P.write( 1 );
+    left_N.write( 0 );
+    right_pwm.write( d );
+    left_pwm.write( d );
+    /*right_pwm.pulsewidth_us( d );
+    left_pwm.pulsewidth_us( d );*/
+}
+
+void move_b( float d )
+{
+    right_P.write( 1 );
+    right_N.write( 0 );
+    left_P.write( 0 );
+    left_N.write( 1 );
+    right_pwm.write( d );
+    left_pwm.write( d );
+    /*right_pwm.pulsewidth_us( d );
+    left_pwm.pulsewidth_us( d );*/
+}
+
+void turn_r( float d )
+{
+    right_P.write( 0 );
+    right_N.write( 1 );
+    left_P.write( 0 );
+    left_N.write( 1 );
+    right_pwm.write( d );
+    left_pwm.write( d );
+    /*right_pwm.pulsewidth_us( d );
+    left_pwm.pulsewidth_us( d );*/
+}
+
+void turn_l( float d )
+{
+    right_P.write( 1 );
+    right_N.write( 0 );
+    left_P.write( 1 );
+    left_N.write( 0 );
+    right_pwm.write( d );
+    left_pwm.write( d );
+    /*right_pwm.pulsewidth_us( d );
+    left_pwm.pulsewidth_us( d );*/
+}
+
+void stop( void )
+{
+    right_P.write( 0 );
+    right_N.write( 0 );
+    left_P.write( 0 );
+    left_N.write( 0 );
+    right_pwm.write( 0 );
+    left_pwm.write( 0 );
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Dec 10 10:58:29 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912