Aaron Birenboim / Mbed 2 deprecated TankDrive Featured

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Mr_What
Date:
Sun Aug 16 22:46:25 2015 +0000
Parent:
3:502f90649834
Commit message:
seems to be running from app with reduced diagnostics

Changed in this revision

ASerial.h Show annotated file Show diff for this revision Revisions of this file
Command.h Show annotated file Show diff for this revision Revisions of this file
MotorDrive298.h 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
diff -r 502f90649834 -r 7620d21baef3 ASerial.h
--- a/ASerial.h	Thu Aug 13 17:50:28 2015 +0000
+++ b/ASerial.h	Sun Aug 16 22:46:25 2015 +0000
@@ -13,7 +13,7 @@
 #define EOLN "\r\n"
 
 // singleton serial command byte buffer
-#define CMDBUFLEN 16
+#define CMDBUFLEN 64
 int cbuf[CMDBUFLEN];
 static int bufIn=0;
 static int bufOut=0;
@@ -27,9 +27,9 @@
     //              decrements before bufIn, one hopes that the glitch will not be problematic.
     //       indication of char in the buffer remains correce, and one hopes that by the next
     //       time they check, both counts are accurate.
-    if (bufIn > 1001*CMDBUFLEN) {
-        bufOut -= 1000*CMDBUFLEN;
-        bufIn  -= 1000*CMDBUFLEN;
+    if (bufIn > 401*CMDBUFLEN) {
+        bufOut -= 400*CMDBUFLEN;
+        bufIn  -= 400*CMDBUFLEN;
     }    
 }
 
@@ -70,12 +70,13 @@
         if(bufOut < bufIn) {
             int c = cbuf[bufOut % CMDBUFLEN];
             bufOut++;
-            DiagSerial.printf("\r\n\t%d got %d(%c)\r\n",bufOut-1,c,c);
+            //DiagSerial.printf("\r\n\t%d got %d(%c)\r\n",bufOut-1,c,c);
             
             
             int n = bufIn-bufOut;
             if ((n > CMDBUFLEN-3) && (n < 800*CMDBUFLEN)) {
-                _serial->printf("\t\r\tCommand Buffer Overflow Warning!\r\n");   
+                DiagSerial.printf("\t\r\tCommand Buffer Overflow RESET!\r\n");
+                bufIn=bufOut=0;   
             }
             return(c);
         } else { return(-1); }
diff -r 502f90649834 -r 7620d21baef3 Command.h
--- a/Command.h	Thu Aug 13 17:50:28 2015 +0000
+++ b/Command.h	Sun Aug 16 22:46:25 2015 +0000
@@ -31,7 +31,7 @@
     int i = cSerial.cread();
     if (i < 0) return(false);  // no command yet
     char c = i;
-static int nc=0;DiagSerial.printf("%d got %d(%c)\r\n",nc++,i,i);
+//static int nc=0;DiagSerial.printf("%d got %d(%c)\r\n",nc++,i,i);
 //Serial.print('[');Serial.print(i);Serial.print(',');Serial.print(c);Serial.println(']');
     switch(c)
       {
diff -r 502f90649834 -r 7620d21baef3 MotorDrive298.h
--- a/MotorDrive298.h	Thu Aug 13 17:50:28 2015 +0000
+++ b/MotorDrive298.h	Sun Aug 16 22:46:25 2015 +0000
@@ -117,10 +117,10 @@
   MotorDrive (PinName namEN, PinName namIN1, PinName namIN2, PinName namCS) :
        IN1(namIN1),
        IN2(namIN2),
+#ifdef DBH1
+       CS(namCS),
+#endif
        EN(namEN)
-#ifdef DBH1
-       ,CS(namCS)
-#endif
   {
       EN.write(0.0f);
       IN2.write(0.0f);
@@ -153,10 +153,10 @@
     //BYTE EN;        // enable pin
     //SHORT _speed;     // current speed
     //SHORT _speedCmd;  // commanded speed
-    CmdSerial.printf("Decel %d ms from ful speed\r\n",_decel);
+    DiagSerial.printf("Decel %d ms from ful speed\r\n",_decel);
     //BYTE _mode;
     //unsigned long _doneTime;  // time when mode automatically transitions
-    CmdSerial.printf("Deadman Timeout %d ms\r\n",_deadTime);
+    DiagSerial.printf("Deadman Timeout %d ms\r\n",_deadTime);
   //SHORT _maxPWM;      // clip PWM commands to this magnitude
   //SHORT _startupTime; // ms of full-power pulse to start from dead stop
   //SHORT _stopTime;    // ms to lock-out commands after emergency stop
@@ -179,7 +179,7 @@
 
   virtual void emergencyStop()
   {
-    CmdSerial.puts("Emergency ");
+    DiagSerial.puts("Emergency ");
     _msgCount = 11;  // turn on diagnostics for a few commands
     stop();
     _speedCmd=0;
@@ -259,7 +259,7 @@
             _doneTime = t + _deadTime;
             setReverse(_mode == MOTOR_REV);  // make sure direction is correct
             EN.write(getPWM(_speedCmd));           // analogWrite(Pin.EN,getPWM(_speedCmd));
-            if(_msgCount>0){_msgCount--;CmdSerial.printf("Started %.3f\r\n",_speedCmd);}
+            if(_msgCount>0){_msgCount--;DiagSerial.printf("Started %.3f\r\n",_speedCmd);}
           }
         return;
       }
diff -r 502f90649834 -r 7620d21baef3 main.cpp
--- a/main.cpp	Thu Aug 13 17:50:28 2015 +0000
+++ b/main.cpp	Sun Aug 16 22:46:25 2015 +0000
@@ -97,7 +97,7 @@
   float cr, cl;
   cr = MotR.getCurrent();
   cl = MotL.getCurrent();
-  CmdSerial.printf("\tCurrent:  left=%.3f  right=%.3f\r\n",cl,cr);
+  DiagSerial.printf("\tCurrent:  left=%.3f  right=%.3f\r\n",cl,cr);
 }
 
 //void dumpSerialChar()
@@ -119,10 +119,12 @@
 
 int main()
 {
+    DiagSerial.baud(115200);   DiagSerial.puts("TankDrive Diagnostics\r");
+
+    // have been getting lock-ups when running app.  could 57600 be too fast for BT UART on K64F?
     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);