Servo jitter problem

I have 5 servos running off of a Mega, 3 standard, 1 continuous, and 1 Firgelli L12 linear actuator. They are all powered with an external 5V / 2A power supply. Each servo needs an extension cable to reach the board / power supply. When I run my program, the linear actuator jitters when holding a position. When I remove the extension cable, on a separate servo (not the actuator), the jitter stops. Removing the extension cables from any of the other servos (including the actuator) does nothing to stop the jittering.

I was originally using a DFRduino RoMeo, using the same code, servos, power source, extension cables, etc. I did not have this problem. I moved to the Mega since the RoMeo only has 6 PWM channels and I plan on adding more servos.

I saw in a previous thread about this problem, that the wire length should be less than 6". Why? And why would changing that specific wire length solve the problem, but changing any other wire length not help?

Here is my code. I only included what I thought was relevant. The LOOP calls the pullWire method after receiving some serial data.

#include <Servo.h>

Servo grip, lActuator, clamp, cutWheel, liftWheel;

int clampPin = 5, gripPin = 6, actuatorPin = 9, liftWheelPin = 10, cutWheelPin = 11; // servo pin numbers
int clampOpen = 82, clampClosed = 62;   // clamp positions
int gripOpen = 45, gripClosed = 95;    // grip positions
int liftHome = 90, liftScore = 120, liftBreak = 145;  // list positions
int cutWheelStop = 90, cutWheelMove = 0;    // cut wheel speeds
int armHome = 1000;    // linear actuator positions
int ledPin = 13, switchPin = 22;          // led and switch pin
int numCutRevs = 1;    // number of times the cut wheel rotates 180 degrees

void setup() {
  pinMode(ledPin,OUTPUT);     // LED to show if program is paused
  clamp.attach(clampPin);
  clamp.write (clampClosed);  // close clamp
  grip.attach(gripPin);
  grip.write(gripOpen);       // open grip
  lActuator.attach(actuatorPin, 1000, 2000);
  lActuator.writeMicroseconds(armHome); // return to home position
  cutWheel.attach(cutWheelPin);
  cutWheel.write(cutWheelStop);
  liftWheel.attach(liftWheelPin);
  liftWheel.write(liftHome);
  Serial.begin(9600);
  Serial.println("Begin");
  delay(100);
}

// pull fiber
// desiredLength is in inches
void pullWire(double desiredLength)
{
  while(desiredLength > 2){
      grip.write(gripClosed); // close grip
      clamp.write(clampOpen); //open clamp 
      delay(100);
      lActuator.writeMicroseconds(inchToMM(1)); // pull wire to length
      delay(2000);
      clamp.write(clampClosed); // close clamp
      grip.write(gripOpen); // open grip
      delay(100);
      lActuator.writeMicroseconds(armHome); // retract actuator
      delay(2000);
      desiredLength = desiredLength - 1;  
  }
  if(desiredLength > 0) {
     grip.write(gripClosed); // close grip
     clamp.write(clampOpen); //open clamp 
     delay(100);
     lActuator.writeMicroseconds((int)inchToMM(desiredLength)); // pull fiber to length
     delay(2000);
     liftWheel.write(liftScore); // lift to score
     delay(100);
     scoreAndCut();  // score and cut
     delay(100);
     liftWheel.write(liftBreak);  // lift to break
     delay(100);
     liftWheel.write(liftHome);  // lift in home position
     clamp.write(clampClosed); // close clamp
     grip.write(gripOpen); // open grip
     delay(100);
     lActuator.writeMicroseconds(armHome); // retract actuator
     delay(2000);    
  }
}

// cut the fiber
// move cut wheel, count number of rotations by reading switch
void scoreAndCut(){
  int cutCounter = 0;
  int cutFlag = 1;
  //afterCutGrip.write(afterCutGripClosed);
  cutWheel.write(cutWheelMove);
  while(cutFlag == 1){
    delay(1000);
    while (digitalRead(switchPin) == HIGH) {
      delay(1); 
    }
    cutCounter++;
    if (cutCounter == numCutRevs){
      cutFlag = 0;
    }
  }
  cutWheel.write(cutWheelStop);
}

Are you just swapping the cable or the servo too? What is the actuator voltage with and without the questionable servo/cable.

You seem to say that removing the extension cable for a particular servo "solves" the problem but you haven't said which servo it is? Do you reconnect the servo without the extension so that everything continues to work? Does it matter what servo is at the end of the shortened cable? What happens if you connect the actuator to a different servo cable? Have you tried a different extension cable in case the cable is faulty?

I'm sure there are 20 more simple tests that would be worth doing.

...R

I saw in a previous thread about this problem, that the wire length should be less than 6". Why? And why would changing that specific wire length solve the problem, but changing any other wire length not help?

Probably electrical noise.

Try "braiding" the cables together. If they are all raped around each other I't might less the noise. I don't know why this happens, but it has worked for me in the past. Make sure you have a capacitor running from your power to ground.

Best of luck!

Robin2: You seem to say that removing the extension cable for a particular servo "solves" the problem but you haven't said which servo it is? Do you reconnect the servo without the extension so that everything continues to work? Does it matter what servo is at the end of the shortened cable? What happens if you connect the actuator to a different servo cable? Have you tried a different extension cable in case the cable is faulty?

I'm sure there are 20 more simple tests that would be worth doing.

...R

1) It is a standard Hitec HS-422 servo on pin 6 denoted by "grip" in my code. 2) Yes, reconnecting the servo without the extension 3) Yes, this problem only happens with the "grip" servo plugged in with an extension cable. I even changed out this servo to see if it was a faulty servo, which it isn't. 4) Nothing changes, still have the jitter 5) Yes, cable is not faulty

Two of the standard servos are Hitec HS-422 Servos, the 3rd standard is a Parallax, and the continuous servo is a Parallax. The linear actuator can be driven using the standard Arduino servo commands. The jittering does not happen while the actuator is in motion, only when holding a set position. The actuator has a stall current of 450 mA.

I've tried different pins on the Arduino, different cables, different servos, a different Mega board, different power supplies, etc.

[quote author=Drew Davis link=topic=181409.msg1344700#msg1344700 date=1375814673] Probably electrical noise.

Try "braiding" the cables together. If they are all raped around each other I't might less the noise. I don't know why this happens, but it has worked for me in the past. Make sure you have a capacitor running from your power to ground.

Best of luck! [/quote]

I tried braiding the cables, which didn't work. Will add the capacitor between the power and ground. Any value you recommend?

Thanks for the help!

Swap the actuator and a servo to see if the servo or actuator jitters on the different pins. servo test code you can try with the actuator to see if it still jitters.

// 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, 500, 2500);  //the pin for the servo control, and range if desired
  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
  } 
}

It sounds like your system is working close to some limit and the extra extension cable pushes it too far ...

... except that the problem (the extension cable) is specific to a particular output. That suggests to me that the problem is with that output, or with the output to the actuator. (By 'output' I mean everything from the Arduino chip to the servo/actuator). A poor electrical connection springs to mind - but you may have checked them all carefully.

Alternatively if the problem lies "within" the Arduino swapping the outputs around should have some effect, but from what you say it doesn't. (I'm thinking here of swapping devices without altering the code to match).

I haven't looked at how the Arduino chip is wired internally (not even sure how much of that is public) but have you tried driving the "problem" servo and the actuator from different pins in case there is some internal interference - perhaps ensure that they are on different Ports?

...R

5 servos can take a lot more than 2A worst case, so its likely the power rail is dipping and causing the actuator to fluctuate. Try measuring the voltage while its operating - does the voltage stay stable?

Robin2: It sounds like your system is working close to some limit and the extra extension cable pushes it too far ...

... except that the problem (the extension cable) is specific to a particular output. That suggests to me that the problem is with that output, or with the output to the actuator. (By 'output' I mean everything from the Arduino chip to the servo/actuator). A poor electrical connection springs to mind - but you may have checked them all carefully.

I think I fixed my problem. I current have the servos and power source soldered to a protoboard. This morning I moved everything back to my breadboard and discovered that it works perfectly with or without the extension cables. Reexamined my protoboard, and I can't find the faulty connection, but I am going to assume that this is where the problem is.

Thanks for all of your help / suggestions!