Automous Code?

I was wondering if anyone had some basic automous code I could look at to start us off with something

Links are great


pwm1 = 255;
pwm2 = 255;

that will drive you forward will the end of time.

We have some done in EasyC last year.

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;

case 1:
pwm01=pwm02 = 255; //drives pwm01 and pwm02 forward.
if(timeCounter >= 100)
case 2:
pwm01=pwm02= 127;//stop pwm01 and pwm02.

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.

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)

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.