changes to motor library

Dependents:   pid-car-example

Fork of motor by Lawrence Harlow

Branch:
motorupdate
Revision:
15:f40e834d063b
Parent:
14:bc77edc4adb0
Child:
16:9c5e9306ae10
--- a/motor.cpp	Sun Nov 20 13:24:43 2016 +0000
+++ b/motor.cpp	Sun Nov 20 13:45:30 2016 +0000
@@ -10,17 +10,15 @@
 
 
 //Speed control
-void Acc(float& motorA, float& motorB);
-void Decc(float& motorA, float& motorB);
-void StartLine();
+
+float setDutyCycle(float dutyC, int w,int targetW);
 
 //Corner Control
 
 void dutyCycleCorner( float speed, float angle);
 void corner(float &w1,float &w2,float deltaTheta,int maxspeed);
 
-void steering(float center, float theta, int maxspeed);
-void centerWheels();
+
 int cornerPwmControl;// this sets the cornering percentage ratio. value between 1 and 0.
                      // 100 means both motors run at the same speed. 0 means that one motor turns off.
 
@@ -81,101 +79,36 @@
 //------------------------ this is for speed control---------------------------------------------------
 //-----------------------------------------------------------------------------------------------------
 
-
+float setDutyCycle(float dutyC, int w,int targetW)
+{
     
-void Acc(float& motorA, float& motorB)// set up so as to control both motors during acc. Potential use during corners
-    {
-        motorA = motorA + 0.1;
-        motorB = motorB + 0.1;
-        TFC_SetMotorPWM(motorA,motorB);
-        
-                
-    return ;
     
-    }
-    
-void Decc(float &motorA, float &motorB)
+    if(true)
     {
-        // a good thing to do would be to have a margin for adjustment so that the car cornering can control the acc+dcc much better. 
+        if(w<targetW)   
+        {
+            dutyC+=0.1;        
         
-        motorA = motorA - 0.1;
-        motorB = motorB - 0.1;
+        }  
         
-        TFC_SetMotorPWM(motorA,motorB);
+        else
+        {
+            dutyC-=0.1;   
+        }
         
-    return ;
-    
     }
     
     
-void StartLine()
+    else if(false)
     {
-        TFC_HBRIDGE_ENABLE;
-        float a=0;
-        float b=0;
-          
-        int x=0 ;
-        while(x<5)
-        {
-            Acc(a,b);
-            wait(0.5);
-            x++  ;
-        } 
         
-     return ;
-    }
-    
-void finishLine(float pwmA)
-    {
-        float pwmB= pwmA;
-        while(pwmA>0)
-        {
-            
-          
-           Decc(pwmA,pwmB);
-           
-        }
-        return;
     }
     
-    
-/*void speedSetting(int w1, int w2 ,int w1M, int w2M)
-{
-    // need to compare the measured frequency 
-    
-    float deltaW1 = w1 - w1M;
-    float deltaW2 = w2 - w2M;
-    
-    if(deltaW1 <0)
-    {
-        changespeed(0,w1);   
-    }
-    
-    else if(delatW1 >0)
-    {
-        changespeed(1,w1);
-    } 
-    return;
-}*/
-    
-//need to fill out function for calculating the change in speed.
-void changespeed(bool a, float w)
-{
-    float change;
-    
-    if(a == 1)
-    {
-        w+= change;
-    }
-    
-    else if (a ==0)
-    {
-        
-        w-= change;    
-    }
- return;   
+ 
+    return dutyC;
 }
     
+
  //----------------------------------------------------------------------------------------------------------------------------   
  //------------------------------------------------Cornering Control-----------------------------------------------------------   
  //----------------------------------------------------------------------------------------------------------------------------   
@@ -185,7 +118,7 @@
 // tThis is a function which works off of the duty cycle. NO SENSOR REQUIREMENT
 // CLEAN THIS UP AND UPDATE  FOR SENSORS VERSION WITH THIS CODE
 // this function works off the actual value rather than the change in angle. therefore need to have a variabe which stores where the value is.
-void dutyCycleCorner( float speed, float angle)
+void dutyCycleCorner( float speed, float theta)
 {
         bool leftOrRight;
         if(theta<0)
@@ -195,7 +128,7 @@
             
         }
  
-        float deltaW = ((0.2f*tan((angle/0.02222f)* (3.14f / 180.0f)))/0.2f)*speed;
+        float deltaW = ((0.2f*tan((theta/0.02222f)* (3.14f / 180.0f)))/0.2f)*speed;
         
         //TFC_SetMotorPWM(w2,w1);
         if(leftOrRight){
@@ -211,7 +144,7 @@
 }
         
         
-void sensorCorner(float &w1,float &w2,float deltaTheta,int maxspeed)
+void sensorCorner(float &w1,float &w2,float theta,int speed)
 {   // when cornering left the left motor slows down more than the right hand side
     // may just replace with ACC and DECC
    
@@ -224,10 +157,10 @@
             
         }
  
-    float deltaW = ((0.2f*tan((angle/0.02222f)* (3.14f / 180.0f)))/0.2f)*speed;
+    float deltaW = ((0.2f*tan((theta/0.02222f)* (3.14f / 180.0f)))/0.2f)*speed;
     
-    &w1= maxspeed+ deltaW;
-    &w2= maxspeed -deltaW;
+    w1= speed+ deltaW;
+    w2= speed -deltaW;
         
         
     return;   
@@ -236,44 +169,11 @@
 
     
     
-float centerWheels(float min, float max)
-{
-    float center= (min +max)/2;
-
-    return center;
-}
-
-void steering(float center, float theta, int maxspeed,float & w1, float & w2)
-{   // this function is for simply calculating the motor speeds. this reduces the amount of calculations needed 
-    //and can be triggered when the car steers.
-    
-    
-    float deltaTheta =  center- theta;
-    
-    // need to convert to degrees/radians. that can do the above as well.
-    if(deltaTheta <0)
-    {
-        // going left?
-        corner(w1,w2,deltaTheta,maxspeed);
-    }
-    
-    else{
-        //going right?
-        corner(w2,w1,deltaTheta,maxspeed);
-        
-    }
-    
- return;   
-}
-
-void setDutyCycle(int w, int targetW)
-{
-    
-    
- 
-    
-}
 
 
 
 
+
+
+
+