PDA

View Full Version : Automous Code?


Raikon
01-26-2007, 01:11 PM
I was wondering if anyone had some basic automous code I could look at to start us off with something

Links are great

THANKS IN ADVANCE!:D

Stuart
01-26-2007, 01:44 PM
pwm1 = 255;
pwm2 = 255;
while(1)
{
}

that will drive you forward will the end of time.

Chris_Elston
01-26-2007, 02:05 PM
We have some done in EasyC last year.


http://www.frcsoft.com/forums/index.php?download=11

Andrew Schreiber
01-28-2007, 09:03 PM
pwm1 = 255;
pwm2 = 255;
while(1)
{
}

that will drive you forward will the end of time.

Actually that will make the dreaded code error light turn red... I think, something about the putData() function not being called every 26.3 microseconds.

On the topic of auton code:


int autonStep = 1;
int timeCounter = 0;

switch(autonStep)
{
case 1:
pwm01=pwm02 = 255; //drives pwm01 and pwm02 forward.
if(timeCounter >= 100)
{
autonStep++;
}
break;
case 2:
pwm01=pwm02= 127;//stop pwm01 and pwm02.
break;
}

timeCounter ++;


the above code will drive the specified pwms forward for 100 fall throughs of the code. This would be put in user_routines_fast.c. Using this concept it is possible to write any autons you need. Just remember to increment that step variable so you dont get caught up. If you have pots or limit switches you can use them in your if statements too. Autons (for us at least) are usually defined by lots of if statements. Thought writing functions to do things like move arms and such makes this simpler.

ebowla
01-28-2007, 10:21 PM
I wouldn't use a switch statement for so few options, it would be cleaner with just an if() and else if() statements. Thats what I use pretty much all the time.

Damien is right about the complication of the code. It all depends on what you want it to do of course.

Oh and as a general rule, I cant think of any exceptions, you should never add any loops to the code. Ever. It causes problems. There is only the one big main() loop and thats it. There might have been another general one for automomous code, but that would be in the default code.(if is there at all, cant remember)

TimCraig
01-29-2007, 01:13 AM
Oh and as a general rule, I cant think of any exceptions, you should never add any loops to the code. Ever. It causes problems.

There's nothing wrong with using loops IF they're of deterministic length and obviously don't make your code execute longer than the 26.2 milliseconds allotted for each pass through the main loop. What you can't do is loop in while waiting for some event. If the event hasn't happened, give it up and check the next pass through the main loop.

There are many calculations that would be foolish coding without loops. CORDIC trig functions leaps to mind. But the time in the loop is deterministic.