Servos will not close

3 replies [Last post]
simon.ospo
Title: NooBot
Joined: 03/28/2013
Posts:
BotPoints: 5
User offline. Last seen 9 years 27 weeks ago.

We are trying to make a program that makes two microservos first open, wait three seconds, and then close.

The servos will open with no issues, but when it comes time to close they have a seizure (this really is the best way to describe it; they rapidly and erratically change directions of motion while not traveling far in either direction for a few seconds after which one will stop where it is and the other will jerk to one side; their original position is opposite one another forming perhaps a 120 degree angle before the close).
We have been using the set_servo_position command, are there any other commands to use? Do you have any other ideas on why this might not be working?

Co-Vice-President of Programming for the Medford High School Robotics Team
Yes, that is a real position.

KCotrone
Title: NooBot
Joined: 01/29/2013
Posts:
BotPoints: 38
User offline. Last seen 8 years 50 weeks ago.

Posting code would be helpful to figure out what's going on. I'm having a similar issue when running servos but I'm not having them after I have ran the robot once before. It seems like they might be initializing or something.

simon.ospo
Title: NooBot
Joined: 03/28/2013
Posts:
BotPoints: 5
User offline. Last seen 9 years 27 weeks ago.

Allright, here you go:

// Created on Mon March 25 2013

int main()
{
printf("Press B button to open. \nPress A Button to close"); //Directions for user
while (b_button()==0) {} //While B button is not pressed, do nothing
while (a_button()==0) //While a button is not use, do this...
{
printf("\nYou pressed the B button");
enable_servos(); //turn on all servos
set_servo_position(3, 1004); //Open right claw
set_servo_position(1, 900); //Open left claw
disable_servos(); //turn off all servos
}
while (a_button()!=0) //While a button is pressed
{
printf("\n You pressed A button");
enable_servos(); //turn on all servos
set_servo_position(3, 944); //Open right claw
set_servo_position(1, 1333); //Open left claw
disable_servos(); //turn off all servos
}
return 0;
}

Co-Vice-President of Programming for the Medford High School Robotics Team
Yes, that is a real position.

KCotrone
Title: NooBot
Joined: 01/29/2013
Posts:
BotPoints: 38
User offline. Last seen 8 years 50 weeks ago.

Servos will actually hold their positions if they aren't in a while loop. Calling set_servo_position gives each servo a specified position to go to. The software does nothing more and you can move on. Because of this, set_servo_position doesn't wait until the servo is in that position because the hardware on the servo takes care of that.

I haven't tested this code but I believe it should work. When opening the claw, you have to hold the a_button down.

  1. int main()
  2. {
  3. enable_servos();
  4. printf("Press B button to open. \nPress A button to close");
  5. while(!b_button()) wait until b_button is pressed
  6. msleep(10);
  7.  
  8. printf("\nYou pressed the B button");
  9. set_servo_position(3, 1004); //Open right claw
  10. set_servo_position(1, 900); //Open left claw
  11.  
  12. while(!a_button())//Wait until a_button is pressed
  13. msleep(10);
  14.  
  15. set_servo_position(3, 944); //Open right claw
  16. set_servo_position(1, 1333); //Open left claw
  17.  
  18. while(a_button())//Wait for a_button to not be pressed
  19. msleep(10);
  20.  
  21. return 0;
  22. }