Dependencies: mbed Motordriver QEI
Revision 0:993cd673f077, committed 2011-06-13
- Comitter:
- Keisuke_Fujii
- Date:
- Mon Jun 13 07:41:53 2011 +0000
- Child:
- 1:19d647492936
- Commit message:
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Motordriver.lib Mon Jun 13 07:41:53 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 Mon Jun 13 07:41:53 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 Mon Jun 13 07:41:53 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 Mon Jun 13 07:41:53 2011 +0000 @@ -0,0 +1,105 @@ +#include "include_file.h" + +int main( int argc, char **argv ) +{ + char key; + float d = 0.5; + 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"); + 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); + wait_ms( 10 ); + } +} + +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 Mon Jun 13 07:41:53 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912