first

Dependencies:   BEAR_Reciever Motor eeprom iSerial mbed

Fork of BEAR_Motion by BE@R lab

Revision:
6:98871feebea0
Parent:
1:84167ca00307
Child:
7:bf239d051e8c
--- a/main.cpp	Thu Jan 14 18:49:01 2016 +0000
+++ b/main.cpp	Sat Jan 16 01:17:21 2016 +0000
@@ -1,11 +1,11 @@
 //*****************************************************/
-//  Include  // 
+//  Include  //
 #include "mbed.h"
 #include "pinconfig.h"
 #include "PID.h"
 #include "Motor.h"
 #include "eeprom.h"
-#include "Reciever.h" 
+#include "Receiver.h"
 
 //*****************************************************/
 //--PID parameter--
@@ -23,7 +23,7 @@
 //-- Communication --
 Serial PC(D1,D0);
 ANDANTE_PROTOCOL_PACKET command;
-//-- encoder --  
+//-- encoder --
 int Upper_Position;
 int Lower_Position;
 int data;
@@ -44,35 +44,35 @@
 {
     Enc.format(8,0);
     Enc.frequency(200000);//due to rising time,have to decrease clock from 1M - 240k
-    
+
     Encoder = 0;
     Enc.write(0x41);
     Enc.write(0x09);
     data = Enc.write(0x00);
     Encoder = 1;
-    
+
 }
 //*****************************************************/
 int Get_EnValue(int Val)
 {
     int i = 0;
     static unsigned char codes[] = {
-    127, 63, 62, 58, 56, 184, 152, 24, 8, 72, 73, 77, 79, 15, 47, 175,
-    191, 159, 31, 29, 28, 92, 76, 12, 4, 36, 164, 166, 167, 135, 151, 215,
-    223, 207, 143, 142, 14, 46, 38, 6, 2, 18, 82, 83, 211, 195, 203, 235, 
-    239, 231, 199, 71, 7, 23, 19, 3, 1, 9, 41, 169, 233, 225, 229, 245, 
-    247, 243, 227, 163, 131, 139, 137, 129, 128, 132, 148, 212, 244, 240, 242, 250,
-    251, 249, 241, 209, 193, 197, 196, 192, 64, 66, 74, 106, 122, 120, 121, 125, 
-    253, 252, 248, 232, 224, 226, 98, 96, 32, 33, 37, 53, 61, 60, 188, 190, 
-    254, 126, 124, 116, 112, 113, 49, 48, 16, 144, 146, 154, 158, 30, 94, 95 };
-    
-    while(Val != codes[i])
-    {
+        127, 63, 62, 58, 56, 184, 152, 24, 8, 72, 73, 77, 79, 15, 47, 175,
+        191, 159, 31, 29, 28, 92, 76, 12, 4, 36, 164, 166, 167, 135, 151, 215,
+        223, 207, 143, 142, 14, 46, 38, 6, 2, 18, 82, 83, 211, 195, 203, 235,
+        239, 231, 199, 71, 7, 23, 19, 3, 1, 9, 41, 169, 233, 225, 229, 245,
+        247, 243, 227, 163, 131, 139, 137, 129, 128, 132, 148, 212, 244, 240, 242, 250,
+        251, 249, 241, 209, 193, 197, 196, 192, 64, 66, 74, 106, 122, 120, 121, 125,
+        253, 252, 248, 232, 224, 226, 98, 96, 32, 33, 37, 53, 61, 60, 188, 190,
+        254, 126, 124, 116, 112, 113, 49, 48, 16, 144, 146, 154, 158, 30, 94, 95
+    };
+
+    while(Val != codes[i]) {
         i++;
     }
-    
+
     return i;
-    
+
 }
 //*****************************************************/
 void SET_UpperPID()
@@ -90,20 +90,20 @@
     Low_PID.setInputLimits(0,127);
     Low_PID.setOutputLimits(0,1);
 }
-//******************************************************/   
+//******************************************************/
 void Move_Upper()
 {
     Read_Encoder(EncoderA);
     Upper_Position = Get_EnValue(data);
 
     Up_PID.setProcessValue(Upper_Position);
-            
-    if(Upper_Position - Uppper_SetPoint > 0 ){ 
+
+    if(Upper_Position - Uppper_SetPoint > 0 ) {
         dir = 1;
-        }
-    if(Upper_Position - Uppper_SetPoint < 0 ){ 
+    }
+    if(Upper_Position - Uppper_SetPoint < 0 ) {
         dir = -1;
-        }
+    }
     Upper.speed(LU_PID.compute() * dir);
 }
 //******************************************************/
@@ -113,15 +113,15 @@
     Lower_Position = Get_EnValue(data);
 
     Low_PID.setProcessValue(Lower_Position);
-            
-    if(Lower_Position - Lower_SetPoint > 0 ){ 
+
+    if(Lower_Position - Lower_SetPoint > 0 ) {
         dir = 1;
-        }
-    if(Lower_Position - Lower_SetPoint < 0 ){ 
+    }
+    if(Lower_Position - Lower_SetPoint < 0 ) {
         dir = -1;
-        }
+    }
     Lower.speed(LU_PID.compute() * dir);
-}   
+}
 //******************************************************/
 
 
@@ -129,9 +129,8 @@
 {
     SET_UpperPID();
     SET_LowerPID();
-    
-    while(1) 
-    {
+
+    while(1) {
         Up_PID.setSetPoint(Upper_SetPoint);
         Low_PID.setSetPoint(Lower_SetPoint);
 
@@ -140,9 +139,9 @@
     }
 
 }
-    
-    
-    
-    
+
 
 
+
+
+