Hello everyone!
Recently I was appointed to be one of the programers in our team. This is my first time I’m in FIRST. I have been learning a bit how to use EasyC and for now it’s easier than I thought. Our school got first the Vex robot to practice on it till the larger robot comes. But I have one question: does the bumper sensor have an option to make it as an interrupt?
I’m asking this because I want to do a simple task for the robot: the robot has 2 bumper sensors, one on the front and one on the back. I want to program it to do the following: if the front bumper is pressed, then go backwards for 500 miliseconds and then turn for 500 miliseconds (about 90 degrees). But if the back bumper is pressed while doing so, I want it to drive back forward. For now, I didn’t know if the bumper sensor has the option to be an interrupt, so I programed it in the following, inelegant way:
void Bumper(void)
{
int counter;
Get_Bumper_Data(Front_Bumper_Port) /*puts the data from the front bumper into a global varaible named Front_Bumper_Data*/
if(Front_Bumper_Data==0) //if front bumper is pressed
{
Drive(255,0); /*this function makes the motors run, in this case it drives back*/
counter=0;
while(counter<=50) //while the robot is driving backwards
{
Get_Bumper_Data(Back_Bumper_Port) /*puts the data from the back bumper into a global varaible named Back_Bumper_Data*/
if(Back_Bumper_Data==0) //if back bumper is pressed
{
break;
}
wait(10);
counter=counter+10;
}
Get_Bumper_Data(Back_Bumper_Port)
if(Back_Bumper_Data==1) //if back bumper is not pressed
{
Drive(255,127)//turns
counter=0;
while(counter<=50)
{
Get_Bumper_Data(Back_Bumper_Port)
if(Back_Bumper_Data==0)
{
break;
}
wait(10);
counter=counter+10;
}
}
}
And now I put the function in the main in this way:
void main(void)
{
while(1) //infinitive loop
{
Drive(0,255) //drives forwoard (it is a function I made)
Bumper();
}
}
My question is: isn’t there any other more elegant way to do this? I mean, I did the while loop because thats the only way I found how to check every little part of time if the back bumper was pressed. If the back bumper has the interrupt option then it could be a lot easier. So if it does, can someone tell me how to do it?
p.s. sorry about my English.