Functie van het slaan van de bal
Dependencies: Encoder HIDScope mbed-dsp mbed MODSERIAL
Revision 14:e9ab81429271, committed 2014-10-29
- Comitter:
- BasvanBuuren
- Date:
- Wed Oct 29 16:21:19 2014 +0000
- Parent:
- 13:b35f3553f210
- Commit message:
- Hij doet het gewoon!
;
Changed in this revision
MODSERIAL.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r b35f3553f210 -r e9ab81429271 MODSERIAL.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MODSERIAL.lib Wed Oct 29 16:21:19 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Sissors/code/MODSERIAL/#b04ce87dc424
diff -r b35f3553f210 -r e9ab81429271 main.cpp --- a/main.cpp Wed Oct 29 15:36:59 2014 +0000 +++ b/main.cpp Wed Oct 29 16:21:19 2014 +0000 @@ -2,7 +2,8 @@ #include "HIDScope.h" //#include "mbed-dsp.h" #include "encoder.h" -#include <iostream> +//#include <iostream> +#include "MODSERIAL.h" #define SAMP_TIME 0.01 #define K_P (0.001) @@ -15,6 +16,7 @@ //define in and output +MODSERIAL pc(USBTX,USBRX); Encoder encoderA(PTD0,PTD2); PwmOut m1_speed(PTA5); DigitalOut m1_dir(PTA4); @@ -38,50 +40,61 @@ int main() { + int y1; Ticker looptimer; + pc.baud(9600); looptimer.attach(setlooptimerflag,SAMP_TIME); while(1) - { - cin >> y1; - cout << y1 << endl; - slam(y1); + { + if(! pc.readable()) + { + pc.printf("Main %d\n\r", encoderA.getPosition()); + wait(0.1); + } + else + { + y1 = pc.getc()-48; + pc.printf("%d\n\r", y1 ); + slam(y1); + } } } void slam(int emg_value) { - cout << "Ik begin met de slafunctie" << endl; - cout << encoderA.getPosition() << endl << "check" << endl; + //pc.printf( "Ik begin met de slafunctie\n\r"); + //pc.printf( encoderA.getPosition() << endl << "check\n\r"); + pc.printf("Sla\n\r%d\n\r", encoderA.getPosition()); switch (emg_value) { case 1: - cout << "zaak1" << endl; + pc.printf( "zaak1\n\r"); m1_dir=1; max_speed=0.33; //m1_speed.write(0.33); - cout << "Motor 1 draait" << endl; + //pc.printf( "Motor 1 draait\n\r"); break; case 2: - cout << "zaak2"<< endl; + pc.printf( "zaak2\n\r"); m1_dir=1; max_speed=0.66; //m1_speed.write(0.66); - cout << "Motor 1 draait" << endl; + pc.printf( "Motor 1 draait\n\r"); break; case 3: - cout << "zaak3"<< endl; + pc.printf( "zaak3\n\r"); m1_dir=1; max_speed=1; //m1_speed.write(1); - cout << "Motor 1 draait" << endl; + pc.printf( "Motor 1 draait\n\r"); break; default: m1_dir=1; m1_speed=0; break; } - cout << "Ik ben uit de switch" << endl; + //pc.printf( "Ik ben uit de switch\n\r"); while(!looptimerflag); looptimerflag=false; new_speed=pid(MAXENCO,encoderA.getPosition()); @@ -100,7 +113,7 @@ { while(!looptimerflag); looptimerflag=false; - //cout << "Eat, Sleep, Rave, Repeat" << endl; + //pc.printf( "Eat, Sleep, Rave, Repeat\n\r"); new_speed=pid(MAXENCO,encoderA.getPosition()); clamp(&new_speed,-max_speed,max_speed); if (new_speed>0) @@ -112,10 +125,11 @@ m1_dir=0; } m1_speed.write(fabs(new_speed)); - //cout << new_speed << endl; + //pc.printf( new_speed << endl; } - cout << "Ik ben uit de eerste whilelus" << endl; - cout << encoderA.getPosition() << endl << "check" << endl; + pc.printf( "Ik ben uit de eerste whilelus\n\r"); + //pc.printf( encoderA.getPosition() << endl << "check\n\r"); + pc.printf("%d\n\r", encoderA.getPosition()); while(!looptimerflag); looptimerflag=false; new_speed=pid(MINENCO,encoderA.getPosition()); @@ -147,8 +161,9 @@ m1_speed.write(fabs(new_speed)); } m1_speed.write(0); - cout << "Ik ben uit de tweede whilelus" << endl; - cout << encoderA.getPosition() << endl << "check" << endl; + pc.printf( "Ik ben uit de tweede whilelus\n\r"); + //pc.printf( encoderA.getPosition() << endl << "check\n\r"); + pc.printf("%d\n\r", encoderA.getPosition()); } void clamp(float * in, float min, float max)