0

Here the rough sketch of my circuit connections:

img

The 8 servo motors are powered externally with a DC Power supply. The ground of power supply, the servo motors and Arduino is made common. Arduino is powered by laptop

#include <VarSpeedServo.h>

VarSpeedServo rot1;    
VarSpeedServo rot2;    
VarSpeedServo rot3;   
VarSpeedServo rot4;

VarSpeedServo grip1;   
VarSpeedServo grip2;   
VarSpeedServo grip3;   
VarSpeedServo grip4;

void setup() {

rot1.attach(11);
grip1.attach(10);

rot2.attach(1);
grip2.attach(2);

rot3.attach(8);
grip3.attach(9);

rot4.attach(5);
grip4.attach(7);

home1();
delay(1000);
home2();
delay(1000);
home3();
delay(1000);
home4();

}

void loop() {
}

void home1()
{
 rot1.write(0, 30, true);
 delay(2000);
 rot1.detach();
 grip1.write(40, 30, true);
 delay(2000);
 grip1.detach();
}

void home2()
{
  rot2.write(0, 30, true);
  delay(2000);
  rot2.detach();
  grip2.write(40, 30, true);
  delay(2000);
  grip2.detach();
}

void home3()
{
  rot3.write(180, 30, true);
  delay(2000);
  rot3.detach();
  grip3.write(160, 30, true);
  delay(2000);
  grip3.detach();
}

void home4()
{
  rot4.write(180, 30, true);
  delay(2000);
  rot4.detach();
  grip4.write(80, 30, true);
  delay(2000);
  grip4.detach();
}
  1. The above program is for controlling 8 servo motors. I am building a Rubik's cube solving robot. It has 4 arms and each arm has 2 servo motors. One motor opens the grip to hold the cube and other motor rotates the cube in particular angle.

  2. When ever I upload the program, the servo motors initially goes to different positions and then moves according to the program. I don't know what is the reason behind it.

  3. Should i change something in the program or should I change something in the circuit ?

Spektre
  • 49,595
  • 11
  • 110
  • 380
  • What is the position? Is it the position corresponding to 0? If so.. Sorry, no solution. The problem is that they require some time to initialize... You can try to edit the library to start at a particular position, but.. it will always move to that particular position as soon as you reboot it – frarugi87 Apr 14 '16 at 13:02
  • 1
    I would hook up an oscilloscope to test if the PWM is not distorted from the start ... – Spektre Sep 26 '16 at 10:26

1 Answers1

0

I assume you are using a standard servo motor, not a 'continous rotation' servo motor?the problem you are facing little hard to solve at fundamental level.

A servo motor when powered off, it will tend to remain in it's last commanded position by default (assuming that any type of load on the gear train doesn't move it when not in use), and there is no way for a finding first starting up to know what position the servo motor is presently at, because there is no position feedback signal from the servo motor back to the arduino is currently available.

What i can suggest is that if it's super important then you must mechanically couple some kind of pot to the servo linkage and read back it's true position via a analog input pin.

Wish this will help you.