Skip to main content
//Let's learn Something New.ROBOTICS · EMBEDDED SYSTEMS · RESEARCH
Preferences
PERSONALIZE YOUR VIEW
Appearance & reading

Choose how you explore the notebook.

QUICK THEMES

3-DOF Robot Trajectory Tracking: Obstacles and Lyapunov Stability

Share
Share this article Facebook
ROBOTICS LAB · INTERACTIVE TUTORIAL 02

Reaching a point is only the beginning. A useful manipulator must follow a moving reference, correct its errors and avoid the objects around it. This follow-up turns our 3-DOF arm into a trajectory tracker—and asks what we can actually prove about its behaviour.

In the first tutorial, we derived forward and inverse kinematics. Here we keep the same yaw–pitch–pitch geometry, derive its Jacobian, build a velocity controller and examine Lyapunov stability. Then we introduce spherical obstacles and a control-barrier safety filter.

Trajectory trackingWhole-link obstacle checksLyapunov & barrier functions
01 / TRY THE CONTROLLER

Follow a path, then put something in the way

Press Run simulation. The dashed curve is the desired tool path; the solid trace is what the robot achieves. The default sphere intersects the reference path, so perfect tracking and clearance cannot both be satisfied. Turn Obstacle avoidance off to compare the same starting state and reference.

Explore the workspace: drag the background to orbit the 3D camera, scroll or pinch to zoom, and use Shift-drag or right-drag to pan. The camera controls remain available while the arm moves. Drag a sphere to reposition it; choose View, XY, XZ or YZ as the drag plane. On touchscreens, two fingers zoom and pan.

Preparing the trajectory laboratory… Enable JavaScript to use the simulator; the complete mathematical explanation follows below.

Lengths in metres, angles in radians internally. The simulator commands joint velocities. It does not model motor torque, inertia, joint flexibility, ground collision or self-collision. Obstacles are static while the arm runs. Editing an obstacle pauses at the current pose and reference time; Run resumes there after a valid placement. Path and controller changes reset the experiment.

1. See the safety–tracking trade-off

Run the default circle with avoidance on, then off. Compare the minimum clearance with the dashed 6 cm threshold. Observe when V increases as the desired point moves through the obstacle.

2. Test the Lyapunov prediction

Select no obstacles and Hold a fixed target. Set damping to zero. With the default speed limit, the initial error decays close to the predicted exponential; small integration errors remain.

3. Explain tracking lag

Select a moving path, no obstacles, and turn velocity feedforward off. Feedback must create an error before it can command motion. Re-enable feedforward and compare the residual error.

4. Stress the assumptions

Choose the figure eight, shorten the period and lower the joint speed limit. More constraints become active. A larger feedback gain cannot make an infeasible reference feasible.

02 / FROM POSITION TO VELOCITY

Differentiate the arm geometry

Let \(\mathbf q=[q_1,q_2,q_3]^T\) contain the base yaw, shoulder pitch and elbow pitch. The two links have lengths \(L_1,L_2\), and the shoulder height is \(h\). Define the signed radial reach \(r\) and vertical offset \(z_r\):

Forward kinematics, recalled
\[ \begin{aligned} r&=L_1\cos q_2+L_2\cos(q_2+q_3),\\ z_r&=L_1\sin q_2+L_2\sin(q_2+q_3),\\ \mathbf p=f(\mathbf q)&=\begin{bmatrix}r\cos q_1\\r\sin q_1\\h+z_r\end{bmatrix}. \end{aligned} \]

For this laboratory, \(L_1=1.4\) m, \(L_2=1.1\) m and \(h=0.45\) m. The coordinate and positive-angle conventions follow Part 1.

A small joint motion produces a Cartesian motion through the position Jacobian, \(J=\partial f/\partial\mathbf q\). For example, \(\partial r/\partial q_2=-z_r\) and \(\partial r/\partial q_3=-L_2\sin(q_2+q_3)\). Differentiate all three position coordinates to obtain:

Analytical position Jacobian
\[ \dot{\mathbf p}=J(\mathbf q)\dot{\mathbf q},\qquad J=\begin{bmatrix} -r\sin q_1&-z_r\cos q_1&-L_2\sin(q_2+q_3)\cos q_1\\ r\cos q_1&-z_r\sin q_1&-L_2\sin(q_2+q_3)\sin q_1\\ 0&r&L_2\cos(q_2+q_3) \end{bmatrix}. \]

Its determinant is \(\det J=-rL_1L_2\sin q_3\). The position map loses rank when the tool lies on the yaw axis, \(r=0\), or when the planar links are fully extended or folded, \(\sin q_3=0\). A Cartesian request in a missing velocity direction cannot be recovered by simply increasing the controller gain. Haviland and Corke's differential-kinematics tutorial develops this velocity-level viewpoint in more general manipulators.

03 / SPECIFY THE MOTION

A trajectory has both a position and a velocity

A path describes a geometric curve. A trajectory also specifies where to be at each time. For a horizontal circle with centre \(\mathbf c\), radius \(a\), period \(T\) and angular frequency \(\omega=2\pi/T\), we choose:

Circular position and analytical feedforward
\[ \mathbf p_d(t)=\mathbf c+\begin{bmatrix}a\cos\omega t\\a\sin\omega t\\0\end{bmatrix},\qquad \dot{\mathbf p}_d(t)=\begin{bmatrix}-a\omega\sin\omega t\\a\omega\cos\omega t\\0\end{bmatrix}. \]

The lab uses \(\mathbf c=(1.35,0,1.00)\) m. Path size changes \(a\); period changes the speed without changing the geometric curve.

The 3D figure eight uses offsets \([a\cos\omega t,\;0.7a\sin2\omega t,\;0.16\sin\omega t]^T\). The smooth sweep uses \([a\cos\omega t,\;0.15\sin\omega t,\;0.20\sin\omega t]^T\); Hold fixes the offset at \([a,0,0]^T\). Their velocities are the analytical time derivatives. No finite-difference estimate of reference velocity is needed.

04 / CLOSE THE FEEDBACK LOOP

Combine feedforward with error correction

Define position error as actual minus desired: \(\mathbf e=\mathbf p-\mathbf p_d\). If Cartesian velocity were directly available, a natural command would be \(\mathbf v_c=\dot{\mathbf p}_d-k\mathbf e\), with \(k>0\). Feedforward supplies the planned motion; feedback corrects deviations. This is the velocity-control setting discussed in Modern Robotics.

Exact resolved-rate tracker
\[ \dot{\mathbf q}_{\mathrm{nom}}=J^{-1}\!\left(\dot{\mathbf p}_d-k\mathbf e\right) \quad\Longrightarrow\quad \dot{\mathbf e}=J\dot{\mathbf q}_{\mathrm{nom}}-\dot{\mathbf p}_d=-k\mathbf e. \]

This calculation assumes an invertible Jacobian, an accurate model and joint drives that execute the requested velocities. It also assumes the trajectory can be followed without violating constraints. A three-joint arm controlling three position coordinates has no spare joint velocity at a regular configuration: \(J^{-1}\mathbf v_c\) already uses all three degrees of freedom.

Regularise the inverse near a singularity

The implemented nominal command uses a damped least-squares inverse. It solves a small regularised velocity-matching problem:

Damped least squares
\[ \begin{aligned} \dot{\mathbf q}_{\mathrm{nom}} &=\underset{\mathbf u}{\operatorname{argmin}}\; \|J\mathbf u-\mathbf v_c\|^2+\lambda^2\|\mathbf u\|^2\\ &=J^T\!\left(JJ^T+\lambda^2I\right)^{-1}\mathbf v_c. \end{aligned} \]

With metres and radians as used here, \(J\) and \(\lambda\) carry compatible length scaling. The numerical value of \(\lambda\) is tied to these units. At \(\lambda=0\), the formula requires full rank.

Positive damping reduces large joint commands but introduces velocity mismatch. Joint speed and position limits are enforced separately by the optimisation described below. If damping is zero and the matrix cannot be reliably solved, the simulation pauses and asks for more damping.

05 / WHAT STABILITY MEANS

Prove the ideal tracking error decays

Lyapunov's direct method studies a scalar function along closed-loop solutions. It lets us establish stability without first solving every nonlinear trajectory; Tedrake's Lyapunov notes explain this framework. For our position error, choose

Lyapunov candidate and ideal derivative
\[ V(\mathbf e)=\tfrac12\mathbf e^T\mathbf e,\qquad \dot V=\mathbf e^T\dot{\mathbf e} =-k\|\mathbf e\|^2=-2kV. \]

Here \(V>0\) for nonzero error and \(V=0\) exactly at zero error. With the exact unconstrained controller, integrating the scalar equation gives

Exponential tracking-error convergence
\[ V(t)=V(0)e^{-2kt},\qquad \|\mathbf e(t)\|=\|\mathbf e(0)\|e^{-kt}. \]

Stability means a sufficiently small initial error stays small. Asymptotic stability additionally requires that the error tends to zero. This equation establishes exponential convergence of the position error while the assumptions remain valid. It does not establish global stability of every joint configuration: inverse branches are nonunique, joint limits exist and singularities can interrupt the feedback law.

Check a numerical point by hand

Take \(L_1=1.4\) m, \(L_2=1.1\) m and \(\mathbf q=(0,\pi/4,-\pi/2)\). Then \(r\approx1.7678\) m and \(z_r\approx0.2121\) m. For \(\mathbf e=(0.04,-0.03,0.02)\) m, \(\dot{\mathbf p}_d=(0,0.10,0)\) m/s and \(k=3\) s\(^{-1}\):

Exact, undamped and unconstrained example
\[ \mathbf v_c=\begin{bmatrix}-0.12\\0.19\\-0.06\end{bmatrix},\quad \dot{\mathbf q}_{\mathrm{nom}}\approx\begin{bmatrix}0.1075\\0.0303\\-0.1460\end{bmatrix}\;\mathrm{rad/s},\quad V=0.00145\;\mathrm{m}^2,\quad\dot V=-0.00870\;\mathrm{m}^2/\mathrm{s}. \]
06 / PROTECT THE WHOLE LINK

Turn obstacle clearance into a velocity constraint

A collision-free tool position does not imply a collision-free arm. Model each moving link as a capsule: a line segment thickened by radius \(r_\ell=0.045\) m. For an obstacle sphere of centre \(\mathbf o\) and radius \(R_o\), find the closest centreline point on each link:

Closest point on a link segment
\[ \begin{aligned} \tau&=\operatorname{clip}_{[0,1]} \frac{(\mathbf o-\mathbf A)^T(\mathbf B-\mathbf A)}{\|\mathbf B-\mathbf A\|^2},\\ \mathbf s(\mathbf q)&=\mathbf A(\mathbf q)+\tau\bigl(\mathbf B(\mathbf q)-\mathbf A(\mathbf q)\bigr). \end{aligned} \]

The endpoints are shoulder–elbow for the upper link and elbow–tool for the forearm. Inflate the obstacle by the link radius and the requested clearance \(d_s=0.06\) m. Define one barrier value for each obstacle–link pair:

Safe set and control-barrier condition
\[ \begin{aligned} R&=R_o+r_\ell+d_s,\qquad b(\mathbf q)=\|\mathbf s(\mathbf q)-\mathbf o\|^2-R^2,\\ b\ge0\quad&\Longleftrightarrow\quad\text{surface clearance}\ge d_s,\\ \dot b+\alpha b\ge0\quad&\Longleftrightarrow\quad 2(\mathbf s-\mathbf o)^T J_s\dot{\mathbf q}\ge-\alpha b,\qquad\alpha>0. \end{aligned} \]

For the squared closest-distance derivative, use \(J_s=(1-\tau)J_A+\tau J_B\). The extra term involving \(\dot\tau\) drops out: at an interior closest point, \((\mathbf s-\mathbf o)^T(\mathbf B-\mathbf A)=0\); at a persistent endpoint optimum, \(\tau\) is fixed. This gives the distance gradient without differentiating the clip operation explicitly.

The shoulder Jacobian is zero. The elbow Jacobian follows by differentiating its coordinates, exactly as for the tool:

Elbow velocity Jacobian
\[ J_E=\begin{bmatrix} -L_1\cos q_2\sin q_1&-L_1\sin q_2\cos q_1&0\\ L_1\cos q_2\cos q_1&-L_1\sin q_2\sin q_1&0\\ 0&L_1\cos q_2&0 \end{bmatrix}. \]

The fixed base capsule uses radius 0.08 m. It cannot move to escape an obstacle; an overlap with its required margin is rejected at the start. The moving-link constraints include the tool endpoint automatically.

Dragging edits a static scene while the arm is paused. The new placement is checked against the current complete arm before it is accepted; an overlap is rejected and the previous obstacle position restored. Each accepted edit starts a fresh diagnostic-history segment, preserving the robot pose and reference clock. Physically moving obstacles during execution would require their velocity in the barrier derivative.

Why the barrier condition preserves clearance

In the continuous-time model, \(\dot b\ge-\alpha b\) implies \(b(t)\ge b(0)e^{-\alpha t}\). Starting from \(b(0)\ge0\), the state remains in the safe set if the condition can be enforced throughout the motion and the closed-loop solution is well defined. The CBF quadratic-program framework of Ames and coauthors formalises this forward-invariance idea. This argument is a clearance statement, not a proof that the robot reaches its goal.

07 / TRACK AS CLOSELY AS CONSTRAINTS ALLOW

Project the tracker onto feasible joint velocities

At each simulation step, solve a three-variable quadratic programme. Its objective is to change the nominal joint-velocity command as little as possible while satisfying obstacle constraints and joint bounds:

Implemented safety filter
\[ \begin{aligned} \mathbf u^*&=\underset{\mathbf u\in\mathbb R^3}{\operatorname{argmin}}\; \tfrac12\|\mathbf u-\dot{\mathbf q}_{\mathrm{nom}}\|^2\\ \text{subject to }&\quad\mathbf a_j^T\mathbf u\ge-\alpha b_j \quad\text{for each moving link–sphere pair},\\ &\quad\underline u_i\le u_i\le\overline u_i,\\ \underline u_i&=\max\{-u_{\max},-\beta(q_i-q_{i,\min})\},\\ \overline u_i&=\min\{u_{\max},\beta(q_{i,\max}-q_i)\}. \end{aligned} \]

Here \(\mathbf a_j^T=2(\mathbf s_j-\mathbf o_j)^TJ_{s_j}\), \(\beta=4\) s\(^{-1}\), and the joint intervals in degrees are \([-150,150]\), \([-20,140]\), and \([-160,-10]\). Obstacles stay fixed during each run.

For a valid safe state with static obstacles, zero joint velocity satisfies all these inequalities. That provides a feasible fallback in the mathematical QP; it may mean stopping instead of tracking. The small solver checks the Karush–Kuhn–Tucker conditions by enumerating up to three independent active constraint normals. All computations stay inside the article; the simulator downloads no control library.

Local avoidance can stall

A three-DOF position tracker cannot generally keep its tool on an obstacle-crossing reference and also maintain clearance. This filter has no global route search. It can slow, deviate, or wait; it can also become stuck at a configuration from which local admissible motions do not make progress. A collision-free global path and time parameterisation are separate planning problems.

08 / READ THE ACTUAL LYAPUNOV DERIVATIVE

What damping and obstacles change in the proof

Let \(P_\lambda=JJ^T(JJ^T+\lambda^2I)^{-1}\), and write the executed velocity as \(\dot{\mathbf q}=\dot{\mathbf q}_{\mathrm{nom}}+\delta\mathbf u\). The correction includes the safety filter, joint limits and any swept-step reduction. With feedforward enabled, the actual error dynamics are

Actual continuous-time error identity
\[ \begin{aligned} \dot{\mathbf e}&=-kP_\lambda\mathbf e-(I-P_\lambda)\dot{\mathbf p}_d+J\delta\mathbf u,\\ \dot V&=-k\mathbf e^TP_\lambda\mathbf e -\mathbf e^T(I-P_\lambda)\dot{\mathbf p}_d +\mathbf e^TJ\delta\mathbf u. \end{aligned} \]

The first term reduces error. The other terms can oppose it. With a moving target, damping can create tracking lag. An obstacle can force the arm to move away from the desired point. The lab therefore displays actual \(\dot V=\mathbf e^T(J\dot{\mathbf q}-\dot{\mathbf p}_d)\) alongside the ideal value \(-2kV\); it does not impose a hard Lyapunov-decrease constraint in the QP.

For a more precise bound, suppose the Jacobian's smallest singular value stays at least \(\sigma_*>0\) in the region visited, damping is fixed, and \(\|\dot{\mathbf p}_d\|\le v_*\), \(\|J\delta\mathbf u\|\le d_*\). Then

Conditional error bound
\[ \begin{aligned} \mu&=\frac{\sigma_*^2}{\sigma_*^2+\lambda^2},\qquad \eta=\frac{\lambda^2}{\sigma_*^2+\lambda^2}v_*+d_*,\\ \dot V&\le-k\mu\|\mathbf e\|^2+\eta\|\mathbf e\|. \end{aligned} \]

Under those uniform assumptions, the bound is strictly negative outside the error ball \(\|\mathbf e\|\le\eta/(k\mu)\). This supports an ultimate-bound argument while the solution remains in that regular region. The simulator does not compute a certified \(\sigma_*\) or \(d_*\), so the formula is an analytical condition rather than an automatically certified performance radius.

A temporary positive \(\dot V\) does not by itself prove instability. It tells us that this error measure is increasing at that instant. For an obstacle-crossing reference, nonzero error is unavoidable; the original zero-error exponential proof no longer applies to the constrained motion.

09 / DISCRETE TIME IS PART OF THE MODEL

Check the motion between samples

The integrator uses a fixed step \(\Delta t=1/120\) s and \(\mathbf q_{n+1}=\mathbf q_n+\Delta t\,\mathbf u_n\). A continuous-time barrier inequality checked only at sample times is not, by itself, a sampled-data collision guarantee.

The lab adds a conservative geometric check along the linearly interpolated joint motion. For any corresponding point on either moving centreline, an angular increment \(\Delta\mathbf q\) gives the displacement bound

Conservative swept-step displacement bound
\[ B(\Delta\mathbf q)=(L_1+L_2)(|\Delta q_1|+|\Delta q_2|)+L_2|\Delta q_3|. \]

At the midpoint of an interval, if every obstacle–capsule clearance exceeds the requested margin by at least \(B/2\), the entire interpolated interval is certified clear by this bound. Otherwise the check bisects the interval, up to six levels. Uncertainty rejects the candidate step; the commanded motion is halved and checked again. If no candidate can be certified after ten attempts, the run pauses.

This check applies to the specified capsules, fixed spheres and joint interpolation, within numerical tolerance. It does not cover unmodelled geometry, moving obstacles or hardware dynamics. Turning avoidance off deliberately disables this check so that the baseline can demonstrate collisions.

ObservationInterpretation
V decays close to an exponentialThe exact-tracking assumptions are approximately satisfied.
Clearance holds while tracking error growsThe constrained tracker is prioritising separation from obstacles.
V settles above zeroCheck damping, missing feedforward, speed limits and reference feasibility.
The arm pauses or stallsA local feasible velocity or a certifiable integration step may not provide progress.
The tool is clear but a link collides in the baselineEnd-effector-only checks would have missed a whole-arm collision.

Use Export recent CSV to inspect up to the last 120 seconds of sampled positions, joint angles, executed velocities, error, V, actual V̇, clearance and command corrections. The curves show recent history; they are diagnostics from one numerical run, not a stability certificate.

10 / CONTINUE THE SERIES

From local tracking to planned motion

We now have a complete velocity-level loop: differentiate the geometry, track a timed reference, measure its error and constrain motion near obstacles. A useful next step is to plan a feasible path before tracking it, then add acceleration limits and a torque-level robot model. Each extension changes the assumptions required by the stability argument.

THE DISCUSSION

Comments

Ask a question, share a result, or add something useful.

0

Be the first to comment.Start the conversation below.