Author Topic: Can I modify this code to make an obstacle avoidance robot pause for a minute  (Read 2593 times)

0 Members and 1 Guest are viewing this topic.

Offline aluminumwelderTopic starter

  • Beginner
  • *
  • Posts: 4
  • Helpful? 0
http://www.billporter.info/2010/02/03/irobot-create-force-field-obstacle-avoidance/

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!

Offline jkerns

  • Robot Overlord
  • ****
  • Posts: 270
  • Helpful? 12
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();
}
else
{
speed = normalspeed();
increment timer if you have to
}

Or something like that.
I get paid to play with robots - can't beat that with a stick.

http://www.ltu.edu/engineering/mechanical/bachelor-science-robotics-engineering.asp

Offline aluminumwelderTopic starter

  • Beginner
  • *
  • Posts: 4
  • Helpful? 0
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
http://www.societyofrobots.com/axon/axon_function_list.shtml#timers
Code: [Select]
     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
    elapsed_time=timer0GetOverflowCount()*255+TCNT0;

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

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

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

Offline jkerns

  • Robot Overlord
  • ****
  • Posts: 270
  • Helpful? 12
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).
I get paid to play with robots - can't beat that with a stick.

http://www.ltu.edu/engineering/mechanical/bachelor-science-robotics-engineering.asp

 


Get Your Ad Here

data_list