Go to Post If people played without PDA's back when FIRST had this addiction to nigh-impossible-to-calculate-in-your-head multipliers, then we can play without PDA's now. - Ian Curtis [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 09-12-2006, 11:04
itsme itsme is offline
Registered User
FRC #2217 (FOMH)
Team Role: Programmer
 
Join Date: Dec 2006
Rookie Year: 2007
Location: Israel
Posts: 86
itsme is an unknown quantity at this point
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;
                                  }      
       }
}
And now I put the function in the main in this way:

Code:
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.

Last edited by itsme : 09-12-2006 at 11:18.
  #2   Spotlight this post!  
Unread 09-12-2006, 12:19
Donut Donut is offline
The Arizona Mentor
AKA: Andrew
FRC #2662 (RoboKrew)
Team Role: Engineer
 
Join Date: Mar 2005
Rookie Year: 2004
Location: Goodyear, AZ
Posts: 1,307
Donut has a reputation beyond reputeDonut has a reputation beyond reputeDonut has a reputation beyond reputeDonut has a reputation beyond reputeDonut has a reputation beyond reputeDonut has a reputation beyond reputeDonut has a reputation beyond reputeDonut has a reputation beyond reputeDonut has a reputation beyond reputeDonut has a reputation beyond reputeDonut has a reputation beyond repute
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.
__________________
FRC Team 498 (Peoria, AZ), Student: 2004 - 2007
FRC Team 498 (Peoria, AZ), Mentor: 2008 - 2011
FRC Team 167 (Iowa City, IA), Mentor: 2012 - 2014
FRC Team 2662 (Tolleson, AZ), Mentor: 2014 - Present
  #3   Spotlight this post!  
Unread 09-12-2006, 12:48
itsme itsme is offline
Registered User
FRC #2217 (FOMH)
Team Role: Programmer
 
Join Date: Dec 2006
Rookie Year: 2007
Location: Israel
Posts: 86
itsme is an unknown quantity at this point
Re: Question about programing the bumper sensors

Quote:
Originally Posted by Donut
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)?
  #4   Spotlight this post!  
Unread 09-12-2006, 13:11
Donut Donut is offline
The Arizona Mentor
AKA: Andrew
FRC #2662 (RoboKrew)
Team Role: Engineer
 
Join Date: Mar 2005
Rookie Year: 2004
Location: Goodyear, AZ
Posts: 1,307
Donut has a reputation beyond reputeDonut has a reputation beyond reputeDonut has a reputation beyond reputeDonut has a reputation beyond reputeDonut has a reputation beyond reputeDonut has a reputation beyond reputeDonut has a reputation beyond reputeDonut has a reputation beyond reputeDonut has a reputation beyond reputeDonut has a reputation beyond reputeDonut has a reputation beyond repute
Re: Question about programing the bumper sensors

Quote:
Originally Posted by itsme
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.
__________________
FRC Team 498 (Peoria, AZ), Student: 2004 - 2007
FRC Team 498 (Peoria, AZ), Mentor: 2008 - 2011
FRC Team 167 (Iowa City, IA), Mentor: 2012 - 2014
FRC Team 2662 (Tolleson, AZ), Mentor: 2014 - Present
  #5   Spotlight this post!  
Unread 09-12-2006, 19:59
bobmonkey836's Avatar
bobmonkey836 bobmonkey836 is offline
BobMonkey07
AKA: Jeff Powers
FRC #0836 (Robobees)
Team Role: Mentor
 
Join Date: Dec 2005
Rookie Year: 2005
Location: maryland
Posts: 39
bobmonkey836 is on a distinguished road
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.
__________________
Solution to life's problems: "CTRL", "ALT", "DELETE".
"CTRL"+"Z" Saved my life.
Approximately Normal
2007 Annapolis Regional at USNA!!

Management is doing things right; leadership is doing the right things.
- Peter Drucker
  #6   Spotlight this post!  
Unread 10-12-2006, 08:38
Kingofl337's Avatar
Kingofl337 Kingofl337 is offline
You didn't see anything....
AKA: Adam
FRC #0501 (Power Knights)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 1998
Location: Manchester, NH
Posts: 861
Kingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond repute
Send a message via Yahoo to Kingofl337
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.
__________________
FIRST Team 501 PowerKnights - Mentor
FIRST Team 40 Checkmate - Mentor Alum
FIRST Team 146 Blue Lightning - Alumni

Last edited by Kingofl337 : 10-12-2006 at 08:41.
  #7   Spotlight this post!  
Unread 10-12-2006, 12:00
Gdeaver Gdeaver is offline
Registered User
FRC #1640
Team Role: Mentor
 
Join Date: Mar 2004
Rookie Year: 2001
Location: West Chester, Pa.
Posts: 1,370
Gdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond reputeGdeaver has a reputation beyond repute
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   Spotlight this post!  
Unread 10-12-2006, 13:07
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Question about programing the bumper sensors

Quote:
Originally Posted by Kingofl337 View Post
We don't give you access to interrupts in easyC V2 for vex because we don't people stalling the microprocessor.
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
  #9   Spotlight this post!  
Unread 10-12-2006, 15:20
itsme itsme is offline
Registered User
FRC #2217 (FOMH)
Team Role: Programmer
 
Join Date: Dec 2006
Rookie Year: 2007
Location: Israel
Posts: 86
itsme is an unknown quantity at this point
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   Spotlight this post!  
Unread 10-12-2006, 18:03
Kingofl337's Avatar
Kingofl337 Kingofl337 is offline
You didn't see anything....
AKA: Adam
FRC #0501 (Power Knights)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 1998
Location: Manchester, NH
Posts: 861
Kingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond repute
Send a message via Yahoo to Kingofl337
Re: Question about programing the bumper sensors

easyC Pro and FRC does support interrupts through WPILib.
__________________
FIRST Team 501 PowerKnights - Mentor
FIRST Team 40 Checkmate - Mentor Alum
FIRST Team 146 Blue Lightning - Alumni
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 20:50.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi