Society of Robots - Robot Forum

Software => Software => Topic started by: gamefreak on February 14, 2008, 08:06:09 PM

Title: Strange code problem
Post by: gamefreak on February 14, 2008, 08:06:09 PM
Alright, while working on a demo for my project I found something strange, all of the servos are hooked up the same way, number 4 and 5 always rotate the same direction and they are modified, numbers 1 through 3 all rotate clockwise then reset, but number 0 goes the opposite direction, the other 3 servos are hitec, while the first one is from parallax, is this what the problem is?

Code: [Select]
int i;
for(i=0;i<150;i++)
{
PORT_ON(PORTD,7);
delay_cycles(25);
PORT_OFF(PORTD,7);
delay_cycles(200);
}


while(1)
{

for(i=0;i<25;i++)
{
PORT_ON(PORTD, 0);
delay_cycles(20);
PORT_OFF(PORTD, 0);//keep off
delay_cycles(200);

PORT_ON(PORTD, 1);
delay_cycles(20);
PORT_OFF(PORTD, 1);//keep off
delay_cycles(200);

PORT_ON(PORTD, 2);
delay_cycles(20);
PORT_OFF(PORTD, 2);//keep off
delay_cycles(200);

PORT_ON(PORTD, 3);
delay_cycles(20);
PORT_OFF(PORTD, 3);//keep off
delay_cycles(200);

PORT_ON(PORTD, 4);
delay_cycles(20);
PORT_OFF(PORTD, 4);//keep off
delay_cycles(200);

PORT_ON(PORTD, 5);
delay_cycles(20);
PORT_OFF(PORTD, 5);//keep off
delay_cycles(200);
}
delay_cycles(2000);

for(i=0;i<25;i++)
{
PORT_ON(PORTD, 0);
delay_cycles(25);
PORT_OFF(PORTD, 0);//keep off
delay_cycles(200);

PORT_ON(PORTD, 1);
delay_cycles(25);
PORT_OFF(PORTD, 1);//keep off
delay_cycles(200);

PORT_ON(PORTD, 2);
delay_cycles(25);
PORT_OFF(PORTD, 2);//keep off
delay_cycles(200);

PORT_ON(PORTD, 3);
delay_cycles(25);
PORT_OFF(PORTD, 3);//keep off
delay_cycles(200);

PORT_ON(PORTD, 4);
delay_cycles(25);
PORT_OFF(PORTD, 4);//keep off
delay_cycles(200);

PORT_ON(PORTD, 5);
delay_cycles(25);
PORT_OFF(PORTD, 5);//keep off
delay_cycles(200);
}
delay_cycles(2000);

for(i=0;i<25;i++)
{
PORT_ON(PORTD, 0);
delay_cycles(30);
PORT_OFF(PORTD, 0);//keep off
delay_cycles(200);

PORT_ON(PORTD, 1);
delay_cycles(30);
PORT_OFF(PORTD, 1);//keep off
delay_cycles(200);

PORT_ON(PORTD, 2);
delay_cycles(30);
PORT_OFF(PORTD, 2);//keep off
delay_cycles(200);

PORT_ON(PORTD, 3);
delay_cycles(30);
PORT_OFF(PORTD, 3);//keep off
delay_cycles(200);

PORT_ON(PORTD, 4);
delay_cycles(30);
PORT_OFF(PORTD, 4);//keep off
delay_cycles(200);

PORT_ON(PORTD, 5);
delay_cycles(30);
PORT_OFF(PORTD, 5);//keep off
delay_cycles(200);
}
delay_cycles(2000);

for(i=0;i<25;i++)
{
PORT_ON(PORTD, 0);
delay_cycles(35);
PORT_OFF(PORTD, 0);//keep off
delay_cycles(200);

PORT_ON(PORTD, 1);
delay_cycles(35);
PORT_OFF(PORTD, 1);//keep off
delay_cycles(200);

PORT_ON(PORTD, 2);
delay_cycles(35);
PORT_OFF(PORTD, 2);//keep off
delay_cycles(200);

PORT_ON(PORTD, 3);
delay_cycles(35);
PORT_OFF(PORTD, 3);//keep off
delay_cycles(200);

PORT_ON(PORTD, 4);
delay_cycles(35);
PORT_OFF(PORTD, 4);//keep off
delay_cycles(200);

PORT_ON(PORTD, 5);
delay_cycles(35);
PORT_OFF(PORTD, 5);//keep off
delay_cycles(200);
}
delay_cycles(2000);

for(i=0;i<25;i++)
{
PORT_ON(PORTD, 0);
delay_cycles(40);
PORT_OFF(PORTD, 0);//keep off
delay_cycles(200);

PORT_ON(PORTD, 1);
delay_cycles(40);
PORT_OFF(PORTD, 1);//keep off
delay_cycles(200);

PORT_ON(PORTD, 2);
delay_cycles(40);
PORT_OFF(PORTD, 2);//keep off
delay_cycles(200);

PORT_ON(PORTD, 3);
delay_cycles(40);
PORT_OFF(PORTD, 3);//keep off
delay_cycles(200);

PORT_ON(PORTD, 4);
delay_cycles(40);
PORT_OFF(PORTD, 4);//keep off
delay_cycles(200);

PORT_ON(PORTD, 5);
delay_cycles(40);
PORT_OFF(PORTD, 5);//keep off
delay_cycles(200);
}
delay_cycles(2000);




/* Servo Test Code
i=250;
while(i>0)
{
servo_left(40);
i--;
}

i=250;
while(i>0)
{
servo_left(24);
i--;
}
*/

//rprintf("Initialization Complete\r\n");

//output message to serial (use hyperterminal)
//print("Hello, World! Read My Analog: %u\r\n", sensor_0);

//delay_cycles(500);//a small delay to prevent crazy oscillations
}
/*********ADD YOUR CODE ABOVE THIS LINE **********/

return 0;
}
Title: Re: Strange code problem
Post by: Admin on February 15, 2008, 12:16:42 PM
does the parallax servo work fine if you change the code to go the other way?
Title: Re: Strange code problem
Post by: gamefreak on February 15, 2008, 07:19:10 PM
all of the servos go to the end, then rotate back to the starting delay, although the modified servos only rotate in a single direction, the potentiometer is probably off and I dont have an oscilloscope, are there any cheap ones?
Title: Re: Strange code problem
Post by: Admin on February 16, 2008, 04:40:41 PM
You use a multimeter to measure potentiometers, not oscilloscope ;)

Anyway, assume that the parallax servos require a different square wave to operate. Just try changing the frequency and see what happens.

As for a cheaper servo, the HS-311 is always $8.99