Can someone show me a way to write a function that can delay the robot. I would like to write a function and put it in ‘user_routines.c’ and call it anywhere in my ‘user_routines_fast.c’ file. Simply I would like to:
{
pwm13 = 167;
pwm15 = 167;
delay = 100;
}
where ‘delay =’ would pause the robot for whatever time you gave it. Your help would be appreciated. What would the function look like? Thanks…
void delay(unsigned int seconds)
{
unsigned int current = 0;
while (current < (seconds * 1000) / 26.4) // Seconds * 1000 to get milliseconds and then / 26.4 millisecond loop
{
getdata(); // forget what parameter getdata takes
current++;
putdata(); // forget what parameter putdata takes..
}
}
I have no idea if that will work but you can try it…
“Stalling” execution is generally a bad idea. I would make a “loopcounter” variable, and increase the counter every time the function runs. After a certain number of loops, make it do the next thing.
I’d suggest structuring your autonomous code to run every 26ms (off the SPI data updates), tuck some timers into that, and structure you code as a state machine.
You need to be carefull with that loop, you need to call putdata and getdata every so often so the master processor doesnt shut down… i forget what the actual timeout is but its not very long…