basic functions for inverted pendulum

Dependencies:   MMA8451Q-configurable MMA845x mbed

Files at this revision

API Documentation at this revision

Comitter:
angusg
Date:
Thu Nov 19 21:40:19 2015 +0000
Parent:
1:d2f503ea9800
Commit message:
kl05 pendulum

Changed in this revision

MMA8451Q.lib 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
--- a/MMA8451Q.lib	Thu Nov 19 02:13:23 2015 +0000
+++ b/MMA8451Q.lib	Thu Nov 19 21:40:19 2015 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/angusg/code/MMA8451Q-configurable/#4e7dd6eb7829
+https://developer.mbed.org/users/angusg/code/MMA8451Q-configurable/#aca483d0fa8d
--- 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