# Quaternionic feedback for for cartesian impedance control

I've seen that there are plenty of ways of generating orientation errors with quaternions. But the one I've seen most often is the following:

For example, say that for a quaternion $$Q = \{\eta, \epsilon \}$$ that represents the quaternion associated with the rotation matrix $$R$$. Similarly, the orientation error can be described as $$R_d R^\intercal$$. This leads to the following idea:

\begin{align} \Delta Q = Q_d * Q^{-1} \end{align}

Where we have the orientation error: $$\Delta Q = \{\Delta\eta, \Delta\epsilon \}$$. It can be recognized that if the orientation error is $$\Delta Q = \{1, 0 \}$$, if we have $$R$$ and $$R_d$$ are aligned. Hence it is sufficient to represent the orientation error as:

\begin{align} e_o = \epsilon_\Delta = \eta_d \epsilon - \eta \epsilon_d - S(\epsilon_d) \epsilon \end{align}

Where $$S(\cdot)$$ is the skew symmetric operator.

I am scratching my head over this. I saw someone try implementing this method from this blog, and it was mentioned in the comments section that this proposed method only works for the geometric Jacobian $$J(q)_g$$ and not an analytic jacobian $$J_A(q)$$ for quaternions. This leads to the complication because:

If we define the trajectory vectors as:

\begin{align} x = \begin{bmatrix}p_p \\ p_o\end{bmatrix} \quad \dot{x} = \begin{bmatrix}\dot{p}_p \\ \dot{p}_o\end{bmatrix} \quad \ddot{x} = \begin{bmatrix}\ddot{p}_p \\ \ddot{p}_o\end{bmatrix} \end{align}

What is $$p_o$$ ? is it just the vector part of the quaternion $$\epsilon$$ ? And what about singularities? I'm curious about this because this relates to the choice of the Jacobian (geometric or analytical) and the desired mass, dampig and stiffness matrices (dimensions) when computing the dynamics equation:

\begin{align} \Lambda(x) \ddot{x} + \mu (x, \dot{x}) \dot{x} + F_g(x) = F_\tau + F_{ext} \end{align}

where: \begin{align} \Lambda(x) &= J(q)^{-\intercal} M(q) J(q)^{-1}, \\ \mu(x, \dot{x}) &= J(q)^{-\intercal} \Big(C(q, \dot{q}) - M(q) J(q^{-1} \dot{J}(q)) \Big) J(q)^{-1} \end{align}

As you can see, the Jacobian is used a lot and if I were to implement the classical cartesian impedance controller:

$$\tau = g(q) + J(q)^\intercal (\Lambda(x) \ddot{x}_d + \mu(x, \dot{x}) \dot{x}) - \\ J(q)^\intercal \Lambda(x) \Lambda_d^{-1} (K_d \tilde{x} + D_d \dot{\tilde{x}}) +\\ J(q)^\intercal (\Lambda(x) \Lambda_d^{-1} - I) F_{ext}$$

It complicates the dimensions of the desired mass $$\Lambda_d$$ , damping $$D_d$$ and stiffness $$K_d$$.

TLDR; How do I use quaternions for a classical cartesian impedance controller?

For context: