Sven Kugathasan / Mbed OS SKAFMO_2

Dependencies:   PID

Revision:
16:d426b65b4ace
Parent:
15:b0f63ea39943
Child:
17:209ac0b10ba1
--- a/main.cpp	Fri Mar 24 14:37:30 2017 +0000
+++ b/main.cpp	Fri Mar 24 15:11:39 2017 +0000
@@ -135,6 +135,12 @@
 float a; 
 float b;
 
+typedef struct{
+    float a;
+    float b;
+}float2;
+
+
 /*_____Basic Functions (Motor Drive, Synchronization, Reading Rotor State)____*/
 
 //Set a given drive state
@@ -185,17 +191,17 @@
 /*________________Advanced Functions (Speed and Position Control)_____________*/
 
 // Function involves PID 
-void position_control(float rotation_set, float velocity_set){
+void position_control(float2 *cmd){
     
-    rev_target = rotation_set;
-    vel_target = velocity_set;
+    rev_target = cmd->a;
+    vel_target = cmd->b;
     
     //Reverses motor direction if forwards rotation requested 
     if((rev_target < 0)){
         direction = -1;
         rev_target = rev_target * -1;
     }
-    else if(velocity_set < 0){
+    else if(vel_target < 0){
         direction = -1;
         vel_target = vel_target * -1;
     }
@@ -279,9 +285,8 @@
 }
 
 void pid_isr(){  
+    
     TIME = 1;       
-    //led1 = !led1;
-    //tmp.start();
     
     //117 Pulses per revolution
     pulse_count++;           
@@ -305,7 +310,7 @@
     total_rev = (count/6.0f) + partial_rev; 
     
     //Calculate new PID Control Point
-   /* if((total_rev/rev_target) > 0.75f){
+    if((total_rev/rev_target) > 0.75f){
         dist_pid.setProcessValue(total_rev);
         dutyout = dist_pid.compute();
     }
@@ -314,20 +319,8 @@
         dutyout = velocity_pid.compute();
     }
     
-    if((total_rev/rev_target) > 0.75f){
-        dist_pid.setProcessValue(total_rev);
-        dutyout = dist_pid.compute();
-    }
-    else{
-        velocity_pid.setProcessValue(partial_vel);
-        dutyout = velocity_pid.compute();
-    }*/
+    TIME = 0;
     
-    
-    //tmp.stop();
-    //test_time = tmp.read();
-    //tmp.reset();
-    TIME = 0;
 }
 
 /*__________________________Main Function_____________________________________*/ 
@@ -460,9 +453,9 @@
     InterruptCHA.rise(&pid_isr);
     
     //Initial Target Settings 
-    //float rotation_set = 100.00;
-    //float velocity_set = 10.00;
-    
+    float rotation_set = 100.00;
+    float velocity_set = 10.00;
+    float2 cmd_set = {rotation_set,velocity_set};
     // Melody in a Thread
     // PID in Thread
     
@@ -470,10 +463,9 @@
     //float rotation_set = revstates_max;
     //float velocity_set = vel_max;
     
+    pid_thread.start(callback(position_control, &cmd_set));
     
-    serial_com();
-    
-    //position_control(rotation_set, velocity_set); 
+    //serial_com();
     
 }