The program
Dependencies: FileSystem_POPS Sound m3pi_test2 mbed
Fork of m3PI_TP_POPS_II2015v0 by
Revision 4:22275847875d, committed 2018-05-03
- Comitter:
- Maximousse
- Date:
- Thu May 03 12:08:03 2018 +0000
- Parent:
- 3:b4b0c5219d2a
- Commit message:
- test3;
Changed in this revision
diff -r b4b0c5219d2a -r 22275847875d Sound.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sound.lib Thu May 03 12:08:03 2018 +0000 @@ -0,0 +1,1 @@ +http://os.mbed.com/users/suupen/code/Sound/#d526205994e9
diff -r b4b0c5219d2a -r 22275847875d m3pi.lib --- a/m3pi.lib Mon Nov 23 23:24:35 2015 +0000 +++ b/m3pi.lib Thu May 03 12:08:03 2018 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/bouaziz/code/m3pi/#f65c5aa1775c +https://os.mbed.com/teams/Polybot1/code/m3pi_test2/#a12166fc8c19
diff -r b4b0c5219d2a -r 22275847875d main3.cpp --- a/main3.cpp Mon Nov 23 23:24:35 2015 +0000 +++ b/main3.cpp Thu May 03 12:08:03 2018 +0000 @@ -1,31 +1,166 @@ - #include "mbed.h" #include "m3pi.h" #include "MSCFileSystem.h" m3pi m3pi; // Initialise the m3pi -Serial xbee(p28,p27); DigitalOut resetxbee(p26); -Serial pc(USBTX, USBRX); // For debugging and pc messages, uses commented out to prevent hanging +DigitalOut led3(LED3); +DigitalOut led1(LED1); +DigitalIn push(p21); + +Serial pc(USBTX, USBRX); // For debugging and pc messages, uses commented out to prevent hangings +Serial bt(p28,p27); + MSCFileSystem fs("fs"); BusOut myleds(LED1, LED2, LED3, LED4); -int main() { - resetxbee =0; - wait(0.01); - resetxbee =1; +const int THRESH = 200; + +unsigned short sensors[5], mems[5], nbCapt, memsNb; +char tab[4]; +float position, proportional, last_proportional, integral; + +unsigned char dir; +float speed, duration, s1, s2; +char src='x'; + +Timer timer; + + + + + + + + + +Serial& getCurrentSerial() +{ + return (src == 'u' ? pc : bt); +} + + + + +void set_motors(float mr, float ml) +{ + m3pi.left_motor(ml); + m3pi.right_motor(mr); +} + +//------------------------------------------------------------------------------ + +void getCapt(bool mem = false) +{ + int v = 0; + nbCapt = 0; - FILE *p= fopen("/fs/tt.txt","a+"); + m3pi.calibrated_sensors(sensors); + + for(int i=0 ; i<5 ;i++) + { + sensors[i] = (sensors[i] > THRESH ? true : false); + if(sensors[i]) + { + v += 0x1<<i; + nbCapt++; + } + if(mem) + { + mems[i] = sensors[i]; + memsNb = nbCapt; + } + } + m3pi.leds(v); +} + +//------------------------------------------------------------------------------ + +void suiviIntersect(float intervalTour = 0.0f) +{ + bool done = false; + //forward = true; + unsigned int idx=0; + float vl, vr, omega, l_k=0, l_k1=0, sum=0, vmax=1.0f; + +#if 1 // Low speed + const float Ki=0.007f, Kp=0.7f, Kd=1.5f, v=0.2; +#else + const float Ki=0.0007f, Kp=0.07f, Kd=1.5f, v=0.80f; +#endif m3pi.sensor_auto_calibrate(); - wait(1.); + wait(1.0); - fprintf(p,"ecrire dans la cle USB\r\n"); - fclose(p); - - while(1) { + Timer t; t.start(); + while(!done) + { + idx++; + getCapt(); + + // PID + l_k1 = l_k; + l_k = m3pi.line_position(); + //v = sp; + omega = l_k*Kp; // Proportionnal + sum += l_k; + omega += sum*Ki; // Integral + omega += (l_k-l_k1)*Kd; + vl = v+omega < vmax ? (v+omega > -vmax ? v+omega : vmax) : vmax; + vr = v-omega < vmax ? (v-omega > -vmax ? v-omega : -vmax): vmax; + + vr *= 1.2; + vl *= 1.2; + set_motors(vr,vl); + + //---------------------INTERSECTION + if(sensors[0] || sensors[4]) { + char c = 'a'; + //if ((c<='5') & (c>='1')) { + // leds[c - '1'] = !leds[c - '1']; + //} + bt.printf("Voici un %c \n", c); + } + + /* + if(forward) set_motors(vr,vl); + else set_motors(-vl,-vr); + */ + + m3pi.cls(); + //const char* C [1]= {'0' + idx}; + //m3pi.printf(C); } + + return; } + + + + + + + + + + +int main() { + bt.baud(115200); + m3pi.cls(); + wait(0.5); + + m3pi.sensor_auto_calibrate(); + + set_motors(0.f,0.f); + char c = 'a'; + bt.printf("Hello World!\n"); + + while(1) + { + getCapt(); + suiviIntersect(); + } +} \ No newline at end of file