A simple robot that drives forward a set number of pulses at a set PWM speed.

Dependencies:   mbed Motor QEI

Files at this revision

API Documentation at this revision

Comitter:
aberk
Date:
Fri Sep 10 13:22:56 2010 +0000
Commit message:
Version 1.0

Changed in this revision

Motor.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
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
diff -r 000000000000 -r 7f8bf6df6c7b Motor.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.lib	Fri Sep 10 13:22:56 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/aberk/code/Motor/#c75b234558af
diff -r 000000000000 -r 7f8bf6df6c7b QEI.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QEI.lib	Fri Sep 10 13:22:56 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/aberk/code/QEI/#5c2ad81551aa
diff -r 000000000000 -r 7f8bf6df6c7b main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Sep 10 13:22:56 2010 +0000
@@ -0,0 +1,40 @@
+/**
+ * Drive a robot forwards or backwards by supplying a PWM signal to
+ * H-bridges connected to the motors.
+ */
+
+#include "Motor.h"
+#include "QEI.h"
+
+#define PULSES_PER_REVOLUTION 624
+
+Motor leftMotor(p21, p20, p19);  //pwm, inB, inA
+Motor rightMotor(p22, p17, p18); //pwm, inA, inB
+QEI leftQei(p29, p30, NC, 624);  //chanA, chanB, index, ppr
+QEI rightQei(p27, p28, NC, 624); //chanB, chanA, index, ppr
+
+int main() {
+    
+    leftMotor.period(0.00005);  //Set motor PWM periods to 20KHz.
+    rightMotor.period(0.00005);
+
+    int leftPulses  = 0;    //How far the left wheel has travelled.
+    int rightPulses = 0;    //How far the right wheel has travelled.
+    int distance    = 6000; //Number of pulses to travel.
+
+    wait(5); //Wait a few seconds before we start moving.
+    
+    leftMotor.speed(0.4);
+    rightMotor.speed(0.4);
+    
+    while((leftPulses < distance) || (rightPulses < distance)){
+    
+        leftPulses  = leftQei.getPulses();
+        rightPulses = rightQei.getPulses();
+        
+    }
+    
+    leftMotor.brake();
+    rightMotor.brake();
+
+}
diff -r 000000000000 -r 7f8bf6df6c7b mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Sep 10 13:22:56 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e