Software > Software

Can I modify this code to make an obstacle avoidance robot pause for a minute



this is almost the code I need for my project. However I need the robot to pause for a minute every 10 or so feet of movement so that it can take photos. I will have an automatic camera unit called the sony snapshot mounted on top.

Does anyone know how to modify it? you can click on the link that says
Download Source
on the above web site.

I can build the thing no problem, however my programming skills suck!

mode = 1; // go mode

if (mode == 1) && (time > whatever)
time = 0;  // restart (however a timer works on your device. You will have to look that up yourself)
mode = 0; // stop mode
speed = 0; // stop
else if (mode == 0) && (time < somethingelse) // still waiting
speed = 0;  // sit and wait
increment time if you have to
else if (mode == 0)  / timed out
time = 0; //restart timer
mode = 1; // go mode
speed = normalspeed();
speed = normalspeed();
increment timer if you have to

Or something like that.

Thanks for the reply. Unfortunately even with that great outline I have no idea how to fix the code. I looked up the Axon 2 microcontroller and it has the following timers

--- Code: ---     Timer Error:
    The Axon clock has a typical 5.8% error from real time. For example, programming a 1 second delay would actually result in a 0.942 second delay.

    The Axon has 6 timers with resolution as follows: 16-bit Timers on 1,3,4,5 8-bit Timers on 0, 2

    To initialize a timer:

    timer0Init(); //initialize the timer0 system
    timer2Init(); //initialize the timer2 system

    To reset the timer and overflow counter:

    //clears timer, reset overflow counter
    reset_timer_0();//reset timer 0
    reset_timer_2();//reset timer 2

    To retrieve timer value:

    //read timer0's overflow counter
    //255 is count before overflow, dependent on clock

Avoid using the same timer to perform multiple actions such as PWM, interrupts, and timing simultaneously.
--- End code ---

this sample code you wrote, what file would I add it to and where? at the beginning
the file names are
hardware.h &

I'd be willing to pay you for your time to get the code correct!
Thanks again!

It would go into whatever file has your "main" in it - that's where the line following code will be that determines your speed. it will be a .c file.

Looks like you would call the function timer0Init(); every time you want to reset the timer.

And you would call elapsed_time=timer0GetOverflowCount()*255+TCNT0 to get the elapsed time while  you are waiting (or moving).


[0] Message Index

Go to full version