Question about programing the bumper sensors

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.

If you were programming using C code, I believe you can hook up any digital sensor to an interrupt port and cause it to trigger an interrupt upon a certain state. However, I don’t think this is possible using EasyC, though I could be wrong.

Likewise, if you have access to it (I don’t know, haven’t used EasyC in a while), putting a command to read the sensor input into the fast loop as opposed to the main one will read as fast as possible with other code executing, which may be fast enough for what you need.

Unfortunately, I don’t think either of those options will work using EasyC.

In which loop did you mean to put the sensor input read? And by saying the sensor input read did you mean the function that I made: Get_Sensor_Data(Sensor_Port)?

It can be the function you made, or it can just be checking the value of the port directly, either is fine.

The loop I was referring to is Process_Data_From_Local_IO(), also known as the “fast loop”, which can be edited in user_routines_fast.c I don’t know if there is a way to edit it in EasyC.

i don’t think easy c has an option like that, however what easy c gives the robot is a hex file. if you can find a program to work with hex files, it might work.

easyC doesn’t have a fast loop and a slow loop. Instead you program executes as fast as the processor can run it. Using a button on a interupt probably wouldn’t get you anywhere.

When you do this:

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;
                          }

The code is probably looping in less then a ms.

Things to remeber when you write any code with high accuracy. MPLAB or EasyC Printing to screen kills your loop speed.
I don’t know the size of rest of your code but as long as you don’t have any prints or waits its probably cycling very fast. < 10ms

Lasty I think I would use a timer instead of a counter and keep reseting it.

We don’t give you access to interrupts in easyC V2 for vex because we don’t people stalling the microprocessor.

Also, remember that no matter how fast the loop is or how fast you catch an interrupt, the user to master proc communications only happen on a tens of ms scale. This means that you can only affect a change to a vector every 10 - 20 ms. I forget the timing of the master interrupt in easy-c. I think it’s different than the Mplab default code.

That’s probably a good decision for somthing named “easyC”, though I usually prefer to follow a different philosophy:

“UNIX was not designed to stop its users from doing stupid things, as that would also stop them from doing clever things.” – Doug Gwyn

First of all, thank you very much for the information, it realy helped me:)
Second of all, would you recommend me to use some program that can hanlde hex files? I mean, if it’s even less than a 1 milisecond loop then I don’t think it’s so essential.

easyC Pro and FRC does support interrupts through WPILib.