thijs ruikes
/
PROJECT-MOTORSPEEDCONTROLLER
ding
Revision 2:44cc689e14d6, committed 2014-10-29
- Comitter:
- wiesdat
- Date:
- Wed Oct 29 13:39:26 2014 +0000
- Parent:
- 1:5ac17a29fa08
- Commit message:
- Motorspeedcontrol: I regelaar, input case
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Oct 29 13:25:18 2014 +0000 +++ b/main.cpp Wed Oct 29 13:39:26 2014 +0000 @@ -11,7 +11,7 @@ PwmOut pwm(PTA5); DigitalOut dir(PTA4); - +int y1; @@ -20,9 +20,7 @@ int n=0,a =1 ,b =0; float out; -//clamps value 'in' to min or max when exceeding those values -//if you'd like to understand the statement below take a google for -//'ternary operators'. + void clamp(float * in, float min, float max) { *in > min ? *in < max? : *in = max: *in = min; @@ -66,33 +64,42 @@ v = (counts)*((2*3.14159265359)/1550); return v; } + +float speedcontrol() +{ + + v = getv(); + cout<<"v: "<<v<<endl; + out = pid(v_ref,v); + cout<<"out: "<<out<<endl; + pwm = out; +} + int main() { dir = 1; - cout<<"typ v_ref: "<<endl; - cin>>v_ref; - cout<<"v_ref: "<<v_ref<<endl; + cout<<"typ case: "<<endl; + cin>>y1; + cout<<"case: "<<y1<<endl; + + while(1) { - v = getv(); - cout<<"v: "<<v<<endl; - out = pid(v_ref,v); - cout<<"out: "<<out<<endl; - pwm = out; + switch(y1) { + case 0 : + v_ref = 1; + break; + case 1 : + v_ref = 2; + break; + case 2 : + v_ref = 3; + break; + } + + speedcontrol(); + } } -/* -int main() -{ - speed = 0.09; - pwm = speed; - while(1){ - wait(0.2); - enca = encoderA.getPosition(); - cout<<enca<<endl; - } -} -*/ -