This micromouse is for educational use in our College. The hardware and software is very simple.
/media/uploads/hayama/mbedmicromouse-manual-japanese-only.pdf
/media/uploads/hayama/eagle-design-micromouse.zip
details (in Japanese), http://plaza.rakuten.co.jp/CPU4Edu/20018
you can see the movie on youtube (for education) -> http://youtu.be/UYi81i8WVtI
(for competition using high torque motor) -> http://youtu.be/fJDyqnC91YY
Revision 1:4f623bfc5fdd, committed 2013-11-13
- Comitter:
- hayama
- Date:
- Wed Nov 13 09:48:01 2013 +0000
- Parent:
- 0:c154c65c5cc7
- Commit message:
- This micromouse is for educational use in our College. The hardware and software is very simple.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r c154c65c5cc7 -r 4f623bfc5fdd main.cpp --- a/main.cpp Thu Jul 04 16:01:36 2013 +0000 +++ b/main.cpp Wed Nov 13 09:48:01 2013 +0000 @@ -8,22 +8,23 @@ // run parameters #define LSPD 5 // timer count for low speed -#define HSPD 3 // timer count for high speed -#define STEP1 665 // number of step for 1 maze area -#define R90 265 // number of step for 90 degree right turn -#define L90 265 // number of step for 90 degree left turn -#define R180 530 // number of step for 180 degree u-turn -#define DISFR 16 // front right sensor value in normal micromouse position -#define DISFL 16 // front left sensor value in normal micromouse position -#define DISR 8 // right sensor value in normal micromouse position -#define DISL 8 // left sensor value in normal micromouse position -#define DISFMAX 2 // threshold of sensor value for front wall detection -#define DISRMAX 2 // threshold of sensor value for right wall detection -#define DISLMAX 2 // threshold of sensor value for left wall detection +#define HSPD 4 // timer count for high speed +#define STEP0 20 // munber of step for slow start +#define STEP1 500 // number of step for 1 maze area +#define R90 207 // number of step for 90 degree right turn +#define L90 207 // number of step for 90 degree left turn +#define R180 414 // number of step for 180 degree u-turn +#define DISFR 2.6 // front right sensor value in normal micromouse position +#define DISFL 2.6 // front left sensor value in normal micromouse position +#define DISR 0.75 // right sensor value in normal micromouse position +#define DISL 0.75 // left sensor value in normal micromouse position +#define DISFMAX 0.3 // threshold of sensor value for front wall detection +#define DISRMAX 0.3 // threshold of sensor value for right wall detection +#define DISLMAX 0.3 // threshold of sensor value for left wall detection // pattern table for stepping motor -const unsigned char RMOTOR[]={0x03, 0x06, 0x0C, 0x09, 0x00}; // magnetization pattern for right motor -const unsigned char LMOTOR[]={0x09, 0x0C, 0x06, 0x03, 0x00}; // magnetization pattern for left motor +const unsigned char RMOTOR[]={0x09, 0x0C, 0x06, 0x03, 0x00}; // magnetization pattern for left motor +const unsigned char LMOTOR[]={0x03, 0x06, 0x0C, 0x09, 0x00}; // magnetization pattern for right motor const unsigned char DtoR[]={0,2,4,0,8,0,0,0,1}; // table indicating to the right direction const unsigned char DtoL[]={0,8,1,0,2,0,0,0,4}; // table indicating to the left direction @@ -113,19 +114,29 @@ if (timS<20) timS++; else timS=0; // set counter timS if (timS==0){ ptFRB=ptFR; // measure all background values + ledFout=1; // LED-ON + wait_us(20); // delay + sensFR=(ptFR-ptFRB)*20; + ledFout=0; // LED-OFF + } + if (timS==5){ ptFLB=ptFL; // measure all background values ledFout=1; // LED-ON - wait_us(100); // delay - sensFR=(ptFR-ptFRB)*20; + wait_us(20); // delay sensFL=(ptFL-ptFLB)*20; ledFout=0; // LED-OFF } if (timS==10){ ptRB=ptR; + ledRLout=1; + wait_us(20); + sensR=(ptR-ptRB)*20; + ledRLout=0; + } + if (timS==15){ ptLB=ptL; ledRLout=1; - wait_us(100); - sensR=(ptR-ptRB)*20; + wait_us(20); sensL=(ptL-ptLB)*20; ledRLout=0; } @@ -135,11 +146,11 @@ if (fS==1){ // do the following process, when flag fS=1 fR=fL=1; // set high speed for both motor if(sensR>DISRMAX){ // when right wall exists, - if ((sensR-DISR)>4) fL=0; // set low speed for left moter, when close to the right wall - if ((sensR-DISR)<-4) fR=0; // set low speed for right moter, when close to the left wall + if ((sensR-DISR)>0.2) fL=0; // set low speed for left moter, when close to the right wall + if ((sensR-DISR)<-0.2) fR=0; // set low speed for right moter, when close to the left wall } else if(sensL>DISLMAX){ // when existing left wall only, - if ((sensL-DISL)>4) fR=0; // similar to the control by right wall. - if ((sensL-DISL)<-4) fL=0; + if ((sensL-DISL)>-0.2) fR=0; // similar to the control by right wall. + if ((sensL-DISL)<-0.2) fL=0; } } else { fR=fL=0; } // when fS=0, set low speed for both motor } @@ -150,7 +161,7 @@ void check_sens(){ while (1){ pc.printf("\f"); - pc.printf("Sensor FR:%f \n",sensFR); + pc.printf("Sensor FR:%f \n",sensFR); pc.printf("Sensor FL:%f \n",sensFL); pc.printf("Sensor R:%f \n",sensR); pc.printf("Sensor L:%f \n",sensL); @@ -170,7 +181,7 @@ //-------------------------------------------------------------------------- void adjust(){ fS=0; // set low speed - while(abs((sensFR-DISFR)-(sensFL-DISFL))>4){ // do adjustment when difference of sensor value larger than threshold(20) + while(abs((sensFR-DISFR)-(sensFL-DISFL))>0.4){ // do adjustment when difference of sensor value larger than threshold(20) if ((sensFR-DISFR)>(sensFL-DISFL)) { modeR=2; modeL=1; // turn right } else { @@ -186,7 +197,7 @@ void slow_start(){ fS=0; // set low speed modeR=modeL=1; // set mode for run forward - cntR=0; stepR=20; // run 20 step at low speed + cntR=0; stepR=STEP0; // run 20 step at low speed while (cntR<stepR); } @@ -196,7 +207,7 @@ void run_step(){ slow_start(); fS=1; // change to high speed - cntR=0; stepR=STEP1-20; + cntR=0; stepR=STEP1-STEP0; while (cntR<stepR); run_break(); } @@ -298,7 +309,7 @@ // go forward and detect walls wS=0; wF=0; wR=0; wL=0; // reset of wall flags slow_start(); // slow start - stepR=STEP1; + stepR=STEP1-STEP0; fS=1; // change high speed while (cntR<stepR){ // go forward if (cntR > (STEP1*2/3) && wS==0){ // wall detection when the mouse run 2/3 step of area @@ -310,7 +321,7 @@ } // go forwrd to adjust distanse of front wall, when exit the above loop by front wall detection. - if (wF==1){ + if (wF==1){ while (sensFR<DISFR); // go forward to have normal distance to front wall adjust(); // adjustment by front wall } @@ -352,7 +363,7 @@ // write steps to smap from goal position // goal position set to m=1, find same value of m in smap and put m+1 to no wall direction, increment of m, // go out roop when reach to stat position. - smap[7][7]=1; smap[7][8]=1; smap[8][7]=1; smap[8][8]=1; // goal position set to 1 + smap[7][7]=1; smap[7][8]=1; smap[8][7]=1; smap[8][8]=1; // goal position set to 1 m=1; // set m=1 for(k=0;k<255;k++){ // repeat maximun 255 times for(i=0;i<16;i++){