Go to Post Yes, a big part of FIRST is learning from others. But a just as important part of FIRST is learning from discovery. - [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 06-02-2004, 23:23
Argoth Argoth is offline
Registered User
AKA: The Prez
#1255 (Team Blarglefish)
 
Join Date: Oct 2003
Rookie Year: 2004
Location: Texas
Posts: 41
Argoth can only hope to improve
IR reflective (tape) sensor code problems

Ummmm.... this will probably make me look really stupid, but part of my team has been playing with the EDU bot's Reflective IR sensors. I was told to program it, but I encountered a problem (why else would I be here? lol). For 15 seconds the bot is supposed to follow the line using two sensors (to eliminate the need for two seperate autonomous modes). Except my program completly skips that step and waits for 15 seconds, then goes to the bumper sensor code that is later on in the program.

/*right sensor= rc_dig_06
left sensor=rc_dig_08
bumper sensor=rc_dig_10*/

int counter=0;
short endprogram=0;

void Default_Routine(void)
{
counter++;
if((endprogram==0)&&(counter<900))
{
if((rc_dig_in06 !=0)&&(rc_dig_in08 !=0))/*if light is seen*/
{
pwm01=pwm03=255; /* turn left motors on */
pwm02=pwm04=0; /* turn right motors on*/
}
else if(rc_dig_in06 == 0) /* if dark is seen */
{
pwm01=pwm03=127; /* turn left motors off */
pwm02=pwm04=67; /* turn right motors forward slowly */
}
else if(rc_dig_in08 == 0) /* if dark is seen */
{
pwm01=pwm03=187; /* turn left motors forward slowly */
pwm02=pwm04=127; /* turn right motors off */
}
}


Can anyone tell me my problem?? PLEASE!!!
__________________
BEWARE OUR ROBOT, It has serious anger issues. Prone to attack whatever is infront of it randomly! Tried to cut our sponsors jugular!

"A common mistake that people make when trying to design something completly foolproof was to underestimate the ingenuity of fools." ~Douglas Adams~
  #2   Spotlight this post!  
Unread 07-02-2004, 00:11
Random Dude Random Dude is offline
Oregon State Head FTA
AKA: Chris
no team (Oregon Robotics Tournament & Outreach Program)
 
Join Date: Aug 2002
Rookie Year: 1998
Location: Oregon
Posts: 142
Random Dude will become famous soon enoughRandom Dude will become famous soon enough
Re: IR reflective (tape) sensor code problems

Side note: use the [code] tag to keep formatting of you code.

On topic, the code seems fine. Are you sure you not doing something silly like reinitalizing the pwm outpus to 127 someplace further on?
  #3   Spotlight this post!  
Unread 07-02-2004, 00:55
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: IR reflective (tape) sensor code problems

where are you declaring "counter" and "endprogram"? if they are outside a function, you probably need to initialize them somewhere else (i.e. don't put the =0 part in, instead assign them the value of 0 in User_Initialization or somewhere there).

if they are in the function, add "static" in front of "int", so that it reads "static int counter" and "static short endprogram" - you don't want the values reset every time the function is called.

it does seem that the counter is working at least somewhat decently, though, as it is waiting for 15 seconds... could you post the code that comes after the IR part?
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #4   Spotlight this post!  
Unread 07-02-2004, 02:00
rwaliany's Avatar
rwaliany rwaliany is offline
R
None #0691 (HartBurn)
Team Role: Programmer
 
Join Date: Jan 2003
Rookie Year: 2000
Location: http://www.hartrobot.com
Posts: 137
rwaliany will become famous soon enough
Re: IR reflective (tape) sensor code problems

Quote:
Originally Posted by deltacoder1020
where are you declaring "counter" and "endprogram"? if they are outside a function, you probably need to initialize them somewhere else (i.e. don't put the =0 part in, instead assign them the value of 0 in User_Initialization or somewhere there).

if they are in the function, add "static" in front of "int", so that it reads "static int counter" and "static short endprogram" - you don't want the values reset every time the function is called.

it does seem that the counter is working at least somewhat decently, though, as it is waiting for 15 seconds... could you post the code that comes after the IR part?
Their code is correct..

You can initialize global variables and set values like so
int ROAAAR = 0;

I usually do
Code:
void blah(void)
{
  static int x = 0; 
}
though.

Personally, I recommend keeping the programming port connected and having a debug statement every 10 loops showing the values of PWMs, etc...

sample
Code:
// Paste top
//in the code, comment out to turn off debug
#define DEBUG_ALL

#ifdef DEBUG_ALL
unsigned int _debug_counter = 0;  // 0-65535 then rollover
#define debug_all(pulses, type)                                                            \
      {                                                                                    \
         if (_debug_counter % pulses == 0)                                                 \
         {                                                                                 \
            switch(type)                                                                   \
            {                                                                              \
            case 1:                                                                        \
               printf("PWM01 = %d, PWM02 = %d...\n", pwm01, pwm02);                        \
               break;                                                                      \
            case 2:                                                                        \
               printf("PWM03 = %d, PWM04 = %d...\n", pwm01, pwm02);                        \
               break;                                                                      \
            case 3:                                                                        \
               printf("rc_dig_out01 %d, rc_dig_out02.\n",                                  \
	       (int)rc_dig_out01, (int)rc_dig_out02);                                      \
               break;                                                                      \
	    default:                                                                       \
	       printf("Invalid type.\n");                                                  \
            }                                                                              \
         }                                                                                 \
      }
#else
#define debug_all(pulses, type) \
   { \
   }
#endif
// End paste top


// every loop call
void Process_Data_From_Master_uP(void)
{
  Getdata(&rxdata); /* Get fresh data from the master microprocessor. */
+ #ifdef DEBUG_ALL
+    _debug_counter++;
+ #endif
  //blah...

//code to call debug_all(numloops, type)
+   debug_all(10, 1);
+   debug_all(100, 2);
+   debug_all(50, 3);
}
That works for me. I like this approach because it doesn't waste memory when DEBUG_ALL is not defined, the code is not compiled in when DEBUG_ALL is set. I'll probably tie into the standard debugging and make the default code's debugging more efficient later. When your running the code even while not debugging, the default code has debugging built in and compiled wasting memory. I decided to post this because it shows a lot of the macro capabilities allowing you to emulate reference variables to a degree.

Thanks,
Ryan Waliany
__________________
R

Last edited by rwaliany : 07-02-2004 at 02:05.
  #5   Spotlight this post!  
Unread 07-02-2004, 20:33
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: IR reflective (tape) sensor code problems

Excuse me, but what are the slashes at the end of lines and the plus at the begining?
  #6   Spotlight this post!  
Unread 07-02-2004, 20:39
steven114 steven114 is offline
Programming Wizard and Team Captain
AKA: Steven Schlansker
FRC #0114 (Eaglestrike)
Team Role: Programmer
 
Join Date: Feb 2004
Location: Los Altos, CA
Posts: 335
steven114 is a jewel in the roughsteven114 is a jewel in the roughsteven114 is a jewel in the rough
Send a message via AIM to steven114
Re: IR reflective (tape) sensor code problems

The pluses indicate that the line has been added to the code based on the previous version (he added lines where there already were some)

The slashes tell the preprocessor to keep looking on the next line, so that

#define HI 3\
4

looks like
#define HI 3 4

to the preprocessor.
  #7   Spotlight this post!  
Unread 07-02-2004, 21:09
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: IR reflective (tape) sensor code problems

Thanx, Did not know that!
  #8   Spotlight this post!  
Unread 07-02-2004, 21:29
Argoth Argoth is offline
Registered User
AKA: The Prez
#1255 (Team Blarglefish)
 
Join Date: Oct 2003
Rookie Year: 2004
Location: Texas
Posts: 41
Argoth can only hope to improve
Re: IR reflective (tape) sensor code problems

I am very stupid. I took my code to the meeting today and let one of the other programmers look at it to see if there was anything wrong in the code I wrote. There wasn't . Mid way up between default routine and beginning of the program there was and extra slash causing some commenting to become uncommented. Suprisingly it kept compiling with no errors!(that was what was really confounding us) So, we fixed it and I thank ya'll for helping.

Ps. I think I am probably the first person who has ever caused an error in the robot with the commenting...
__________________
BEWARE OUR ROBOT, It has serious anger issues. Prone to attack whatever is infront of it randomly! Tried to cut our sponsors jugular!

"A common mistake that people make when trying to design something completly foolproof was to underestimate the ingenuity of fools." ~Douglas Adams~
  #9   Spotlight this post!  
Unread 07-02-2004, 21:32
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: IR reflective (tape) sensor code problems

Quote:
Originally Posted by Argoth
I am very stupid. I took my code to the meeting today and let one of the other programmers look at it to see if there was anything wrong in the code I wrote. There wasn't . Mid way up between default routine and beginning of the program there was and extra slash causing some commenting to become uncommented. Suprisingly it kept compiling with no errors!(that was what was really confounding us) So, we fixed it and I thank ya'll for helping.

Ps. I think I am probably the first person who has ever caused an error in the robot with the commenting...
Hate to disapoint you, but probably not:
Code:
executing_code();
/* commented_out_code();
/*some comment 
about code that's
commented out*/
STILL_RUNNING();*/
Of course, all the veterens mention this to the rookies, so not recently.
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
Trade retro reflective tape sanddrag Technical Discussion 0 07-02-2003 19:53
reflective tape esellers Technical Discussion 8 22-01-2003 19:10
Reflective tape on boxes S2Taz General Forum 1 20-01-2003 17:24
How is reflective tape applied to HP crates? Dr.Bot General Forum 2 06-01-2003 15:17
Substitutes for reflective tape? Oakridege_665 Technical Discussion 1 23-01-2002 11:44


All times are GMT -5. The time now is 10:12.

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