Using a rotating servo to emulate a linear movement from left to right through programming

Hello,

I was wondering if it was possible to emulate a linear movement with a rotating servo going from left to right through programming. It is better explained with this picture:

image

The problem is basically to control the angle of the servo's arm so that the speed of the blue dot across the x axis remains constant in time.

This sounds like a nice trigonomical problem but it's been a while since I have studied this and I am new to programming so an help is appreciated!

The angle is easily controlled with Servo.write(angle);

The speed of the angle is more problematic, since there is no feedback on how fast the servo is moving--you have to assume the speed a particular servo moves.

As for the trig:

https://betterexplained.com/articles/intuitive-trigonometry/

What I need is that is moves more quickly at the edges of the circle as it doesn't translate to much movement in the x axis and therefore, the speed of the servo would constantly be changing, slowing down at 90degrees and speeding up at 0 and 180 degrees. I don't know if this is easy to implement through programming or I should just go buy some linear servos

Yes, it's quite achievable with Arduino. As you said, it's just trigonometry.

1 Like

If you ahve the time, could you tell mehow you would go about it?

You need to start by knowing the length of the green arrow in your diagram, and calculate from that the angle theta, which you will use to control the servo.

sin(theta) = adjacent / hypotenuse

The "hypotenuse" is the radius of the circle in your diagram. It doesn't actually matter what that is, so let's assume that is 1.0 to make the maths easy.

The "adjacent" is the length of the green arrow. It can be between 0.0 and 1.0.

To calculate theta:

theta = asin(adjacent / hypotenuse)

Since hypotenuse is 1.0

theta = asin(adjacent)

This angle theta will be in radians. It needs to be converted to degrees to use with the Arduino servo library.

To convert radians to degrees,

degrees = radians / PI * 180

Using a rotation servo ... do you mean continuous rotation type?
Have a link to your servo?
What Arduino board are you using?

Note: If you have continuous rotation type, then you'll have control of speed and direction, not angle. Therefore, for example:

Servo.write(0);     // full speed counter clockwise
Servo.write(45);    // ½ speed counter clockwise
Servo.write(90);    // servo stopped
Servo.write(135);   // ½ speed clockwise
Servo.write(180);   // full speed clockwise

With a continuous rotation type servo, one won't know the angle, so won't be able to compute the corresponding speed.

It would only be possible with a normal servo, and there would still be limits based on the unknown max speed (omega) of the servo.

Thinking more on the limits -- at 0 and 180 degrees, the length of the green line is cos(theta) and the x-speed of the blue dot is omega*sin(theta) and approaches 0 at the limits. With a limited RPM of a servo there isn't a way to keep the blue dot at a constant speed as it approaches 0° & 180°.

3D print a cam?

Typical solution: drive a spindle.

1 Like

It depends on what kind of fun you like to have. And the deployment scenario.

Without knowing more, like how you plan to use the servo arm to make something else move along a line, I'd guess you'd be further along faster with a linear actuator (servo).

What is the physical use case here? What speed, distance and power is required?

a7

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