Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 2:01372422b0c7
- Parent:
- 1:128dc77d025a
diff -r 128dc77d025a -r 01372422b0c7 main.cpp
--- a/main.cpp Mon Feb 01 16:23:33 2021 +0000
+++ b/main.cpp Fri Mar 05 17:17:41 2021 +0000
@@ -10,7 +10,14 @@
float v = 0.0;
float d = 0.0;
-
+float prevArea = 0.0;
+float area = 0.0:
+float feedback = 0.0;
+
+float KP =-0.0058;
+float KI =1.0223;
+float TI = .001f;
+int sat = 99999;
void pwmUpdate()
{
v = input.read();
@@ -18,12 +25,32 @@
if( abs(d - output.read()) > 0.001) //only updates the duty cycle if there is a change in the duty cycle greater than 0.3%
output.write(d);
}
-
+void piUpdate(){
+ feedback = input.read();//inputs frequency of motor
+ area= TI*feedback + prevArea; //PI integration
+ d = KP*error(i)+ KI*errorArea(i); //PI integration
+ output.write(d); //changing speed from PI
+ prevArea = area; //storing value
+}
+void realUpdate(float x){
+ feedback = input.read();
+ area= TI*feedback + prevArea;
+ d = KP*error(i)+ KI*errorArea(i);
+ output.write(x-d);
+ prevArea = area;
+}
+void step(){
+ for(float s = 0; s < SAT; s+= TI){
+ v = (-1.277e-18*s^4 - 1.61e-14*s^3 + 2.789e-12*s^2 + 1.23e-11*s)/(5.759e-21*s^6 + 1.472e-16*s^5 + 9.414e-13*s^4 + 8.078e-12*s^3 + 2.02e-11*s^2 + 1.23e-11*s)//TF from gclose
+ realUpdate(val);
+ }
+}
int main(void)
{
output.period(0.00005f); // 20 kHz control signal
// attaches pwmUpdate function to the ticker with a period of 20ms
- updater.attach(&pwmUpdate,0.00005f);
+ //updater.attach(&pwmUpdate,0.00005f);
+ updater.attach(&piUpdate,TI);
std::cout << "AnalogIn: " << v << " Duty Cycle: " << d << std::endl;
while(1) {} // do nothing
}
\ No newline at end of file