How can I develop a code with Variable Speed for a Servo?

Hi! This is my first project as a newbie to Arduino. It’s a Sketching Arm with 2 servos and a fixed pen at the end as shown in the image. Basically for now, it can only draw a straight line.

And below is the modified Servo (Sweep) Library I used, where the count is linear so that the servo positions are also linear with respect to time (Graph 1) while moving from X to Z. And the figures below that is the corresponding movement. Now the problem is that the pen tip DOES NOT maintain a constant elevation (ground level) as the pictures show.

So now I want your help to change this code for this constant elevation by making the count (servo-positions) to be curvilinear as in (Graph 2), such that the arm should work like in the figures below it.

Any help would be appreciated!
Thanks In Advance! :slight_smile:

Arduino Code.rar (394 Bytes)

Is there a formula that relates the position of the drawing point to the angles of the servo ?

It would probably be easier to turn the mechanism on its side so that one servo moved the drawing point in an arc up and down the paper and the other moved it in an arc across the paper. That way it would be easy to maintain contact with the paper.

Nope… That is why I need an adjustable curvilinear variation to suit different height levels.

Ah yes I get it. Thanks. It even relieves the servos from extra lifting load right? I guess this is what u meant right?

But when drawing a straight line, still I need a curvy effect in their speed.
There’s an option, to increase the count by 1 (i = i+1) every time up to 90° and write another loop to reduce the count for the remaining 90°. (Uniform acceleration and deceleration). But i don’t know how… :frowning:


Yes, that’s what I had in mind. You still need the algorithm, which I am afraid that I can’t help with.

The servo library supports both write() and write.Microseconds() methods. Depending on the resolution available from the servo the latter provides more precise control because the range of values that it accepts is wider.

Below are some links with servo speed info. I would think what you want to do might be to use two dimensional inverse kinematics formulas with a horizontal drawing arm.,61586.30.html

The horizontal arm idea makes more sense to me. If you really want to use the vertical arm alignment then in order to keep the pen upright and in contact with the drawing surface you really only have one degree of freedom and I would aim to synchronise the shoulder/elbow/wrist movements mechanically and drive it by a single servo. However, turning the mechanism by 90 degrees so that the shoulder/elbow give you 2-d movement makes a lot more sense to me. Either way, Zoomcat's inverse kinematics approach seems like the best way to calculate the server positions required to achieve a given pen position.

A Watt linkage (after the steam engine pioneer) allows the motion from an arc to be converted into a straight line.

It may not be so easy to make a pair of them for the X and Y axes but it may be worth considering.


Thanks everyone! I'll surely give it a shot. & will reply here if it works. Thanks again! :)