From a gyroscope I'm getting angular velocities [dRoll, dPitch and dYaw] as rad/s, sampled at intervals dt = 10ms.
How do I calculate the short term global orientation (drift ignored) of the gyroscope?
Pseudo code would be helpful.
Robotics Stack Exchange is a question and answer site for professional robotic engineers, hobbyists, researchers and students. It only takes a minute to sign up.
Sign up to join this communityFrom a gyroscope I'm getting angular velocities [dRoll, dPitch and dYaw] as rad/s, sampled at intervals dt = 10ms.
How do I calculate the short term global orientation (drift ignored) of the gyroscope?
Pseudo code would be helpful.
gyroscopes do not measure [dRoll ,...] they measure body rates. These are not the same things. There is a transformation matrix ( that I do not have on hand) that relates body rates to euler rates. The euler rates are then integrated to get the short term change in orientation.
-- relation --
this is the relation between the measured body rates from the imu and the euler rates.
\begin{equation} \label{eq:euler_rates} \begin{bmatrix} \dot \phi \\ \dot \theta \\ \dot \psi \end{bmatrix} = \begin{bmatrix} 1 & \sin\phi \tan\theta & \cos\phi \tan\theta \\ 0 & \cos\phi & -\sin\phi \\ 0 & \frac{\sin\phi}{\cos\theta} & \frac{\cos\phi}{\cos\theta} \end{bmatrix} \begin{bmatrix} p \\ q \\ r \end{bmatrix} \end{equation}
where $\left[ p, q, r \right] ^T$ are the body rates measured from the imu.
Short answer: A gyroscope by itself cannot determine its global reference frame. You either need to start the device in a known initial global orientation and measure how much the orientation changes, or you need other devices to determine the "initial" or periodic global reference frame.
Long answer:
A gyroscope only gives you angular velocities, which then can be integrated into relative yaw, pitch, and roll from a starting point. This is a 3 degrees of freedom (3dof) system.
This can be combined with an accelerometer which measures the acceleration. If your device starts in a stationary position, the accelerometer can then be used to measure the direction of gravity and establish the initial "down" direction towards gravity. You now know the initial direction of down (but not north/south/east/west). This is a 6dof system.
Next, you can combine the above two with a magnetometer. This detects magnetic fields including magnetic north. Your device in its stationary starting position can determine which direction is north. You now know the initial down position and the initial north direction in the global reference frame. This is a 9dof system.
To get the orientation from each of the axes, you need to integrate the angular velocities with respect to time.
Below is the code implementation of the said integration:
//What we have
dPitch = 0; angular rate from Pitch
dRoll = 0; angular rate from Roll
dYaw = 0; angular rate from Yaw
//What we want
aPitch = 0; angle from Pitch
aRoll = 0; angle from Roll
aYaw = 0; angle from Yaw
//Calculating the angles:
aPitch += dPitch*dt; // or aPitch = aPitch + dPitch*dt;
aRoll += dRoll*dt; // or aRoll = aRoll + dRoll*dt;
aYaw += dYaw*dt; // or aYaw = aYaw + dYaw*dt;