Basic tank-style drive robot control firmware for Freescale FRDM-K64F. Controls motors on a Dual-Full-H-Bridge with EN, like DBH-1x series, from Bluetooth serial commands

Dependencies:   mbed

Revision:
3:502f90649834
Parent:
2:54d27fdcbe5c
Child:
4:7620d21baef3
--- a/main.cpp	Sun Aug 02 18:34:12 2015 +0000
+++ b/main.cpp	Thu Aug 13 17:50:28 2015 +0000
@@ -37,18 +37,21 @@
 #include "Serial.h"
 //Serial CmdSerial(PTC17,PTC16);  // Command/Diagnostic serial port on UART3, sicne I don't know how to use USB ports (yet)
 Serial CmdSerial(PTC15,PTC14);  // Command/Diagnostic serial port on "bluetooth add-on" header
+Serial DiagSerial(USBTX, USBRX);
 
 // emulation of some Arduino serial methods.
 //    this class has a singleton interrupt callback, so it
 //    creates a singleton global
 #include "ASerial.h"  // emulation of some common Arduino Serial methods
 ASerial cSerial(CmdSerial); 
+//ASerial cSerial(DiagSerial); 
 
 // Set up motor drive for left and right motors
 #define DBH1   // use DBH-1x modifications to typicsl L298 drive logic
 #include "MotorDrive298.h"
-MotorDrive MotL(PTD1,PTD3,PTD2,PTB2);
-MotorDrive MotR(PTD0,PTC4,PTA0,PTB3);
+// en, in1, in2, ct
+MotorDrive MotL(PTD2,PTD3,PTD1,PTB2);
+MotorDrive MotR(PTC3,PTC4,PTD0,PTB3);
 
 #include "Command.h"
 
@@ -119,7 +122,8 @@
     CmdSerial.baud(57600);
     CmdSerial.puts("\r\nTankDrive for K64F with Bluetooth\r\n\n");
     CmdSerial.attach(&gotChar);  // singleton serial character buffer
-
+    DiagSerial.baud(115200);   DiagSerial.puts("TankDrive Diagnostics\r");
+    
     // Set motor drive parameters
     initMotorDrive(MotL);
     initMotorDrive(MotR);
@@ -140,17 +144,18 @@
         if (stat)
         {
             prevCommandTime = t;
-            if (nMsg>0){nMsg--;CmdSerial.printf(">%c%d\r\n",code,val);}
+            if (nMsg>0){nMsg--;DiagSerial.printf("\r\n\t\tcmd>%c%d\r\n",code,val);}
 
             switch(code)
             {
             case 'L': MotL.setSpeed(val/255.0,t); break;
             case 'R': MotR.setSpeed(val/255.0,t); break;
             default : 
-                CmdSerial.printf("Unidentified command \"%c%d\" (stop)",code,val);
+                DiagSerial.printf("Unidentified command \"%c%d\" (stop)",code,val);
                 MotL.stop();
                 MotR.stop();
             }
+
 //CmdSerial.puts("\nrcd\r");
 //CmdSerial.puts("\r\n");
 //detailMsg=2;
@@ -158,8 +163,8 @@
         }
         else
         { // no command, do housekeeping (misc state update stuff)
-            //MotL.update(t);
-            //MotR.update(t);
+            MotL.update(t);
+            MotR.update(t);
 
             if ((prevCommandTime > 0x0fffff00) && (t < 999))
             {  // time counter is close to wrapping around.  make sure this does not happen.
@@ -175,7 +180,7 @@
             if (t - tFlash > FLASH_DT)
             { // Flash standard LED to show things are running
                 tFlash = t;
-                CmdSerial.printf("dt=%d\r\n",t);
+                DiagSerial.printf("dt=%d\r",t);
                 toggleFlash();
                 //reportCurrent();
                 //wait(0.8f);