![]() |
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!!! :ahh: |
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? |
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? |
Re: IR reflective (tape) sensor code problems
Quote:
You can initialize global variables and set values like so int ROAAAR = 0; I usually do Code:
void blah(void)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 topThanks, Ryan Waliany |
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?
|
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. |
Re: IR reflective (tape) sensor code problems
Thanx, Did not know that!
|
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... :D |
Re: IR reflective (tape) sensor code problems
Quote:
Code:
executing_code(); |
| All times are GMT -5. The time now is 16:54. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi