Society of Robots - Robot Forum
Electronics => Electronics => Topic started by: ozbot on December 15, 2008, 03:53:27 AM
-
Now I have greased up the gears and attempted to use the first tutorial program. What i've found is that I can only seem to get one direction of rotation. Am using these lines to test servo:
i=250;
while (i>0)
{
servo_left(x);
i--;
}
Between 40 & 44 in the "servo_left(x)" will give me varying speed, but if I go below 40, instead of a direction reversal, the gears just click slightly forward & back continuosly. This behavior is on both the left and right servo's. I have not attempted to send PWM by the 1, 1.5, 2 ms, as I do not yet know the code for that. I have inspected the gear assebly & there are no physical/gearing problems.
I had replaced the 5K feedback pots (as they were crap quality, lots of drift) with a 2K2 either side as a voltage divider. If that didnt balance it, I would still be able to forward and back my servo in an offset range, no?
I have had one wheel spontaneously start rotating in the unusable direction once, when not even referred to! that might indicate a (sporadic) wiring problem, but have gone over it twice now.
Am using an ATMEL ATmega8, have tried 2 different micro's & same results. Kinda hopin I missed somethin obvious, this is drivin me nuts.......
-
i=250;
while (i>0)
{
servo_left(x);
i--;
}
You probably realized this by now, but x doesn't change in that code. Change x to i ;D
Also, make it go from about 10 to 80, and add a delay in it. Otherwise the code will be finished in a fraction of a second.
-
Try this code I wrote:
#include <avr/io.h>
#include <util/delay.h>
int main()
{
int i;
DDRB = 0xff;
PORTB = 0xff;
while(1)
{
//Hold the motor in neutral for 2 seconds (Each signal is 20ms, so repeating that 100 times = 2000 sec
for(i=0;i<101;i++)
{
PORTB = 0xff;
_delay_ms(1.5);
PORTB = 0x00;
_delay_ms(18.5);
}
//Turn 90deg clockwise for 2 sec
for(i=0;i<101;i++)
{
PORTB = 0xff;
_delay_ms(2);
PORTB = 0x00;
_delay_ms(18);
}
//Turn to -90deg ccw, while passing the neutral state for 2 sec
for(i=0;i<101;i++)
{
PORTB = 0xff;
_delay_ms(1);
PORTB = 0x00;
_delay_ms(19);
}
}
return 1;
}
Connect the servo control wire to any pin in PORTB.
-
"You probably realized this by now, but x doesn't change in that code. Change x to i"
sorry, shoulda been more clear, was testing by putting 44, then 43, 42.... where x is.
anyways, twas a bad servo (mg995=fail) ......replaced it (hobbytech m-2763) and now have my first functional photovore.
I think I put to much heat on the servo control board while soldering on the resistors.
thx all.