Problem controlling two servos in Sync and opposite Direction.

I am making a waffle machine and for this I need to run two heavy duty RC servos in opposite direction. The problem is how to sync them so they lift together. They will obviously have different neutral point, currently I am using a digital level and running just one servo at the time to find out when my waffle iron is level. one servo is barely strong enough to lift iron when I took of some parts. If this is a good approach then what will be the code? My problem is how to get the servos to move smoothly together i.e in sync and in opposite direction. I want the whole sweep i.e 75 deg to happen in 4s:

/*
  waffle maker.
*/

// include the Servo library
#include <Servo.h>

Servo myServo1;  // create a servo object
Servo myServo2;  // create a servo object

int angle;   // variable to hold the angle for the servo motor
int pos=0;

int servo1Neutral=36; //manually calibrated
int servo2Neutral=24; //manually calibrated

int moveMents2Open= 75; // it basically just goes up to open
int moveMents2Close= 0; // can be tuned to get it to closely properly

int time2Open= 4; // seconds to open the thing

void setup() {
  myServo1.attach(9); // attaches the servo on pin 9 to the servo object
  myServo2.attach(8); // attaches the servo on pin 9 to the servo object
  Serial.begin(9600); // open a serial connection to your computer
  Serial.print("go to neutral");
  myServo1.write(servo1Neutral);
  myServo1.write(servo1Neutral);
  delay(10000);
}

void loop() {
 
  angle=45; // should hold actual position

  // print out the angle for the servo motor
  Serial.print("Angle: ");
  Serial.println(angle);

 for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myServo1.write(pos);
    myServo2.write(pos);             // tell servo to go to position in variable 'pos'
    delay(30);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 180; pos>=0; pos-=1)     // goes from 180 degrees to 0 degrees
  {
    myServo1.write(pos);             // tell servo to go to position in variable 'pos'
    myServo2.write(pos);
    delay(30);                       // waits 15ms for the servo to reach the position
  }
  
  
}

In order to "sync" anything, you need positional feedback. What are you intending to use to detect the movement of your servos?
The usual design for something like your device is to have a single power source and use gears/belts to control the motion and force identical movement.
Paul

I see you've found the Sweep example but you've made no attempt to move the servos in opposite directions. The normal approach for a 180 scan like you have now is to write pos to one servo and (180-pos) to the other. In your case you'll need to work out the start and end positions for the servos and change the 0 and 180 to suit. They won't perfectly in synch but may be close enough for practical purposes.

Steve

So a quick update on the progress:

Mechanics:
I see the point of going down the timing belt route, however you need stepper motor, belt, gearbox, end switch, motor driver, bearings etc to make it work. So I am trying to make a much more simpler system by using RC servo. Hower get them to sync is hard, so if they are almost synced maybe I can use spring on the servo horn:

servo saver

Software:
For the software I think its easier to now use the writeMicrosecond method due to the fact my servos goes from 800 to 2200ms. I am still a bit unure how to program it, but I think its better to deal with endpoints instead of trying to move the neutral point, then I should be able to use map function for servo in opposite direction right?

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
Servo myservo2; 
int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin

void setup() {
  myservo.attach(9);
  myservo2.attach(6);// attaches the servo on pin 9 to the servo object
}

void loop() {

  openUpper(); 
  delay(2000);   
  neutral();
  delay(2500);  
  eject();// waits for the servo to get there
  delay(2000);
  neutral();
  delay(3000);
  closeUpper();
  delay(1000);
  
}

void eject(){
 myservo2.writeMicroseconds(900);
}

void neutral(){
 myservo2.writeMicroseconds(1950);
}

void openUpper(){
  myservo.writeMicroseconds(1700);
}
void closeUpper(){
  myservo.writeMicroseconds(1200);
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.