1

For overcoming torque issues, I have attached 2 identical servos on a certain part of my robot arm and because I saw someone do the same.

Now, while writing code I realize:

#include <Servo.h>
...
...
shoulder1.write(map(analogRead(p1), 0, 1023, 0, 179));
shoulder2.write(map(analogRead(p1), 0, 1023, 0, 179));
...

will turn shoulder1 by 20* and then shoulder2 by another 20*, ie. an overall turn of 40*; that too with too much load on servos, as the other servo would be inactive at the time first is active.

I want to achieve 20* fully-sync.ed turn on both servos, how do I accomplish this? Any arduino libraries or walkthrough?


Can I possibly move them both at the same time - something like multithreading on arduino? Here's what I tried:

void rotateTwoServoInSync(int angle) {
    for(int i = 0; i<angle; i++) {
        shoulder1.attach(9);
        shoulder1.write(i);
        shoulder1.detach();
        shoulder2.attach(10);
        shoulder2.write(i);
        shoulder2.detach();
    }
}

Will it work? Is this approach recommendable?

  • you do know that all of that code executes WAAAAY faster than the response time of the servos, and they will, for the most part, operate at the same time? – KyranF May 11 '15 at 4:44
  • if you write both outputs at the same time (two lines of code sequentially) it is enough for them to operate in sync. – KyranF May 11 '15 at 4:46
5

If you have two RC servos that are always required to move together you can simply connect both control inputs to a single output.

| improve this answer | |
  • So do I need a NPN transistor to amplify the signal? – RinkyPinku May 25 '15 at 2:35
  • Nope. Just connect and drive them together. – Spehro Pefhany May 25 '15 at 4:33
3

Spehro's answer is the most obvious. But note that there is no such thing as identical servos. You may stress them if you connect them through a stiff connection.

If you want to have two mechanical parts make the same movement the proper solution is to connect them mechanically, rather than have two servos doing the same action.

| improve this answer | |
0

analogRead() and map() are slow; only perform them once.

unsigned char rot = map(analogRead(p1), 0, 1023, 0, 179);
shoulder1.write(rot);
shoulder2.write(rot);
| improve this answer | |
  • I will implement your advice - but still if rot is 150* then wouldn't shoulder1's 150* movement w.r.t. shoulder2's stationary position break/burn the setup? – RinkyPinku May 11 '15 at 4:10
  • Only if your setup is made of diamond. Otherwise it will have plenty of flexibility to handle the few hundreds of nanoseconds of difference. – Ignacio Vazquez-Abrams May 11 '15 at 4:12
  • I don't know if I agree to that - but torque issue is still unsolved. – RinkyPinku May 11 '15 at 4:15
  • Then your servos aren't identical. – Ignacio Vazquez-Abrams May 11 '15 at 4:21
0

To operate two or more servos at the same time you need to interpolate their movements, first moving one servo a little, then moving the next one, back and forth until all servos arrive at their destination point. I haven't seen a library yet that accomplishes this for you so you probably need to write your own routine. Here is a project where I interpolated three servos and includes the code: https://www.instructables.com/id/MonkeyBot-3-Servo-Climbing-Robot/

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.