changes to motor library

Dependents:   pid-car-example

Fork of motor by Lawrence Harlow

Branch:
motorupdate
Revision:
27:98aecf1889ed
Parent:
26:c74e70a745ec
Child:
28:9d4042b05640
--- a/motor.cpp	Wed Jan 11 11:07:41 2017 +0000
+++ b/motor.cpp	Wed Jan 11 11:17:25 2017 +0000
@@ -4,7 +4,7 @@
 #include "motor.h"
 DigitalOut myled(LED1);
 
-//adam sucks
+
 
 
 
@@ -24,11 +24,11 @@
 //----------------------------------------------This is for Motor Set up------------------------------------------------------------
 //----------------------------------------------------------------------------------------------------------------------------------  
 
- 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() // This simply sets the PWM and turns the motors off whent he button is pushed
     {
         
         
-        TFC_SetMotorPWM(0.4,0.7);
+        TFC_SetMotorPWM(0.4,0.4);
         
         while(1)
         {
@@ -42,7 +42,7 @@
         }
         return;
     }
-    
+// This works for starting the car using the buttons on the bridge 
 void DefaultMode()
     {
         TFC_Init();
@@ -67,7 +67,8 @@
 //-----------------------------------------------------------------------------------------------------    
 //------------------------ this is for speed control---------------------------------------------------
 //-----------------------------------------------------------------------------------------------------
-
+// This simply sets the duty cycle.
+// its a rudementary motor control.
 float setDutyCycle(float dutyC, int w,int targetW)
 {
     
@@ -104,8 +105,8 @@
     
     
     
-// 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 is a function which works off of the duty cycle. NO SENSOR REQUIREMENT
+
 // 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 theta)
 {
@@ -135,7 +136,7 @@
         
 void sensorCorner(float &w1,float &w2,float theta,float speed)
 {   // when cornering left the left motor slows down more than the right hand side
-   
+   // this is the ED for when the car is running off of the sensors rather than a set PWM
    
     bool leftOrRight = false;
     float tune = 1.2;
@@ -151,27 +152,31 @@
      theta = 0.5;   
         
     }
-    float deltaW = ((0.1f*tan((theta/0.02222f)* (3.14f / 180.0f)))/0.2f)*speed;
+    
+    
+    
     
-    //float vin = speed(2 - 0.1/tan((theta/0.022222)*(3.14f / 180.0f));
-    //float vout = speed(2 + 0.1/tan((theta/0.022222)*(3.14f / 180.0f));
+    //These equations set the angular speeds of the motors 
+    //there are two equations for testing purposes
     if(true){
+    float deltaW = ((0.1f*tan((theta/0.02222f)* (3.14f / 180.0f)))/0.2f)*speed;
     if(leftOrRight){
           w1= speed+ deltaW * tune;
           w2= speed -deltaW * tune;
-          //w1=vout;
-          //w2=vin;
+         
           
           }
     else{
             w1= speed- deltaW*tune;
             w2= speed +deltaW*tune;
-            //w1=vin;
-            //w2=vout;
+            
         }
     }
+    
     else{
-         if(leftOrRight){
+        float vin = speed(2 - 0.1/tan((theta/0.022222)*(3.14f / 180.0f));
+        float vout = speed(2 + 0.1/tan((theta/0.022222)*(3.14f / 180.0f));
+        if(leftOrRight){
           
           w1=vout;
           w2=vin;