Chun Feng Huang / CURRENT_CONTROL

Fork of CURRENT_CONTROL by LDSC_Robotics_TAs

Files at this revision

API Documentation at this revision

Comitter:
adam_z
Date:
Fri Apr 22 15:21:31 2016 +0000
Parent:
1:c5973a56d474
Child:
3:c787d1c5ad6a
Commit message:
no problem till now

Changed in this revision

CURRENT_CONTROL.cpp Show annotated file Show diff for this revision Revisions of this file
CURRENT_CONTROL.h Show annotated file Show diff for this revision Revisions of this file
--- a/CURRENT_CONTROL.cpp	Fri Apr 22 14:32:01 2016 +0000
+++ b/CURRENT_CONTROL.cpp	Fri Apr 22 15:21:31 2016 +0000
@@ -25,7 +25,8 @@
 
 void CURRENT_CONTROL::Control(float curRef)
 {
-    curFeedBack = (currentAnalogIn.read() - currentOffset)*analog2Cur;
+    analogInValue = currentAnalogIn.read();
+    curFeedBack = (analogInValue - currentOffset)*analog2Cur;
     pid.Compute(curRef, curFeedBack);
     MotorPlus = 0.5 - pid.output;
     if(pwmIndex_ == PWM1)TIM1->CCER |= 4;
@@ -36,10 +37,20 @@
 {
     analog2Cur = ratio;
 }
-
+//****************for test************************//
 void CURRENT_CONTROL::SetPWMDuty(float ratio)
 {
     MotorPlus = ratio;
     if(pwmIndex_ == PWM1)TIM1->CCER |= 4;
     else if(pwmIndex_ == PWM2)TIM1->CCER |= 64;
+}
+
+float CURRENT_CONTROL::GetAnalogIn(void)
+{
+    return analogInValue = currentAnalogIn.read();   
+}
+
+float CURRENT_CONTROL::GetCurrent(void)
+{
+    return  ((currentAnalogIn.read()-currentOffset)*analog2Cur);   
 }
\ No newline at end of file
--- a/CURRENT_CONTROL.h	Fri Apr 22 14:32:01 2016 +0000
+++ b/CURRENT_CONTROL.h	Fri Apr 22 15:21:31 2016 +0000
@@ -15,10 +15,13 @@
 
     CURRENT_CONTROL(PinName curChannel, PinName PwmChannel1, PinName PwmChannel2, PWMIndex pwmIndex, float Kp, float Ki, float Kd, float samplingTime);
     void Control(float curRef);
+    void SetAnalog2Cur(float ratio);
+    //functions for test////////
     void ChangePwmPeriod(float microSeconds);
-    void SetAnalog2Cur(float ratio);
     void SetPWMDuty(float ratio);
-
+    float GetAnalogIn(void);
+    float GetCurrent(void);
+    //////////////////////////
     PWMIndex pwmIndex_;
     PID pid;
     PwmOut MotorPlus;
@@ -29,6 +32,8 @@
     float curFeedBack;
     float analog2Cur;
     AnalogIn currentAnalogIn;
+    float analogInValue;
+    
 private:
 
     float Ts;