twitching servos robotic arm

hello,
I am a beginer in electronics and arduino, we are working on a school project and have a problem and don`t seem be able to fix it:
We have built a robotic arm, it works but at startup it twitches … a lot.
I will post a short video clip of this , afterwords it seems to be working fine.

Details:
yes I have an initial position set for every servo.
arduino mega.
a pc power suply for the arduino and the robotic arm.

Code:
this is in a header file:

#include <Servo.h>
#include <SoftwareSerial.h>

#define servoTopPin 7
#define servo2Pin 11
#define servo3Pin 8
#define servo4Pin 9
#define servoClawDirPin 10
#define servoClawPin 12

my setup function:

  servoTop.write(defaultServoVal[0]);
  servo2.write(defaultServoVal[1]);
  servo3.write(defaultServoVal[2]);
  servo4.write(defaultServoVal[3]);
  servoClawDir.write(defaultServoVal[4]);
  servoClaw.write(defaultServoVal[5]);

where defaultservopos is an array of values , for the initial position.

I also have another function init servos

  servoTop.attach(servoTopPin);
  servo2.attach(servo2Pin);
  servo3.attach(servo3Pin);
  servo4.attach(servo4Pin);
  servoClawDir.attach(servoClawDirPin);
  servoClaw.attach(servoClawPin);

Tried diffrent versions , calling the functions in the loop (once) , in setup …
same result.

Please advice me, again I would like to point out that I am a beginer.

Thanks

Video : https://streamable.com/7ggyf

We need to see complete code including variables (in </> code tags please) otherwise we can’t tell what you’re doing and when you’re doing it. Or if the whole thing is too big to post make a small program that compiles and runs and that demonstrates the problem.

Steve

I have like 20 tabs and a lot of functions. I posted the setup and variables

O.k. There is nothing wrong with those bits of code in isolation (if you actually created the Servo objects and if the defaults array is setup properly). So the problem is maybe the order you’re calling things or in something else that you’re doing or not doing in some other code. Good luck.

Steve

I don't think that the servo library and the softwareserial library get along. They both try to use the same timer.
Doesn't the mega have 4 hardware serial ports? If so, you should use one of those instead of software serial.

You are attaching all the servos at practically the same instant, so they all try to go to default position at the same instant, (OVERLOAD). Try putting a 150 mS (or more) delay after each attach.