How to deal with Quaternion in acados

Hi :wave:

I am implementing a IMU Kinematic Model, in that the rotation was represented as unit quaternion.

the navigation equations was implemented like the blow code
image

  q_dot = 0.5 * quatmultiply_casadi(q, vertcat(0, gyroMeas - b_omega - n_omega))



  def quatmultiply_casadi(q1, q2):
     # Multiply two quaternions using CasADi symbolic variables.
      q = SX(4, 1)
      q[0] = q1[0]*q2[0] - q1[1]*q2[1] - q1[2]*q2[2] - q1[3]*q2[3]
      q[1] = q1[0]*q2[1] + q1[1]*q2[0] + q1[2]*q2[3] - q1[3]*q2[2]
      q[2] = q1[0]*q2[2] - q1[1]*q2[3] + q1[2]*q2[0] + q1[3]*q2[1]
      q[3] = q1[0]*q2[3] + q1[1]*q2[2] - q1[2]*q2[1] + q1[3]*q2[0]
      
      return q

the right side of the q_dot will return a 4D vector. Can the ERK integrator solve the equation? Is the results also a 4D vector?

the 4D vector was stored in state vector, but I think they should be handled as one quaternion.

how to formulate a quaternion, when the casadi expression are used?

Kind Regards
Lingbing

Hi Lingbing,

here is an acados example which uses quaternions.

I hope this helps.

Best,
Jonathan