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?

asked May 11, 2015 at 3:56
2
  • 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? Commented May 11, 2015 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. Commented May 11, 2015 at 4:46

4 Answers 4

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.

answered May 11, 2015 at 6:14
2
  • So do I need a NPN transistor to amplify the signal? Commented May 25, 2015 at 2:35
  • Nope. Just connect and drive them together. Commented May 25, 2015 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.

answered May 13, 2015 at 9:00
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);
answered May 11, 2015 at 4:08
4
  • 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? Commented May 11, 2015 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. Commented May 11, 2015 at 4:12
  • I don't know if I agree to that - but torque issue is still unsolved. Commented May 11, 2015 at 4:15
  • Then your servos aren't identical. Commented May 11, 2015 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/

answered May 22, 2019 at 4:33

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.