changes to motor library

Dependents:   pid-car-example

Fork of motor by Lawrence Harlow

Branch:
testing
Revision:
7:9aaa4f73bb32
Parent:
5:c50e40797114
Child:
8:4df2a47ab4ee
--- a/motor.cpp	Mon Oct 24 14:44:12 2016 +0000
+++ b/motor.cpp	Mon Nov 07 16:00:45 2016 +0000
@@ -2,9 +2,9 @@
 #include "TFC.h"
 DigitalOut myled(LED1);
 
-int  motor_setup(); 
+
 void TurnOn();
-void RunMotor();
+void runMotor();
 void DefaultMode();
 
 
@@ -19,6 +19,7 @@
 void cornerLeft(float speed);
 void cornerRight(float speed);
 
+void steering(float center, float theta, int maxspeed);
 
 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.
@@ -28,30 +29,24 @@
 // uncomment for testing motor functions.
 
 
- int   motor_setup()
-    {
-        
-        //TurnOn();
-        
-        return 0;
-    }
-    
-    
+
+//need a function for calcu;lating the angle
+//need a function for converting w1 to delta. or do i?
  
     
 
- void   RunMotor() /// putting it into this mode for some reason makes a bit of a whinning noise (this may simply just be the motor running)
+ void   runMotor() /// putting it into this mode for some reason makes a bit of a whinning noise (this may simply just be the motor running)
     {
         
-        TFC_HBRIDGE_ENABLE;
-        // TFC_SetMotorPWM(0.4,0.7);
+        
+        TFC_SetMotorPWM(0.4,0.7);
         
         while(1)
         {
             if(TFC_ReadPushButton(0)>0)
             {
                 TFC_SetMotorPWM(0.0,0.0);
-                TFC_HBRIDGE_DISABLE;
+                
                 DefaultMode();
                 
             }
@@ -61,11 +56,13 @@
     
 void DefaultMode()
     {
+        TFC_Init();
         while(1)
         {
+            TFC_HBRIDGE_ENABLE;
             if(TFC_ReadPushButton(1)>0)
                {
-                    RunMotor();
+                    runMotor();
                 }
             
             else if(TFC_ReadPushButton(0)>0)
@@ -75,6 +72,7 @@
             
                
         }
+        TFC_HBRIDGE_DISABLE;
     return;
     }
     
@@ -204,24 +202,31 @@
      return;   
     }
     
-void deltaCornerRight(float speed,float deltaTheta)
-    {// when cornering right the inner motor slows down more than the right hand side
-    // may just replace with ACC and DECC
-    float r;
-    float d;
-    float l;
-    // it may be worth doing this off the change in theta. so that it is insesnsitive to the calibration.
-    float diff= ((d*tan(deltaTheta)/(2*l)));
+
+    
     
-    float w1 = (speed/r)*(1+diff);
-    float w2 = (speed/r)*(1-diff);
-    
-    // when there is a speed sensor tghe conversion will be much more simplistic. this is basically just guessing.
-    // need to convert w1 to the duty cycle
-    TFC_SetMotorPWM(w2,w1); //temperary values
-        
-        
-     return;   
+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)
+{
+    float deltaTheta =  center- theta;
+    if(deltaTheta <0)
+    {
+        // going left?
+        corner(w1,w2,deltaTheta);
     }
     
+    else()
+    {
+        //going right?
+        corner(w2,w1,deltaTheta)
+        
+    }
     
+ return;   
+}
\ No newline at end of file