![]() |
Delay code isn't delaying.
1 Attachment(s)
I'm working with Kevin Watson's 3.0 compatible FRC framework. I have code in the begining of my Autonomous() function that should cause the robot to wait, based on a few constants defined in Autonomous.h. It doesn't seem to work, and just takes off immediately. Could it have something to do with the fact that the field control system spends a moment in teleop before jumping to autonomous in the begining?
I attached a .zip archive with my entire workspace. Thank you for helping. -Guy Davidson |
Re: Delay code isn't delaying.
Might it have something to do with this line in autonomous.h?
Code:
#define WAITING_TIME 0 |
Re: Delay code isn't delaying.
That line is commented out as part of this block:
Code:
/*Code:
#define LOOPS_IN_A_SECOND 38 |
Re: Delay code isn't delaying.
I didn't think the preprocessor cared about comment lines. Are you getting any compiler errors or warnings about trying to redefine a symbol?
|
Re: Delay code isn't delaying.
Nope. No errors or warnings what-so-ever, as far as I can see.
|
Re: Delay code isn't delaying.
The best thing to do for delays is make a counter that does everything. Here is a few lines that I used for our robot in the Tacoma Regional:
int timer = 0; if(timer < 72) /* 72, if I remember right, is about 2 seconds, this number can be adjusted however you need it to be */ { timer ++; } else { // This is where the remainder of autonomous functions occured } |
Re: Delay code isn't delaying.
It cycles 40 times a second right? So you can just make a function that returned i / 40 so you can say if(timer < 2) which would be the actual amount of seconds. I know it's basic math to just multiply by 40, but it makes the code a little more readable for someone that doesn't know that.
|
Re: Delay code isn't delaying.
That's pretty much what I have there.
|
Re: Delay code isn't delaying.
Quote:
|
Re: Delay code isn't delaying.
It's in autonomous.c in the attached archive. Since it's also based on stuff in autonomous.h, I left it in an archive. Would it help if I copy both .c and .h here?
|
Re: Delay code isn't delaying.
The only thing I can think of now is changing this:
if(auton_counter < WAITING_TIME * LOOPS_IN_A_SECOND) to this: if(auton_counter < (WAITING_TIME * LOOPS_IN_A_SECOND)) Maybe try printing out WAITING_TIME and LOOPS_IN_A_SECOND and see what it's outputting. |
Re: Delay code isn't delaying.
What does your debug statement say for the value of counter?
|
Re: Delay code isn't delaying.
The code is fairly confusing for me as to what you are trying to do. The way I learned programming makes this very hard to read, no offense. I just can't figure out what is wrong with it.
|
Re: Delay code isn't delaying.
Quote:
I don't remember who said it, but I agree with the philosophy that says a programmer's job is to write documentation that compiles into a working program. |
Re: Delay code isn't delaying.
Quote:
|
Re: Delay code isn't delaying.
Quote:
|
Re: Delay code isn't delaying.
It looks like you might be being bitten by C18's habit of doing single byte arithmetic. In your if statement cast WAITING_TIME and LOOPS_IN_A_SECOND to int.
For example: if(auton_counter < (int) WAITING_TIME * (int) LOOPS_IN_A_SECOND){ //wait C18 is most likely currently treating them as single byte numbers - so 8 x 38 is 304, which overflows to become 48. (Which would only give you about a 1 second wait.) |
Re: Delay code isn't delaying.
Quote:
|
Re: Delay code isn't delaying.
I know this sound trivial, and it "should" work the way you have it, but....
Try changing Code:
if(auton_counter < WAITING_TIME * LOOPS_IN_A_SECOND)Code:
if(auton_counter << (WAITING_TIME * LOOPS_IN_A_SECOND)) |
Re: Delay code isn't delaying.
Quote:
|
Re: Delay code isn't delaying.
Quote:
|
Re: Delay code isn't delaying.
Quote:
Code:
if(auton_counter < WAITING_TIME * LOOPS_IN_A_SECOND){ //waitCode:
if (auton_counter < WAITING_TIME * LOOPS_IN_A_SECOND)If you prefer terseness, here is a common idiom for such counters: Code:
if (auton_counter++ < WAITING_TIME * LOOPS_IN_A_SECOND) |
Re: Delay code isn't delaying.
Quote:
Quote:
|
Re: Delay code isn't delaying.
Since integer promotion isn't enabled by default, and those preprocessor macros are effectively just search-and-replace, the calculations would not give the expected result. Casting them correctly and using parentheses generously should fix this, as previously stated.
|
| All times are GMT -5. The time now is 20:23. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi