Hay!
I got a robotic arm with 4 servos. I want it to lift some thing from the table, so I got a line of commands that control the arm. But in the middle of the command, the servos just stop being active and die. The arm goes feeble and falls down. Have any of you got any idea why?
I am using orangutan and the pololu serial adapter. The orangutan gets a signal from the computer to run the commands.
Here is my code:
void servo_move(char servo_name, int servo_begin, int servo_end)
{
if (servo_begin < servo_end)
{
int i;
for(i=servo_begin; i < servo_end; i += 10)
{
//servo_active(servo_name);
servo_set(servo_name, i);
_delay_ms(25);
}
}
else
{
int i;
for(i=servo_begin; i > servo_end; i -= 10)
{
servo_active(servo_name);
servo_set(servo_name, i);
delay_sec(1);
}
}
}
int main(){
//define the servos
unsigned char elbow, wriste, gripper, base; //variables for the servos
//unsigned int ellboe_pos = 1500, wriste_pos = 1500;
servo_init ();
elbow = servo_define (_SFR_IO_ADDR(DDRC), _SFR_IO_ADDR(PORTC), 0);
wriste = servo_define (_SFR_IO_ADDR(DDRC), _SFR_IO_ADDR(PORTC), 1);
gripper = servo_define (_SFR_IO_ADDR(DDRC), _SFR_IO_ADDR(PORTC), 2);
base = servo_define (_SFR_IO_ADDR(DDRC), _SFR_IO_ADDR(PORTC), 3);
//servo_active (elbow);
//servo_active (wriste);
//servo_active(gripper);
//end of servo define
USART_Init(MYUBRR);//Initialize USART
sei();//enable global interrupts
while(1){
if(newSerCmd){//if new byte received
switch(dataIn){
case 'a'://pick up something
servo_active(elbow);
servo_set(elbow, 1500);
delay_sec(3);
servo_active(base);
//servo_set(base, 1500);
servo_move(base, 920, 1500);
delay_sec(3);
servo_active(gripper);
servo_set(gripper, 1500);
delay_sec(3);
servo_active(wriste);
servo_set(wriste, 1800);
delay_sec(3);
servo_inactive(wriste);
servo_set(gripper, 980);
delay_sec(3);
servo_active(wriste);
servo_set(wriste,1500);
delay_sec(3);
servo_inactive(wriste);
//here the servos die....
//servo_set(base, 920);
servo_move(base, 1500, 920);
delay_sec(3);
//servo_inactive(base);
servo_set(elbow, 920);
delay_sec(3);
//servo_inactive(elbow);
servo_set(gripper, 1500);
delay_sec(3);
servo_inactive(gripper);
break;
It’s not all of the code but it’s the problematic part. I comment when the servos die at the code.
Thanks
arbel