Beruflich Dokumente
Kultur Dokumente
the IR Mouse //Motor functions & IR function Writen by IEEE Micromouse Team #include "16f877.h" #include "stdlib.h" #fuses HS, NOWDT, NOBROWNOUT, NOLVP #use delay(clock=20000000) #use fast_io(a) #use fast_io(b) #use fast_io(e) ///////////////////////////Input & Output Pins////////////////////////// //////////////////// Port B IR Sensors Configuration//////////////////// // Name Binary Hex Number // // Front => 0b00001000 0x08 // OuterRight => 0b01000000 0x40 // MidRight => 0b00100000 0x20 // InnerRight => 0b00010000 0x10 // OuterLeft => 0b00000001 0x01 // Midleft => 0b00000010 0x02 // InnerLeft => 0b00000100 0x04 // // Combinations // // MidMid => 0b00100010 0x22 // OutRInnL => 0b01000100 0x44 // InnROutL => 0b00010001 0x11 /////////////////////////////////////////////////////////////////////// const const const const const const const const const const const int int int int int int int int int int int Front = PIN_B3; IRight = PIN_B4; MRight = PIN_B5; ORight = PIN_B6; ILeft = PIN_B2; MLeft = PIN_B1; Oleft = PIN_B0; DirR = DirL = PstepR PstepL PIN_A0; PIN_A1; = PIN_E0; = PIN_E1; //Front Sensor //Inner Right Sensor //Midile Right Sensor //Outer Right Sensor //Inner Left Sensor //Middle Left Sensor //Outer Left Sensor // // // // Motor Motor Motor Motor Pin A0 Yellow Wire Direction F/R R Pin A1 Red Wire Direction F/R L Step Input E0 Brown Wire R Step Input E1 Blue Wire L
//////////////////////// Global Variables //////////////////////////////// int16 int16 int16 int8 int8 int8 int1 int1 int1 const const count = 0; run = 0; time = 0; Sensors = 0; Sensors1 = 0; IRData = 0; Right_Wall; Left_Wall; Front_Wall; int16 five = 5; int16 eighth = 85;
// This is 90 degree turn // This is 180 degree turn // This is 360 degree turn
/////////////////////// Motor Functions /////////////////////////////// void void void void void Right_turn(int16); Left_turn(int16); Forward(int16); Turn_around(); IR_Data();
/////////////////////// Right turn /////////////////////////////////// void Right_turn(int16 step) { delay_ms(1000); output_high(DirL); output_high(DirR); for(count=0;count<=step;count++) { output_high(PstepL); output_high(PstepR); delay_us(100); output_low(PstepL); output_low(PstepR); delay_ms(10); } }// End of Right Turn ////////////////////// Left Turn /////////////////////////////////// void Left_turn(int16 step) { delay_ms(1000); output_low(DirR); output_low(DirL); for(count=0;count<=step;count++) { output_high(PstepR); output_high(PstepL); delay_us(100); output_low(PstepR); output_low(PstepL); delay_ms(10); } }// End of Left Turn ////////////////////// Forward //////////////////////////////////// void Forward(int16 step) { for(run=0;run<=step;run++) { Sensors = input_b(); on Sensors = (Sensors&0x7F); ors
// these two line check the data // port B, which are the IR Sens
if (Sensors == 0b00100010) { delay_ms(1000); output_low(DirL); output_high(DirR); while((run<=step)&&(Sensors1 != 0x08)&&(Sensors == 0x22) ) { output_high(PstepL); output_high(PstepR); delay_us(100); output_low(PstepL); output_low(PstepR); delay_ms(10); Sensors = input_b(); k the data on Sensors1 = (Sensors&0x08); // port b, we want to look just for front IR Sensors = (Sensors&0x7F); //checks for the mid m id still exists } // end of while }//End of IF statment for MID MID Sensors = input_b(); on Sensors = (Sensors&0x7F); ors if(Sensors == 0b01000100) tion { do //Do-while loop to counter turn { Right_turn(5); time = time+5; }while(time<=eighth); // end of do-while // Start of while forwar //Start of if for OutRInnL Condi // port B, which are the IR Sens // these two line check the data
while(Sensors != 0b00100010) d loop { delay_ms(1000); output_low(DirL); output_high(DirR); output_high(PstepL); output_high(PstepR); delay_us(100); output_low(PstepL); output_low(PstepR); delay_ms(10); Sensors = input_b(); e check the data on
} on
time = time+5; }while(time<=eighth); // end of do-while // End of the OutRInnL Condition // these two line check the data // port B, which are the IR Sens
if(Sensors == 0b00010001) //START OF OUTL INNL CONDITION { time = 0; do //Do-while loop to counter turn { Left_turn(5); time = time+5; }while(time<=eighth); // end of do-while while(Sensors != 0b00100010) d loop { delay_ms(1000); output_low(DirL); output_high(DirR); output_high(PstepL); output_high(PstepR); delay_us(100); output_low(PstepL); output_low(PstepR); delay_ms(10); Sensors = input_b(); e check the data on Sensors = (Sensors&0x7F); are the IR Sensors } time = 0; do back to center? { Right_turn(5); time = time+5; }while(time<=eighth); // end of do-while // End of the OUTL INNL Condition // End of the First For Loop (Forward Loop) // END OF THE WHILE FORWARD LOOP //Do-while Counter the counter, // port B, which // Start of while forwar
///////////////////// Turn Around //////////////////////////////// void Turn_around() { delay_ms(1000); output_high(DirL); output_high(DirR); for(count=0;count<=half;count++) { output_high(PstepL); output_high(PstepR); delay_us(100); output_low(PstepL);
output_low(PstepR); delay_ms(10); } }// End of Turn Around /////////////////// IR Data Function ///////////////////////////// void IR_Data() { IRData = input_b(); port B if((IRData&&0b01110000)==0b01110000) { Right_Wall = 1; t wall bit = 1 } else { Right_Wall = 0; l bit = 0 } if((IRData&&0b00001000)==0b00001000) { Front_Wall = 1; wall bit = 1 } else { Front_Wall = 0; l bit = 0 } if((IRData&&0b00000111)==0b00000111) { Left_Wall = 1; wall bit = 1 } else { Left_Wall = 0; bit = 0 } }// End of IR data Read ///////////////////////// Main ////////////////////////////////////////////// // This is the section where the IEEE Club's implimentation of temuxas // rule is placed. This whole "function" exist in the main for // many reasons. // 1. All the control is maintained in the Main Function // 2. This allows all the Turn and Sensor data to be called by // the rule so there is no error or contention. // 3. The variables will be seperated and there will be no mix up // in the data that is collected or arranged in the main. //////////////////////////////////////////////////////////////////////////// void main() { disable_interrupts(GLOBAL); //If Right sensors detec //Reads the IR data from
// // // // //
Set IR inputs on Port B Set Motor Controls on Port A Sets port E to outputs puts port c to outputs NOT USED puts port d to outputs NOT USED
// This area is where we will have our little test run and brain code // to complet the micromouse. Right_turn(quart); delay_ms(500); Left_turn(quart); delay_ms(500); Turn_around(); delay_ms(200); Forward(Full*2); delay_ms(200); Forward(Full); }// End of the Micromouse Program.