|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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: Code:
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;
}
}
}
Code:
void main(void)
{
while(1) //infinitive loop
{
Drive(0,255) //drives forwoard (it is a function I made)
Bumper();
}
}
p.s. sorry about my English. Last edited by itsme : 09-12-2006 at 11:18. |
|
#2
|
||||
|
||||
|
Re: Question about programing the bumper sensors
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. |
|
#3
|
|||
|
|||
|
Re: Question about programing the bumper sensors
Quote:
|
|
#4
|
||||
|
||||
|
Re: Question about programing the bumper sensors
Quote:
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. |
|
#5
|
||||
|
||||
|
Re: Question about programing the bumper sensors
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.
|
|
#6
|
||||
|
||||
|
Re: Question about programing the bumper sensors
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. Last edited by Kingofl337 : 10-12-2006 at 08:41. |
|
#7
|
|||
|
|||
|
Re: Question about programing the bumper sensors
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.
|
|
#8
|
|||||
|
|||||
|
Re: Question about programing the bumper sensors
Quote:
"UNIX was not designed to stop its users from doing stupid things, as that would also stop them from doing clever things." – Doug Gwyn |
|
#9
|
|||
|
|||
|
Re: Question about programing the bumper sensors
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. |
|
#10
|
||||
|
||||
|
Re: Question about programing the bumper sensors
easyC Pro and FRC does support interrupts through WPILib.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Bumper sensors | jbill30 | Programming | 1 | 01-05-2006 18:49 |
| Quick question about sensors..plz help thnx | pheNIX637 | Technical Discussion | 6 | 30-10-2005 02:52 |
| Bumper sensors | jeffmorris | FIRST Tech Challenge | 1 | 02-10-2005 16:20 |
| question on the pressure pad sensors | Simon Strauss | Rules/Strategy | 5 | 08-01-2005 23:42 |
| question about one joystick drive programing | james700 | Programming | 13 | 29-01-2003 14:49 |