Driver for controlling Renishaw RenBuggy

Dependencies:   SevenSegmentDisplay DCMotorDrive mbed MotorController

Revision:
3:0dd99309381e
Parent:
2:4180acdfa77a
Child:
4:64d065d6d072
--- a/main.cpp	Tue Dec 24 11:07:02 2013 +0000
+++ b/main.cpp	Wed Jan 15 11:51:19 2014 +0000
@@ -7,8 +7,9 @@
 
 #include "mbed.h"
 #include "SevenSegmentDisplay.h"
+#include "MotorController.h"
 
-uint8_t ui8Tens = 0, ui8Units = 0;
+uint16_t u16LeftSpeed = 0, u16RightSpeed = 0;
 
 // Options to instantiate SevenSegmentDisplay are...
 // FADE: causes the number changes to fade in smoothly
@@ -16,35 +17,61 @@
 // + FLASH: causes the display to flash
 SevenSegmentDisplay segmentled( FADE );
 
+MotorController RenBuggy(p5, p7, p6, p8);
+DigitalIn LFast(p9), LSlow(p12), RFast(p15), RSlow(p18);
+
 void attimeout();            //declare prototype for timeout handler.
 
 Ticker timeout;             //Create an instance of class Ticker called timeout.
 
 int main()
 {
-    //segmentled.FlashRate(100); //Sets the flash rate to every 100ms
-    //segmentled.FadeMode(FADE + FLASH); //Changes display mode to fade with flash
-    //segmentled.FadeRate(10); // Sets the fade rate to 10ms intervals
+    LFast.mode(PullUp);
+    LSlow.mode(PullUp);
+    RFast.mode(PullUp);
+    RSlow.mode(PullUp);
 
-    // Set up interrupt to call attimeout() every half a second.
-    timeout.attach_us(&attimeout, 500000);
+    timeout.attach(&attimeout, 3);
+//    LeftMotor.SetMotorPwmAndRevolutions(18000,32);
 
-    for(;;) {} // Loop forever (the program uses interrupts)
+
+    for(;;) {
+    } // Loop forever (the program uses interrupts)
 }
 
 void attimeout()
 {
-    ui8Units ^= 0x80;
-    if ((ui8Units & 0x80) == 0) {
-        ui8Units++;             // "units"
-        if (ui8Units > 36) {    // cycle through entire range 0 -> 9, A -> Z
-            ui8Units = 0;       // Reset the "units" to 0
-            ui8Tens++;          // Increment "tens" digit
-            if (ui8Tens > 36) { // cycle through entire range 0 -> 9, A -> Z
-                ui8Tens = 0;    // Reset the "tens" to 0
-            }
-        }
+    int MotorConv = 0;
+    static int Flip = 0;
+    
+    if ((RFast == 0) && (u16RightSpeed < PWM_PERIOD * 1000))
+    {
+        u16RightSpeed += 15;
+//        RightMotor.SetMotorPwm(u16RightSpeed);
+    }
+    if ((RSlow == 0) && (u16RightSpeed > 0))
+    {
+        u16RightSpeed -= 15;
+//        RightMotor.SetMotorPwm(u16RightSpeed);
+    }
+    if ((LFast == 0) && (u16LeftSpeed < PWM_PERIOD * 1000))
+    {
+        u16LeftSpeed += 15;
+//        LeftMotor.SetMotorPwm(u16LeftSpeed);
+    }
+    if ((LSlow == 0) && (u16LeftSpeed > 0))
+    {
+        u16LeftSpeed -= 15;
+//        LeftMotor.SetMotorPwm(u16LeftSpeed);
     }
     // Updates display with new values.
-    segmentled.SevenSegmentDisplayChange(ui8Tens, ui8Units);
+    if (Flip++ == 0)
+        MotorConv = RenBuggy.LeftReadOdometer();
+    else
+    {
+        MotorConv = RenBuggy.RightReadOdometer();
+        Flip = 0;
+    }
+    //MotorConv = RenBuggy.LeftReadOdometer();
+    segmentled.DisplayInt(MotorConv);
 }
\ No newline at end of file