Servo Jitter Plz Help Need by Saturday

I am trying to control a robot arm using a ps2 controller. But I get jittering in the servos. Even with one HiTech HS-422 servo with no load.
I am using the Cytron PS2 Shield for connecting the PS2 controller to the Mega and the Sainsmart Sensor Shield for connecting the servo.
I’ve tried everything, but I am lost. Here are the things I’ve tried with no result:

  • changing the baude rate
  • powering just from usb, powering just from wall adapter (6V 2A max), powering from both at the same time
  • using noInterrupts() and interrupts() to stop possible timing issues
  • changing the SoftSerial pins that the Cytron shield is using
  • plugging the servo into different pins

A am a noob at Arduino. Thank you for reading. =)

My code (simplified)

#include <Cytron_PS2Shield.h>

#include <SoftwareSerial.h>

#include <Servo.h>

Cytron_PS2Shield ps2(10,11);
int pwm = 1500;

Servo myservo;
void setup(){
  myservo.attach(8,500,2500);
  ps2.begin(9600);
  Serial.begin(9600);
}

void loop(){
  if(ps2.readButton(PS2_TRIANGLE)==0){
    pwm -= 10;
  } else if(ps2.readButton(PS2_CROSS)==0){
    pwm += 10;
  }
  myservo.writeMicroseconds(pwm);
  Serial.println(pwm);
  delay(10);
}

EDIT: Here is a link to a video Jitter Example - YouTube

What video? Show us a schematic.

I’m sorry, but I don’t have a detailed schematic of my setup. Would it help if I explained it in words, or is there a way that I can create a schematic?

Again, I am a bit new to this, so I apologize if my questions are elementary.

Try a basic servo sketch without ps2 stuff, does it still jitter? How are you powering the servos and the Arduino?

.

Here are the images attached to the top post so others don’t have to download them.

055189d46bc72efc7f8390295052f12addc2c323.jpg

af317db09b03a40f6d69b710442f36f500b3a27a.jpg

How to insert uploaded images.

LarryD:
Try a basic servo sketch without ps2 stuff, does it still jitter?
How are you powering the servos and the Arduino?

+1 To LarryD’s questions.

Here are some recent threads discussing powering servos.

If you ramp the servo speed, you can get much smoother motion than just setting the target position and having the servos move at full speed to their destination.

Here’s a video demonstrating some constant acceleration code I recently posted to the forum.

The acceleration algorithms could be used with input from the PS2 controller.

The interrupt handling in SoftwareSerial during receiving will add jitter to the servo control pulses.

I concur with MarkT; it's a well known issue when using the Servo library with the SoftwareSerial library.

The only way that I know of to "fix" it is to either ditch one or the other: Use a hardware-based serial port (either pins 0 & 1 on the Arduino Uno - or get a Mega and use one of the extra hardware serial ports it has) or use a hardware-based servo driver (like a serial servo driver from Pololu, for instance).

In the latter case, you can connect the driver board to the Arduino and command it via a SoftwareSerial interface.

A couple of other alternatives:

  1. Get a second Arduino, and code up your own multi-servo controller software on it that takes commands from the hardware serial port, then link the two boards via SoftwareSerial (on the "controller" side) to the hardware serial on the "driver" side.

  2. Instead of regular TTL serial, use SPI (and associated pins). Designate the controller being the master node and the driver being a slave node. The advantage here would be speed and performance for the comms; the disadvantage is the fact that SPI can travel long distance (more than a few feet, normally).

Why not use the PlayStation 2 controller directly with the Uno? I've heard good things about Bill Porter's PS2 library. This would free you from needing to use software serial.

cr0sh: or use a hardware-based servo driver

I don't understand why external servo drivers are so commonly used. They just seem like an extra (and IMO unneeded) layer between the servo and the Arduino.

Here are some of the reasons I don't use external servo controllers. (Quoted from this reply.)

DuaneDegn: I generally don't want servos moving at constant speed. In the joystick/pan & tilt example, the program accelerates the servo up to speed and decelerates the servo to a stop. The target stopping point is constantly changing as the joystick is moved. So even if the servo controller could handle the acceleration and deceleration (which I don't think it can) the parameters of target position and target speed are constantly changing.

Besides the joystick/servo videos I have a couple other servo videos which demonstrate motion I don't think servo controllers could duplicate.

This is a simple demo showing a normal servo sweep with the position incrementing in a linear manner (servo on the left) vs a sinusoidal motion (servo on the right). I believe only the linear motion could be produced using an external servo controller.

This video is similar to the one I just mentioned, but on a larger scale. By controlling the position of each servo at 50Hz I think more complex motions are possible than simply commanding servos to move at a set speed.

In order to have servos responding to continuously changing input parameters, you need to actively control the servo at a relatively high frequency. I generally try to control servos at 50Hz since this is the refresh rate of many hobby servos and a 50Hz control loop is fast enough to appear "real-time". If the servos are supposed to be responding to real-time inputs, then they should be controlled in "real-time". Unless you want the servos to play back some sequence of motions which are independent from user input or sensor input, then I think you'll need to be continually updating the servos' positions. I don't see an advantage of having some servo controller PCB relaying these commands.

Hello all, I fixed the situation according to cr0sh's suggestion. I connected the PS2 shield through the hardware serial. And everything is now working splendidly. It was indeed a conflict between the Servo library and Software Serial library.

Thank you to everyone for their suggestions and support.