Merged to branch

Dependencies:   USBDevice mbed EquatorStrutController LightWeightSerialTransmit

Fork of EquatorStrutDigitalMonitor by Stewart Coulden-Smith

Files at this revision

API Documentation at this revision

Comitter:
alpesh
Date:
Mon Aug 11 09:08:39 2014 +0000
Parent:
6:bfe745b152fa
Child:
8:7f6e81140f27
Commit message:
hkj

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Aug 07 09:19:16 2014 +0000
+++ b/main.cpp	Mon Aug 11 09:08:39 2014 +0000
@@ -137,7 +137,7 @@
     Homing = true;
     HallTriggered = false;
     
-    SetPower(-0.5);
+    SetPower(-0.7);
     
     while (!HallTriggered)
     {
@@ -446,13 +446,13 @@
     RGHCosInterrupt.enable_irq();
 }
 
-double TargetSpeed=50.0; //Millimeter per second
+double SetPoint = 50.0; //Millimeter per second
 
 double KpTerm;
 double ErrorInt;
 double ErrorDer;
 
-double KpGain = 0.000009;
+double KpGain = 0.0;
 double KiGain = 0.0;
 double KdGain = 0.0;
 
@@ -468,12 +468,12 @@
 
 void Controller ()
     {
-         if (GetSpeed() <= TargetSpeed)
+         if (position <= SetPoint || 1)
             {
                 int timeStep = RunningTime.read_us() - previousTime;
                 previousTime = RunningTime.read_us();
             
-                Error = TargetSpeed - GetSpeed();
+                Error = SetPoint - position;
         
                 KpTerm = Error * KpGain;
         
@@ -481,9 +481,7 @@
         
                 ErrorInt = ErrorInt + Error * timeStep;
         
-                PwmChange = (KpTerm + KiGain * ErrorInt + KdGain * ErrorDer);
-        
-                NewPwm = pwm + PwmChange;
+                NewPwm = (KpTerm + KiGain * ErrorInt + KdGain * ErrorDer);
         
                 if (NewPwm > 1.0) 
                 {
@@ -513,7 +511,6 @@
             }
     }
 
-
 int main()
 
 {
@@ -536,13 +533,56 @@
 
     while(Enabled)
     {
-        while(position < 200)
+        double pow = 0.0;
+        for (int i = 0; i < 10; i++)
         {
-            SerialTransmit();
+            //KpGain += 0.1;
+            float iterationStart = RunningTime.read();
+            
+            pow += 0.05;
+            
+            //while(RunningTime.read()-iterationStart < 10.0)
+            //{
+            //    SerialTransmit();
+                
+            //    Controller();
+            //}
             
-            Controller();
+            while(RunningTime.read() - iterationStart < 30.0 && position < 210.0)
+            {
+                SerialTransmit();
+                SetPower(pow);
+            }
+            
+            iterationStart = RunningTime.read();
+            
+            while(RunningTime.read() - iterationStart < 30.0 && position > 10.0)
+            {
+                SerialTransmit();
+                SetPower(-pow);
+            }
+            
+            Home();
         }
         
         Disable();
     }
-}
\ No newline at end of file
+}
+
+/* Change this throttle value range to 1.0 and 0.0 for car speed
+m_throttlechange = (m_kpGain * m_error + m_kdGain * m_ErrorDer + m_ErrorInt);
+
+            double throttle = m_throttle + m_throttlechange;
+
+            if (new_throttle > 1.0) {
+                m_throttle = 1.0;
+            } else if (new_throttle < 0.0) {
+                m_throttle = 0.0;
+            } else {
+                m_throttle = new_throttle;
+            }*/
+
+
+
+
+