AutomateDirectUSAMotion LibraryIndustrial monitors & PCs

Troubleshooting

Why a 2 DOF Robot Arm Curves Near the End of a Straight Line

Servo and stepper motion Published 9 min read By AutomateDirectUSA engineering team

Short answer

The curve near the end of the stroke is almost always the inverse kinematics, not the servos: the cosine-law solver flips between the elbow-up and elbow-down branch because the sign of the square-root term s2 is not fixed. Hold one branch for the whole stroke, take both angles from atan2, and require c2 to stay between -1 and 1 at every waypoint. Confirm it by plotting the forward-kinematics path of the commanded angles before touching the update rate.

On this page
  1. Where the circular end comes from
  2. Separate the math from the motors first
  3. Keep one elbow for the whole stroke
  4. Worked example: a 100 mm plus 100 mm arm ending 2 mm short of full reach
  5. Stay clear of full extension and the travel limits
  6. If the commanded path is straight but the trace still curves
  7. What the inverse Jacobian would add
  8. The decision
  9. Questions asked

The pencil leaves the line near its end because the inverse-kinematics solver changes elbows mid-stroke, not because the servos cannot follow. A planar two-link arm has two valid solutions for almost every reachable point — elbow-up and elbow-down — and the cosine law separates them through the sign of one square-root term. When that sign is recomputed waypoint by waypoint, or lost to a single-argument arctangent, the elbow swings the long way around while every waypoint still sits on the line, and the trace bends into an arc near the endpoint. Fix the branch first; the servo side almost never needs to change.

Where the circular end comes from #

Assume the common layout: two revolute joints with link lengths L1 and L2, the pencil at the modeled end of link 2, q1 measured from the base x-axis and q2 between the links. For a target at (x, y), with x and y in millimetres and the math carried in radians, the cosine-law solution is:

c2 = (x^2 + y^2 - L1^2 - L2^2) / (2*L1*L2)
s2 = ±sqrt(1 - c2^2)
q2 = atan2(s2, c2)
q1 = atan2(y, x) - atan2(L2*s2, L1 + L2*c2)

The sign in front of the square root is the elbow choice. Both signs put the tip on the same point; they differ only in the arm's configuration. A solver that takes whichever root falls out of a library call, that uses acos(c2) — which always returns one side — or that computes q1 from a single-argument arctangent and loses its quadrant, can flip between the two configurations at any waypoint. The flip is most likely near the end of a stroke, where the two solutions converge and rounding pushes c2 toward the edge of its range, which is exactly where the trace leaves the line.

Separate the math from the motors first #

Rebuild the commanded path with forward kinematics before touching any servo setting, and keep four traces apart:

Trace Where it comes from What it tells you
Requested coordinates waypoint generator the segment you asked for
Joint targets inverse-kinematics solver the branch and quadrant choices it actually made
Forward kinematics of the targets forward model the path the solver is commanding the pencil to follow
Measured angles and pencil trace servos and paper tracking and mechanics, read only after the row above is straight

If the forward kinematics of the commanded targets already curves, the fault is in the solver, and no drive or timing change can fix it. If that reconstructed path is straight but the drawn line curves, the solver is right and the execution checks take over.

Work the list in order; each step is cheaper than the one after it:

  1. Plot the forward kinematics of the commanded targets, waypoint by waypoint, over the intended segment.
  2. Plot both joint targets against waypoint index. Healthy dense waypoints move each joint by fractions of a degree to a few degrees per step; a step of tens of degrees between adjacent waypoints is a branch flip.
  3. Evaluate c2 at every waypoint, not only the endpoints, and reject any waypoint where it falls outside -1 to 1.
  4. Fix the sign of s2 once for the stroke and hold it; confirm q1 and q2 come from atan2, never from acos or a bare arctangent.
  5. Check endpoint clearance from the reach limit and both joints' travel range across the whole stroke.
  6. Only when the commanded path is straight, check command timing, the update interval, joint speed settings and the measured-minus-commanded angle error.

Keep one elbow for the whole stroke #

Both configurations are equally valid mathematics; mixing them inside one stroke is the fault. Choose the branch at the start — the one that keeps both joints inside their travel and clear of full extension for every waypoint — then hold the sign of s2 constant to the last waypoint. Reject waypoints that fall outside the workspace instead of clamping c2 back into range, and skip ad-hoc repairs such as forcing the two joint angles to sum to a fixed total: they hide the branch error without removing it. When you difference joint targets between waypoints, wrap the angles to ±180° first so a wrapped representation does not read as a large physical move.

Worked example: a 100 mm plus 100 mm arm ending 2 mm short of full reach #

Inputs: example link lengths L1 = 100 mm and L2 = 100 mm — substitute the lengths of your own links — with the pencil at the end of link 2, and the last two waypoints of a stroke, A at (180 mm, 60 mm) and B at (196 mm, 28 mm) in the base frame. The math runs in radians; angles are quoted in degrees for readability. The result below is a calculated example for these inputs, not a measured trace.

Rule: the squared distance from the base to the target fixes the cosine of the elbow angle through the cosine law; the square root of what remains fixes its sine, and the sign of that square root chooses the elbow side; atan2 of sine and cosine gives q2, and atan2 of the target against the wrist term gives q1.

At B: 196² + 28² = 38416 + 784 = 39200 mm², so c2 = (39200 − 20000) / 20000 = 0.960, inside the valid range. Elbow-up: s2 = +√(1 − 0.960²) = +0.280, so q2 = atan2(0.280, 0.960) = 16.26°, and q1 = atan2(28, 196) − atan2(28.0, 196.0) = 8.13° − 8.13° = 0.00°. Forward check: 100·cos(0.00°) + 100·cos(16.26°) = 100 + 96.0 = 196 mm and 100·sin(16.26°) = 28.0 mm, so the tip lands on the waypoint. Elbow-down: s2 = −0.280 gives q2 = −16.26° and q1 = 16.26°, and the same forward check lands on the same point, confirming both branches are valid.

At A: 180² + 60² = 36000 mm², c2 = 0.800, and the elbow-up solution gives s2 = +0.600, q2 = 36.87°, q1 = 18.43° − 18.43° = 0.00°.

Now solve A elbow-up and B elbow-down, which is what an unstable sign choice produces. The last step then demands q1 to move from 0.00° to 16.26° and q2 from 36.87° to −16.26°, a 53.13° swing of the elbow, while the pencil itself has only √(16² + 32²) = √1280 ≈ 35.8 mm of chord left. The servos faithfully drive that swing, and the pencil draws it as the arc you see near the end.

Conditioning falls too: the Jacobian determinant for this geometry is L1·L2·sin(q2), which is 6000 mm² at A, 2800 mm² at B and zero at the 200 mm boundary. Decision: B sits 2.0 mm inside that 200 mm limit, so it is reachable — hold s2 positive for the whole stroke and the curve disappears. Any waypoint whose c2 falls outside −1 to 1 is unreachable and must be moved, not clamped.

Stay clear of full extension and the travel limits #

At full extension the links are collinear, sin(q2) is zero and the Jacobian determinant collapses: the arm loses its radial direction, and a requested Cartesian velocity demands ever larger joint velocity. Slowing the stroke improves tracking near that pose but cannot restore the missing direction — pull the endpoint inward or reshape the segment instead. The reachable annulus runs from |L1 − L2| to L1 + L2; with unequal links a segment can start and end in reach yet cross the unreachable inner disc, which is why every waypoint needs the c2 test rather than the two ends alone.

Joint travel adds its own bounds. The AX-12A servo in this case takes joint-mode position targets across the 0° to 300° span its control table documents, and your mounting direction, zero offsets and unit conversion sit between the mathematical angles and that range, so verify each joint's physical zero before trusting a computed pose. The same per-joint pass described in calibrating a 6 DOF robot arm kit for inverse kinematics transfers directly to two joints. One safety note: run a corrected stroke the first time with the pencil lifted clear of the paper, because a branch flip near full extension sweeps the elbow across the table.

If the commanded path is straight but the trace still curves #

Then execution, not math, bends the line. Joint-position servos regulate their own angles; nothing in them coordinates two joints along a segment. Work these in order:

Setting or reading Where it lives What goes wrong
Waypoint interval trajectory scheduler long or irregular gaps give the servos time to fall behind
Paired writes communication driver targets for one waypoint arriving apart distort the coordinated move
Joint speed limit servo configuration a joint that tops out bends the path even with correct targets
Target minus measured angle feedback log error that grows toward the endpoint is tracking, not kinematics
Pencil holder offset the mechanics an unmodeled offset at the tip bends even a correct path

Keep the interval regular and as fast as the link sustains for both joints on every waypoint — the trade between command interval and tracking is the same one described in what a fieldbus command update rate decides for servo axes. If one joint stops short while the other arrives, the causes behind why a servo axis never reaches its commanded speed are the ones to rule out. If the trace is uniformly longer, shorter or mirrored against the command, suspect scaling or sign: that is the same fault family as an axis that travels 1.25 times the commanded distance, not a branch problem. Start with a slow Cartesian speed and raise it only while the measured angles keep following the sequence.

What the inverse Jacobian would add #

The inverse Jacobian converts Cartesian velocity into joint velocity: q_dot = inverse(J) * [vx, vy], with vx and vy in millimetres per second and the result in radians per second; multiplying by the update interval dt in seconds gives an angle increment, q_next = q_current + q_dot * dt, which you convert into the servo's documented position units before sending. That structure suits continuous velocity control along a path, but for drawing a segment it adds integration drift and singularity handling without producing a straighter line than dense waypoints through the cosine law with one fixed branch. So the direct answer to the question behind this fault: yes, this class of arm draws near-straight lines — the endpoint curve was the branch flip, not a limit of position-mode servos.

The decision #

  • Forward kinematics of the commanded targets curves: repair the solver — hold one sign of s2, take both angles from atan2, wrap before differencing — and leave the servos alone.
  • c2 outside −1 to 1 at any waypoint: that waypoint is unreachable; move the endpoint inward or reshape the segment, and never clamp c2.
  • Commanded path straight but the drawn line curves: execution — regular interval, paired writes, joint speed limits, then measured-minus-commanded error, then the pencil holder offset.
  • Endpoint close to full reach: expect stiff radial conditioning — the worked example's endpoint sat 2.0 mm inside its limit and the determinant had fallen to less than half — so slow only there or move the point in.

Questions asked

How do I choose between elbow-up and elbow-down for a given stroke?

Run the whole waypoint list through the solver with each sign of s2 and score each candidate on the things that disqualify a stroke: any joint outside its travel range, any waypoint too close to full extension, or a joint that would cross a mechanical stop. Keep the branch that clears every waypoint with margin, then hold that sign for the whole stroke. With equal link lengths there is rarely a reason to change branches inside one segment.

Why does the trace bend more near the end even after I fix the branch?

Near full extension the two solutions merge and the Jacobian determinant L1·L2·sin(q2) shrinks toward zero, so each millimetre of Cartesian motion demands a larger joint motion and small tracking errors show directly in the trace. Slow the stroke through that region or pull the endpoint inward; both reduce the visible bending. The determinant at your own waypoints, from the same formula, tells you how much margin you have left.

How fast should I send waypoints?

The fastest interval your serial link sustains for both joints on every waypoint, with no dropped messages, and no faster. Set it, command a slow Cartesian speed, and compare measured angles against targets; raise the speed only while the error at the hardest waypoint stays small. Dropped waypoints or an irregular interval bend the trace even when every individual solution is correct.

Do I need angle feedback to draw straight lines?

No. The math decides the line; feedback only decides how well you can see the faults. If the servos report their measured angle, as smart position-mode servos in this class typically do, you can rebuild the drawn path from measurements and separate tracking error from a solver fault. Without angle feedback you can still rebuild the commanded path on paper, but the tracking checks fall back on the paper trace alone.

Can I mix elbow branches between two different strokes?

Yes. The branch is a per-stroke decision, not a machine setting. Pick the sign of s2 that suits each segment's workspace and joint margins, lift the pencil between strokes, and re-approach the next segment from a well-conditioned pose. What breaks a line is a branch change in the middle of a stroke, where the elbow must swing around while the tip is supposed to hold a path.

Keep reading

  • How-to

    Reseat servo horns at the startup pose on a robot arm

    Reseat every servo horn with the arm in its startup pose, straight up, before you touch software. A horn seated one spline tooth off shifts each commanded angle by 360 divided by the tooth count — typically 10 to 25 degrees on hobby-class servos — and offsets cannot recover travel the link geometry clips at an end stop. Trim only the residual fraction of a tooth with per-joint limits and a linear map.

    Servo and stepper motion

  • How-to

    Grasped object conveyor alignment: choose the signed quarter-turn

    Resolve the grasped object's alignment direction and the conveyor travel direction into one frame and compute the signed correction atan2(n·(u×v), u·v). Command -90 or +90 degrees only when the incoming orientations truly span those two cases; otherwise command the computed angle or reject the pose. Rotate the tool through the grasp relationship, never the object's model alone.

    Servo and stepper motion

  • How-to

    Setting Up Servo Electronic Gearing With Registration Correction

    Gear the folder servo to the web encoder with one fixed electronic gear ratio and apply registration error as a bounded phase trim ramped across the 100 to 200 ms between corrections. At 150 m/min a 0.1 mm tolerance is 40 microseconds of web travel — about eight 0.0127 mm increments — so doubling or halving a pulse train for six pulses trips following error, while a ramped trim changes speed by 0.04 percent.

    Servo and stepper motion