Robotarm is has a bad case of the "shakes"

How can i get my robot arm to be more stable and operate smoothly. insted of it being jerky and jitery?

link to a video of my robot http://youtu.be/a8VSh4gSbkQ
and a copy of the sketch i created.

this is my first real arduino code i have modified or have attempted to write so pleaase dont rip it apart.

#include <Servo.h>                                // required libraries to make this sketch work
#include <Wire.h>
#include <WiiNunchuck.h>

Servo servo1;                                   //creating servo elements
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo servo6;


int val;                                         //declaring integers
int val2;
int val3;
int val4;
int val5;
int val6;


void setup()
{
    Serial.begin(19200);                         // thing that need to be done in order for the nunchuk to function
    Serial.print("WiiNunchuck Demo ready\n");    // this dosent really need to be here.......
    Nunchuck.calibrate();
   
   
    servo1.attach(5);                            // attaching servos to pins.
    servo2.attach(6);                         
    servo3.attach(7);
    servo4.attach(8);
    servo5.attach(9);
    servo6.attach(10);
   
   
                                               // This initializes the nunchuck. If it can't initialize, or doesn't see the nunchuck, it waits forever.
                                               // It takes one option, a 1 for power, or 0 for no power. If power is turned on, it will output + on analog 3, - on analog 2.
                                               // I recommend using 0 and powering it through the 3.3v power connector if possible.  Use this only if you are using the little nunchuck adapter.
    Nunchuck.init(1);
}

void loop()
{                                                       // get data refreshes data for functions that occur below this point.
    Nunchuck.getData();                                 // Prints data for all the sensors in a table format
    Nunchuck.printData();                               // dosent really need to be here either but it will print to serial monitor if it is opened.
    delay(10);
  
    if
   
    (Nunchuck.zbutton()== 0)                               //if clause only activated if button is not pressed.  
   
    {
    val = Nunchuck.accelx();                         // servo 1 controlled by nunchuk tilt in x direction
    val = map( val,310,716,0,179);
    servo1.write(val);
   
   
   
    val2 = Nunchuck.accely();                      // servo 2 controlled by nunchuk tilt in y driection.
       val2 = map( val2,310,716,0,179);
       servo2.write(val2);
     
      val3 = Nunchuck.joyy();
      val3 = map(val3,0,255,0,180);               //servo 3 controlled by nunchuk joystick in y direction.
      servo3.write(val3);
     
     
    }
    else
    {
       val4 = Nunchuck.accely();                      //servo 4 controlled by nunchuk tilt in y direction. when z button is pressed
       val4 = map( val4,310,716,179,0);
       servo4.write(val4);
      
       val5 = Nunchuck.accelx();                     // servo 5 controlled by nunchuk accl in x direction.
      val5 = map(val5,310,716,0,180);
      servo5.write(val5);
       
       
        val6 = Nunchuck.joyx();                       // servo 6 controlled by nunchuk joystick in x direction. when z button is pressed
       val6 = map( val6,0,255,179,0);
       servo6.write(val6);
    }
   
}

I’d probably replace all the "servox.write"s with serial prints and find out what the data looks like.
Jittery data in == jittery arm out.
If this is the problem, then some smoothing would be in order.

If i do find that the data is erratic what would i need to do in order to smooth it? are there any examples i can look at, perhaps i would have to create some kind of filter? how exactly would i go about doing that?

I had the same when I used my nunchuck to control servo motors. All I did was to look at the smooth example that is with the arduino gui, and then use that code to smooth it out, worked pretty well after that. :slight_smile: