Sorry I don't have the $50 robot, so I may not be able to fully answer this.
It is difficult to know what is going on. Is this your complete program? That is you call your servo scan function 4 times with different angles and that is it?
For your servos to work properly (assuming analog servos) you need to provide it a pulse about every 20ms. So you probably want your program to loop for a certain length of time at each pulse width. Also understand that your program tells it to go instantly from 0 to 90 degrees, it does not actually do any scanning, but jumps as fast as it can. and then you tell it to snap back... My guess is that is not really what you want and your servos will not appreciate it much.
Note: I have not verified your timings to see if they are valid, but you might try something that looks more like:
init i;
for (;;) {
for (i=200; i <=340; i++)
servo_scan(i);
for (i=340; i >=200; i--)
servo_scan(i);
}
Now assuming that each call to servo_scan takes maybe 20ms, then one scan in one direction would take about 140 calls * 20ms or about 2.8 seconds. If this is too slow, than change your increment, if too fast make a couple of calls each time...
Kurt
Thanks for the reply Kurt,
yes my approach is compleately wrong. i thought that when i command servo_scan(200); it will move to 0 position and when i command it servo_scan(278); it will move to 90 degree position and when servo_scan(325); it will move to 180 degree position. it is a totally wrong, i understood it by working on it almost 3days.
whait i want to do is move the servo to 0 degree positon then see whether some object is there using IR range finder mounted on servo. sen move the servo to 90 degee position and do the same thing. next at 180 degree position.
now im rtying with following code, it also dont move the servo perfectly but servo is now rotating some angle.
still i dont have clear idea about the values i should pass to servo_scan() function.
im using ATmega8 and configured ti use 8Mhz clock.
void servo_scan(signed long int speed)
{
PORT_ON(PORTD, 3);
delay_cycles(speed);
PORT_OFF(PORTD, 3);//keep off
//delay_cycles(1600);
//delay_cycles(371-speed);
}
void left(void)
{
servo_scan(278);
servo_scan(280);
servo_scan(282);
servo_scan(284);
servo_scan(286);
servo_scan(288);
}
void right(void)
{
servo_scan(278);
servo_scan(276);
servo_scan(274);
servo_scan(272);
servo_scan(270);
servo_scan(268);
}
void middle(void)
{
servo_scan(278);
servo_scan(278);
servo_scan(278);
servo_scan(278);
servo_scan(278);
servo_scan(278);
}
int main(void)
{
configure_ports(); // configure which ports are analog, digital, etc.
a2dInit(); // initialize analog to digital converter (ADC)
a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage
//rprintf("Initialization Complete\r\n");
/**************************************************/
/*********ADD YOUR CODE BELOW THIS LINE **********/
while(1)
{
middle();
left();
middle();
right();
delay_cycles(4000);
}
return 0;
}