go_away

Author Topic: delay function  (Read 2944 times)

0 Members and 1 Guest are viewing this topic.

Offline ert481Topic starter

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 0
  • yo young?
delay function
« on: August 07, 2008, 10:19:35 AM »
$50 robot

with the C code,  delay_cycles();

does the robot go forward and then when delay runs out it goes to the next thing?

or does the delay pause everything and when it runs then go to the next thing?

i want it to do the first thing that i said but when i program it it seems like it does the second thing i said.

if it does the second thing can you tell me how to make it do the first thing i said?   ::)

thanks
young people can build robots to!!!

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,430
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
Re: delay function
« Reply #1 on: August 07, 2008, 11:14:20 AM »
its emulating a pulse width required by the servos.

there is a PWM channel on the avr, but to make life simpler we just bring the voltage high on that pin, wait, then bring it low. thats a pulse width.

+5vdc being high, 0vdc being low.
« Last Edit: August 07, 2008, 11:15:20 AM by pomprocker »

Offline ert481Topic starter

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 0
  • yo young?
Re: delay function
« Reply #2 on: August 07, 2008, 11:55:32 AM »
i get it but it doesn't answer the question i asked
« Last Edit: August 07, 2008, 11:59:26 AM by ert481 »
young people can build robots to!!!

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,430
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
Re: delay function
« Reply #3 on: August 07, 2008, 12:06:12 PM »
you need to put your C code example in context with the rest of the code in order for me to tell whats its doing so i can help you.

You use the button above marked with the pound sign (#) to post code.
« Last Edit: August 07, 2008, 12:14:32 PM by pomprocker »

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,430
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
Re: delay function
« Reply #4 on: August 07, 2008, 12:14:11 PM »
the delay function does a decremented count. to get your robot to go foward you would have to put it in a nested loop


Code: [Select]

while(1) {
     unsigned int i;

     for (i = 0; i < 500; i++)
          robot_go_straight();

}  // end while loop






that would make your robot go forward for a count of 500 cycles then go on to the next thing, but in my example there is no next thing so the while loop would start again and it would go forward another 500 cycles again and again.

« Last Edit: August 07, 2008, 12:18:10 PM by pomprocker »

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
Re: delay function
« Reply #5 on: August 07, 2008, 12:49:42 PM »
There is no technical difference between the cases you specified:
a)does the robot go forward and then when delay runs out it goes to the next thing?
b)or does the delay pause everything and when it runs then go to the next thing?

because you set pin outputs, the delay pauses everything, and when the delay runs out, it resumes. "go forward" is relative to that code. it may either set a pin, create a servo signal, etc.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,663
  • Helpful? 169
    • Society of Robots
Re: delay function
« Reply #6 on: August 09, 2008, 07:56:28 AM »
The delay_cycles(); pauses everything, as in nothing changes.

Offline ert481Topic starter

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 0
  • yo young?
Re: delay function
« Reply #7 on: August 09, 2008, 02:47:01 PM »
pomprocker, how would i add two things? can you give me the C code for that? do i do a whole nother while loop or put it in the same loop?  :)
young people can build robots to!!!

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,430
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
Re: delay function
« Reply #8 on: August 09, 2008, 04:22:39 PM »
when doing embedded programming, you always have to put your main code inside an infinite loop. whether it be
Code: [Select]
while (1){}
or
for (;;){}

because unlike a computer program which ends, and embedded program should never end until your flip the power switch to off.


Here is some code that would theoretically make it do something and wind up where it started

Code: [Select]

void main {

while(1) {
     unsigned int i;

     for (i = 0; i < 500; i++)
          robot_go_straight();

     for (i=0; i < 500; i++)
          robot_go_back();

}  // end while loop
}  // end main




You would have to add the robot_go_back function in SoR_Utils.h.
Just copy robot_go_straight and paste it. Change the name and reverse the values in servo left and right.
« Last Edit: August 09, 2008, 04:26:37 PM by pomprocker »

Offline ert481Topic starter

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 0
  • yo young?
Re: delay function
« Reply #9 on: August 09, 2008, 06:10:21 PM »
thanks ill try it if it doesn't work ill hollar
young people can build robots to!!!

Offline ert481Topic starter

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 0
  • yo young?
Re: delay function
« Reply #10 on: August 10, 2008, 04:23:59 AM »
i tried it and it failed. these are the errors i get.

Photovore_v1.c:54: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token

Photovore_v1.c:72: error: expected declaration or statement at end of input
young people can build robots to!!!

Offline ert481Topic starter

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 0
  • yo young?
Re: delay function
« Reply #11 on: August 10, 2008, 05:38:07 AM »
hey i got it to work. i just took out: void main  and it worked (yeah) :D
young people can build robots to!!!

 


Get Your Ad Here

data_list