Go Down

Topic: Servo twitch on startup (Read 2915 times) previous topic - next topic

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.

AWOL

Have you tried to write the servo position before the attach?
"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.

oric_dan

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.








zoomkat

Quote
Any good solutions?


Posting your code might help.
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

#4
Jan 27, 2013, 02:43 am Last Edit: Jan 27, 2013, 05:05 pm by ticklechicken Reason: 1
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: [Select]
#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

zoomkat

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: [Select]

// 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
  }
}
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

JimboZA


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?
"Could you do the egg bacon spam and sausage without the spam then? "

No PMs for help please.
DO NOT power servos from Arduino 5V: give them their own power and connect the grounds.

AWOL

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.
"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.

JimboZA

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.
"Could you do the egg bacon spam and sausage without the spam then? "

No PMs for help please.
DO NOT power servos from Arduino 5V: give them their own power and connect the grounds.

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.

zoomkat

Have you double checked your servo wiring? Make sure you have a good ground connection between the servo power ground and the arduino ground.
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

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...

zoomkat

I've done some tinkering with servos controlled by the arduino and never had this issue.
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

oric_dan


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.


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.

Go Up