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.
Revision 1:38c836c4bc0f, committed 2016-03-10
- Comitter:
- marinacaroline
- Date:
- Thu Mar 10 19:52:42 2016 +0000
- Parent:
- 0:19db2de32450
- Commit message:
- this code covers the elevator lab through section 4, and has the logic, proportional, and integral controllers all inside and labelled. to use one, just comment out the other two;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 19db2de32450 -r 38c836c4bc0f main.cpp --- a/main.cpp Wed Mar 09 03:36:06 2016 +0000 +++ b/main.cpp Thu Mar 10 19:52:42 2016 +0000 @@ -6,14 +6,14 @@ Motor RickyBobby(p25,p27,p28); //declares output to motor int go,cnt,pwm; //These two variables are integers -float number,counter,x,mesHeight,desHeight,err; +float number,counter,x,mesHeight,desHeight,err,Kp,dutyCyc,intErr,Ki; int main() { pc.baud(115200); //sets baud rate while(1) { //Infinite loop cnt=0; - number=60; + number=100; //these two lines communicate from the mbed to the teraterm window to collect //desired values @@ -29,28 +29,58 @@ x=dale.read(); mesHeight = ((267.3918*x*x*x) + (-431.3231*x*x) + 236.6525*x + -22.2608); err = desHeight-mesHeight; + Kp = 1.8; + +/* + //This is the Integral Controller + intErr = err*cnt; + dutyCyc = Kp*err + Ki*intErr; + pwm = dutyCyc; + RickyBobby.speed(dutyCyc); + wait(.05); +*/ + + //This is the Proportional Controller + + dutyCyc = (Kp*err); + RickyBobby.speed(dutyCyc); + wait(.05); + pwm = dutyCyc; + + + if (pwm > 1) { + pwm = 1; + //dutyCyc = 1; + } + + else if (pwm < -1) { + pwm = -1; + //dutyCyc = -1; + } + + //pc.printf("mesHeight = %f\r\n", mesHeight); - if (err > 0) { + //This is the Logic Controller +/* if (err > 0) { RickyBobby.speed(1); pwm = 1; wait(.05); - } + } else if (err < 0) { RickyBobby.speed(-1); pwm = -1; wait(.05); } - else { RickyBobby.speed(0); pwm = 0; } - +*/ cnt=cnt+1; wait(.05); pc.printf("%d,%f,%d\r\n",cnt,mesHeight,pwm); - + } RickyBobby.speed(0); go = 0;