If some one sees a flaw, PLEASE tell me, the Canadian Regional is on Wednesday.
One more thing… I attached a screenshot of where I placed the counter (in the user instalizationz). I this the right spot?
Don’t think so. Instead, put it in the same function that your code above is in (where is that, BTW?) And make sure it’s static:
static int count = 0;
And don’t forget to increment count somewhere in the function. I can’t tell you how many times I wrote code like this and pulled my hair out trying to find the bug, which turned out to be that I had forgotten to increment the counter:
count++;
Another thing: What are those count values? 1000? 1005? You comment that
/* Hey! There are 3435 loops in 15 minutes */
but you must mean seconds, not minutes. But there are only about 570 loops in 15 seconds (38 * 15). And how long were you planning to run the arm? 1005 - 1000? That’s only 5 cycles, or about 0.13 second. I doubt you’d even see it move! Especially since autonomous would be over 11 seconds before it is scheduled to start.
Let’s say you want to start the arm after 12 seconds and run it for 2 seconds. Change “1000” to “456” (38 * 12) and “1005” to 532 (38 * (12+2) ).
Does that make sense?
I take it that this is a line-following routine, and the three inputs are three line sensors(?). Consider that your timing test
else if (count > 1000){
will only be tested if all of the preceding tests fail. So if any of the sensors sees something, it will prevent the arm from ever running.
How about wrapping the tests on the sensors inside an “if” statement so that they only run if the time is not yet up to a certain point:
if ( count < 456 ) // still less than 12 seconds have elapsed
{
// all the if's for the sensors go here
}
else if ( count < 532 ) // 12 seconds have gone by, but less than 14
{
// stop wheels
pwm13 = 127;
pwm15 = 127;
// raise arm
pwm3 = 175; // I think it's pwm03, not pwm3. check it.
}
else
{
// stop raising arm
pwm3 = 127; // I think it's pwm03, not pwm3. check it.
}
BTW, your algorithm (for line following?) seems to have a case where it will stop the motors:
if (rc_dig_in01 == 0 && rc_dig_in02 == 0 && rc_dig_in03 == 0)
{
pwm13 = 127;
pwm15 = 127;
}
Does that mean, “if you don’t see the line at all, stop.”? How will it ever find the line again? I’m probably not understanding what the sensors do.
-norm