basic functions for inverted pendulum

Dependencies:   MMA8451Q-configurable MMA845x mbed

Revision:
2:342aa0ce937e
Parent:
1:d2f503ea9800
--- a/main.cpp	Thu Nov 19 02:13:23 2015 +0000
+++ b/main.cpp	Thu Nov 19 21:40:19 2015 +0000
@@ -11,8 +11,8 @@
 
 #define MMA8451_I2C_ADDRESS (0x1d<<1)
 
-//#define LOW_POWER
-#define DEBUG
+#define LOW_POWER
+//#define DEBUG
 
 int main(void)
 {
@@ -26,10 +26,9 @@
     float ctrl_mag = 0.00;          /* Magnitude of controller output U */
         
     float Kp = 2.5;
-    float Kd = 0.1;
+    float Kd = 0.2;
     
-    char c;
-    
+    char c;    
     uint8_t data = 0;
 
     PwmOut en(PTB7); // PWM for enable signal
@@ -45,14 +44,15 @@
 #endif    
     
 #ifdef DEBUG
-    for(int i=0; i<0x80; i++)
+    for(int i=0; i<0x50; i++)
     {                                //int addr, uint8_t * data, int len)
         acc.readRegs(i, &data, 1);
         printf("Reg 0x%02x: 0x%02x \r\n", i, data);
     }
+    c = getchar();
 #endif
 
-    c = getchar();
+    
 
     while (true) {
         
@@ -100,14 +100,18 @@
 #ifndef LOW_POWER
             rled = 1.0f - ctrl_mag; // make the red led proportional to the positive error signal
 #endif                 
- 
-        } else if (0 == ctrl_val) {
+        } 
+        
+        /*
+        else if (0 == ctrl_val) {
             m1 = 1;
             m2 = 1;             // lock the motors
 #ifndef LOW_POWER
             rled = 1.0f; // turn off both leds
 #endif                 
-        } else {
+        } 
+        */
+        else {
             m1 = 1;
             m2 = 0;
             //rled = 1.0f - ctrl_mag; // make the blue led proportional to the negative error signal