Pages: [1] 2   Go Down
Author Topic: Servo twitch on startup  (Read 2216 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm making a remote start for my generator and I have a servo to operate the choke.  When I power my system, both the Arduino and the servo get power at the same time.  My servo gives a quick little twitch and rotates about 30 degrees.  This isn't desirable.  Everything runs off the 12V battery and the servo gets its power from a 5V BEC.  The servo is too big to run off the Arduino 5V supply.

I played around a little and I can get rid of the twitch by delaying the power to the servo.  My current solution is to manually connect the BEC after the Arduino is alive and sending a control signal to the servo.  This works, but obviously isn't a good long term solution.

Anyone else experienced this?  Any good solutions?

My current thought is to use a MOSFET to control the BEC.  I would just turn on the BEC around 200 milliseconds after the Arduino control signal is sent.  Is there some product out there that outputs 5V and can be easily turned on/off through a built in Arduino input (combined BEC and MOSFET/relay)?  I'm trying to reduce assembly time as I have to build a bunch of these.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26291
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you tried to write the servo position before the attach?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2916
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The most common thing with servos is that they twitch when power is applied. Some are
much worse than others. The GWS servos I have are especially bad.

That's if you aren't even sending pulses to the servo. Then, you have the problem that the
servo will almost never be in the exact position corresponding to the first pulse it gets, and
it will go to the commanded position at maximum speed. So, 2 uncontrollable movements,
(a) one at power up, and (b) the other with the first command pulse.

For (a), try different servos. For (b), you might use some sort of external position feedback,
such as another pot, or alternately, take advantage of the fact that servos have poor torque
when the pulses aren't coming in at a full 50-Hz rate. IOW, send the first few pulses at a slow
update rate so the servo takes a while to get over to its commanded position.







Logged

0
Offline Offline
Tesla Member
***
Karma: 143
Posts: 9598
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Any good solutions?

Posting your code might help.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the suggestions.  I had to put this away for a while, but I'm back for the weekend.

The problem is in the setup, not in the loop.  The twitch is at the myservo.attatch() and myservo.write() commands.  As AWOL suggested, I tried swapping those commands and also adding a delay(1000) in between the commands.  None of these ideas worked.  What's shown below is the last code I tried.

Code:
#include <Servo.h>
Servo myservo;

int servo = 9;     // pin output to control the servo
int start = 50;    // start position of servo
int finish = 130;  // finish position of servo

void setup() {  
  myservo.write(start);   // move servo to start position
  myservo.attach(servo);  // attaches the servo to pin 9
  *** non-servo related code removed ***
}

void loop() {
  *** all this code works fine ***
}

oric_dan - (a) I've tried 3 servos, and they all do this.  I'm buying cheap servos, so maybe that's the problem.  (b) In my system, the servo will always end in the start position for the next operation.  I don't have to worry about this part of the initial servo jump.

EDIT - corrected comments in code to pin 9
« Last Edit: January 27, 2013, 11:05:06 am by ticklechicken » Logged

0
Offline Offline
Tesla Member
***
Karma: 143
Posts: 9598
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Simple servo test code. I noticed in your code that a comment said pin 8 was being used, but the code used pin 9. Also, if the 5V BEC can be set to 6v, the servo will perform better. Does the BEC function the same as an UBEC that is used to power servos (In usually see the BEC associated with brushless motors)?

Code:
// zoomkat 10-22-11 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// for IDE 0022 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h>
Servo myservo;  // create servo object to control a servo

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control
  Serial.println("servo-test-22-dual-input"); // so I can keep track of what is loaded
}

void loop() {
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string
    int n = readString.toInt();  //convert readString into a number

    // auto select appropriate value, copied from someone elses code.
    if(n >= 500)
    {
      Serial.print("writing Microseconds: ");
      Serial.println(n);
      myservo.writeMicroseconds(n);
    }
    else
    {   
      Serial.print("writing Angle: ");
      Serial.println(n);
      myservo.write(n);
    }

    readString=""; //empty for next input
  }
}
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Johannesburg. UTC+2
Online Online
Faraday Member
**
Karma: 95
Posts: 4338
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you tried to write the servo position before the attach?

My (probably wrong) assumption was that you could only do a write to an attached servo.... What's the thinking behind this please?
Logged

Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26291
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What's the thinking behind this please?
A write sets the timing for the pulse, but if there's no pin attached to the Servo object, it effectively changes the default position for the Servo.
Say, for example, your application always parks the servo at zero degrees.
At startup, the default behaviour of the Servo object would be to move the servo to 90°, and you would do an immediate write to set it to zero. It may well twitch.
Do the write before the attach, no twitch.
Or, you could just put the horns on with a ninety degree displacement.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Johannesburg. UTC+2
Online Online
Faraday Member
**
Karma: 95
Posts: 4338
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah ok, thanks.

That makes sense, especially in the light of this part....

Quote
the default behaviour of the Servo object would be to move the servo to 90°

... which I didn't know in the first place.
Logged

Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

zoomkat - Yes, its acutally a UBEC.  It's an old habit from the r/c car days to call them BEC's.  I switched the UBEC output from 5V to 6V and I still get the twitch.

AWOL - I changed my starting position from 50deg to 90deg.  I still get the twitch.

Let me give everyone more detail.  When the myservo.attach(servo) line is executed, the servo rotates 30deg clockwise.  It doesn't matter if I write a myservo.write(start) before this line or not.  The attach line always causes the 30deg cw rotation.  I've tried manually moving the servo horn to some random position before energizing the system.  Even then, the servo rotates 30deg cw before going to its start position.  I'm stumped.
Logged

0
Offline Offline
Tesla Member
***
Karma: 143
Posts: 9598
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you double checked your servo wiring? Make sure you have a good ground connection between the servo power ground and the arduino ground.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good idea.  I just checked all the wiring and the grounds look good.  When I was going over my breadboard, I realized that I was assuming the two grounds on the UBEC were grounded to each other.  I just verified this with the multimeter, but I added a ground circuit across the UBEC grounds just to be safe.  Still twitching...
Logged

0
Offline Offline
Tesla Member
***
Karma: 143
Posts: 9598
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've done some tinkering with servos controlled by the arduino and never had this issue.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2916
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've done some tinkering with servos controlled by the arduino and never had this issue.

As noted, some servos, such as GWS, twitch much more than others on power application.
Other than finding servos that don't twitch, it may work to use a Mosfet to apply power to the
servo [p-chan Mosfet on high-side power], and start the incoming pulses before power is applied. 
Maybe.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As noted, some servos, such as GWS, twitch much more than others on power application.
Other than finding servos that don't twitch, it may work to use a Mosfet to apply power to the
servo [p-chan Mosfet on high-side power], and start the incoming pulses before power is applied. 
Maybe.
This works with the servos I have.  After I power on the Arduino, I manually connect the servo to power and there's no twitch.  So I know the P-chan Mosfet circuit you describe will work.

I swapped my Uno boards and the twitch is still present.  When swapping servos on the new Uno, one thing that was interesting is that different brand servos twitch in different directions (ccw vs cw).  I'm ordering some other servos today.  If that doesn't do it, I'll do the Mosfet design.
Logged

Pages: [1] 2   Go Up
Jump to: