Servo Chatter

When I initialize my robot, the starboard (right-hand) servo chatters at the neutral position. As you can see from the video, for some reason this affects only the starboard servo and not the port (left-hand) servo. I think the reason has something to do with the manual adjustment not being centered.

Anyhow, rather than carefully tweak the servos manually, there is another way to avoid needless chattering. And that is to modify the servo attachment commands in the Arduino sketch.

What I was doing before was placing the servo attachment commands in the setup function, like so:

void setup(){

myservo1.attach(11);
myservo1.write(90);

myservo2.attach(10);
myservo2.write(90);

The solution is to place the servo attachment commands in the loop() function just before the action function and then place servo detach commands immediately thereafter, like so:

void loop(){

if (rmode == 1) {
servo_on();
act_mode2();
servo_off();
rmode = 0;

. . . where servo_on() attaches the servos as before and servo_off detaches like so:

void servo_off(){

myservo1.detach();
myservo2.detach();

}

By attaching the servos just before they’re used and detaching them immediately thereafter, I am minimizing the time the servos can chatter. In other words, servos can only chatter when they’re attached.

Note that when using the servo detach() command, the pin number is not expressed. That’s because the servo object remembers which pin it was assigned to by the attach() command. If you put a pin number in the detach() parens, you won’t just be making extra work for yourself, you’ll generate a compiler error message (as I learned to my puzzlement for several minutes).

Advertisements

About engineerzero

Once and future engineer.
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s