Servo Help Please FTK

I have a project where i have two servos that need to move in relation to one another.

How can i scale the outputs to reflect this.

im sending position in degrees and not microseconds.

Servo one has a range of 40 degrees to 140 degrees "Min Max"
Servo Two has a range of 10 degrees to 90 degrees "Min Max"

what i want to do is when i write a value to servo 1. i want to also take that value and write it to servo 2. but i want it to move in relation to servo one. so when i write a value to servo 1 it automatically adjusts this value to the appropriate position for servo 2 and writes it.

So when servo 1 is at 40 degrees. servo 2 is also at 10 degrees, both are at the bottom of their scales.

when servo 1 is at 90 degrees, servo 2 is at 45 degrees, both are in the middle of their scales.

when servo 1 is at 140 degrees servo 2 is at 90, or both are at the end of their scales.

and every number within.. it doesnt have to be exact, just close.

im not sure how to even address this. i seem to have it in my head that i can use constrain and map functions to do this. but so far i cant seem to wrap my brain around it.

running on a Arduino uno. any help is appreciated

this is how im writing position data to my servos

int pos1 = 45;
int pos2 = 0;

//somewhere in here i take the value of pos1 and modify it to be position2

pos1 = constrain(pos1, 40, 140);
pos2 = constrain(pos2, 10, 90);

Servo1.write(pos1);
  delay(15);
Servo2.write(pos2);
  delay(15);

You can refer to how to control speed of servo motor

1 Like

So i would use this. ?

is it that simple? :weary:

pos2 = map(pos1, 40, 140, 10, 90);

Do you want it to be more difficult?

1 Like

not really. just was expecting it to be more involved then that. i guess a nap is required before writing more code. Appreciate the help :v:

You might move the solution check mark up to @Delta_G's post, where the solution was delivered.

We cash these in for swag. 10000 solutions and you get a free UNO R3. :wink:

a7

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