David's dead reckoning code for the LVBots competition on March 6th. Uses the mbed LPC1768, DRV8835, QTR-3RC, and two DC motors with encoders.

Dependencies:   PololuEncoder Pacer mbed GeneralDebouncer

Files at this revision

API Documentation at this revision

Comitter:
DavidEGrayson
Date:
Thu Feb 20 22:24:32 2014 +0000
Parent:
2:968338353aef
Child:
4:1b20a11765c8
Commit message:
Done working on encoder stuff for now.;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Feb 20 20:09:40 2014 +0000
+++ b/main.cpp	Thu Feb 20 22:24:32 2014 +0000
@@ -7,12 +7,16 @@
 Serial pc(USBTX, USBRX);
 
 #define ENCODER1 0x00
+#define ENCODER2 0x01
 
 const PinName encoderPin1A = p6,
-              encoderPin1B = p7;
+              encoderPin1B = p7,
+              encoderPin2A = p8,
+              encoderPin2B = p9;
 
 PololuEncoderBuffer encoderBuffer;
 PololuEncoder encoder1(encoderPin1A, encoderPin1B, &encoderBuffer, ENCODER1);
+PololuEncoder encoder2(encoderPin2A, encoderPin2B, &encoderBuffer, ENCODER2);
 
 int main()
 {
@@ -21,24 +25,40 @@
     // Enable pull-ups on encoder pins and give them a chance to settle.
     DigitalIn(encoderPin1A).mode(PullUp);
     DigitalIn(encoderPin1B).mode(PullUp);
+    DigitalIn(encoderPin2A).mode(PullUp);
+    DigitalIn(encoderPin2B).mode(PullUp);
     wait_us(50);
     encoder1.init();
+    encoder2.init();
 
     Pacer reportPacer(250000);
     Pacer blinkPacer(200000);
-    uint32_t eventCount = 0;    
+    uint32_t eventCount = 0;
+    uint32_t count = 0;
     while(1) {
         while(encoderBuffer.hasEvents())
         {
             PololuEncoderEvent event = encoderBuffer.readEvent();
             eventCount += 1;
+            if (event == POLOLU_ENCODER_EVENT_ERR | ENCODER1)
+            {
+                pc.puts("error\n");   
+            }
+            else if (event == POLOLU_ENCODER_EVENT_INC | ENCODER1)
+            {
+                count += 1;   
+            }
+            else if (event == POLOLU_ENCODER_EVENT_DEC | ENCODER1)
+            {
+                count -= 1;
+            }
         }
         
         if(reportPacer.pace())
         {
             led2 = 1;
             char str[80];
-            sprintf(str, "%8x %8x\n", encoder1.getCount(), eventCount);
+            sprintf(str, "%8x %8x %8x\n", encoder1.getCount(), count, eventCount);
             pc.puts(str);
             led2 = 0;
         }