Professional Documents
Culture Documents
Complementary Filtering!
Gordon Wetzstein!
Stanford University!
!
wikipedia!
Lecture Overview!
oculus.com!
from lecture 2:!
vertex in clip space! vertex!
oculus.com!
from lecture 2:!
vertex in clip space! vertex!
oculus.com!
from lecture 2:!
vertex in clip space! vertex!
rotation! translation!
T ( "eye )
M view = R !T
oculus.com!
from lecture 2:!
vertex in clip space! vertex!
rotation! translation!
T ( "eye )
M view = R !T
M view = R !T ( "eye )
( )
R = Rz ( !" z ) # Rx ( !" x ) # Ry !" y
roll! pitch! yaw!
oculus.com!
Remember: Dead Reckoning with Gyro!
! use only accelerometer data can estimate pitch & roll, not yaw!
! assume no external forces (only gravity) acc is pointing UP!!
normalize gravity vector in
inertial coordinates!
! 0 $ ! 0 $
1
a! # &
( )
a! = R # 1 & = Rz ( '( z ) ) Rx ( '( x ) ) Ry '( y # 1 &
# &
" 0 % " 0 %
! use only accelerometer data can estimate pitch & roll, not yaw!
! assume no external forces (only gravity) acc is pointing UP!!
! 0 $ ! 0 $
1
a! # &
( )
a! = R # 1 & = Rz ( '( z ) ) Rx ( '( x ) ) Ry '( y # 1 &
# &
" 0 % " 0 %
# cos ( !" ) ! sin ( !" ) 0 & # 1
%
z z
(%
0 0
(%
( )
& # cos !" y 0 ( )
sin !" y &
(# 0 &
= % sin ( !" ) cos ( !" ) 0 ( % 0 cos ( !" x ) ! sin ( !" x ) (% 0 1 0 (% 1 (
% ( %$ 0 ('
( ) ( )
z z
% (%
1 ' $ 0 sin ( !" x ) cos ( !" x )
( % ! sin !" 0 cos !" y ('
$ 0 0 '$ y
Pitch and Roll from Accelerometer!
! use only accelerometer data can estimate pitch & roll, not yaw!
! assume no external forces (only gravity) acc is pointing UP!!
! use only accelerometer data can estimate pitch & roll, not yaw!
! assume no external forces (only gravity) acc is pointing UP!!
roll!
# ! sin ( !" ) cos ( !" ) &
ax ! sin ( !" z )
% ( = ! tan ( !" z )
z x
1
a! = % cos ( !" z ) cos ( !" x )
=
a =
a!
( ay cos ( !" z )
% (
%$ sin ( !" x ) ('
( )
! z = "atan2 " ax , ay in rad !["# , # ]
Pitch and Roll from Accelerometer!
! use only accelerometer data can estimate pitch & roll, not yaw!
! assume no external forces (only gravity) acc is pointing UP!!
pitch!
# ! sin ( !" ) cos ( !" ) &
sin ( !" x )
% (
z x az
1 =
a = a! = % cos ( !" z ) cos ( !" x ) ( ax2 + ay2 (
cos 2 ( !" x ) sin 2 ( !" z ) + cos 2 ( !" z ) )
a! % (
%$ sin ( !" x ) (' =1
sin ( !" x )
= = tan ( !" x )
cos ( !" x )
Pitch and Roll from Accelerometer!
! use only accelerometer data can estimate pitch & roll, not yaw!
! assume no external forces (only gravity) acc is pointing UP!!
pitch!
# ! sin ( !" ) cos ( !" ) &
sin ( !" x )
% (
z x az
1 =
a = a! = % cos ( !" z ) cos ( !" x ) ( ax2 + ay2 (
cos 2 ( !" x ) sin 2 ( !" z ) + cos 2 ( !" z ) )
a! % (
%$ sin ( !" x ) (' =1
( $
% ) '
! x = "atan2 az , ax2 + ay2 in rad ! & " 2 , 2 )
(
# #
Pitch and Roll from Accelerometer!
! use only accelerometer data can estimate pitch & roll, not yaw!
! assume no external forces (only gravity) acc is pointing UP!!
pitch!
az sin ( !" x )
=
ax2 + ay2 (
cos 2 ( !" x ) sin 2 ( !" z ) + cos 2 ( !" z ) )
=1
( ( ) )
! x = "atan2 az ,sign ay # ax2 + ay2 in rad ![ "# , # ]
Tilt Correction!
! remember: !
! gyro is reliable in the short run, but drifts over time, mainly
due to accumulation of integration error!
! accelerometer is noisy and affected by motion, thus
reliable in the long run but not over short periods of time!
! with accelerometer, can only measure tilt not heading!
Tilt Correction with Complementary Filtering!
pitch:! ( ( ( )
! x = " (! x + # x $t ) + (1% " ) rad2deg %atan2 az ,sign ay & ax2 + ay2 ))
yaw:! ! y = ! y + " y #t
roll:! ( (
! z = " (! z + # z $t ) + (1% " ) rad2deg %atan2 % ax , ay )) 0 !" !1
Tilt Correction with Complementary Filtering!
pitch:! ( ( ( )
! x = " (! x + # x $t ) + (1% " ) rad2deg %atan2 az ,sign ay & ax2 + ay2 ))
yaw:! ! y = ! y + " y #t
roll:! ( (
! z = " (! z + # z $t ) + (1% " ) rad2deg %atan2 % ax , ay )) 0 !" !1
Example: Pitch!
accelerometer!
complementary filter!
Euler Angles and Gimbal Lock!
The Guerrilla CG Project, The Euler (gimbal lock) Explained see youtube.com!
Rotations with Axis and Angle Representation!
y!
! axis and angle: !
x!
z!
Quaternions!!
Quaternions!
! whats a quaternion?!
! extension of complex numbers 3 imaginary numbers!
q = q0 + q1i + q2 j + q3k
!
i 2 = j 2 = k 2 = ijk = !1
i! j!k
Quaternions!
! whats a quaternion?!
! singularity-free description of rotation!
" ! ! ! !%
q (! ,v ) = $ cos , vx sin , vy sin , vz sin '
# 2 2 2 2&
Quaternions!
" ! ! ! !%
q (! ,v ) = $ cos , vx sin , vy sin , vz sin '
# 2 2 2 2&
angle in unit-length
radians! axis!
" ! ! ! !%
q (! ,v ) = $ cos , vx sin , vy sin , vz sin '
# 2 2 2 2&
s = 1! q02
q1 q2 q3
v x = , v y = , vz =
s s s
Quaternion Algebra!
!1q*
! inverse:! q = 2
q
Quaternion Algebra!
multiplication:! qp = ( q0 + q1i + q2 j + q3 k ) ( p0 + p1i + p2 j + p3 k )
= ( q0 p0 q1 p1 q2 p2 q3 p3 ) +
( q0 p1 + q1 p0 + q2 p3 q3 p2 ) i
( q0 p2 q1 p3 + q2 p0 + q3 p1 ) j
( q0 p3 + q1 p2 q2 p1 + q3 p0 ) k
Quaternion Algebra!
measurements:! != !
! (
! x ,!
! y ,!
!z ) magnitude:! !
l= !
need this in radians / second!!
# 1 & # # !tl & "! x # !tl & "! y # !tl & "! z # !tl & &
q! = q % !tl, "! ( = % cos %
$ 2 (' l %$ ( %$ ( %$ (
, sin , sin , sin
$ l ' $ 2 ' l 2 ' l 2 ' ('
measurements:! != !
! (
! x ,!
! y ,!
!z ) magnitude:! !
l= !
need this in radians / second!!
# 1 & # # !tl & "! x # !tl & "! y # !tl & "! z # !tl & &
q! = q % !tl, "! ( = % cos %
$ 2 (' l %$ ( %$ ( %$ (
, sin , sin , sin
$ l ' $ 2 ' l 2 ' l 2 ' ('
(t+!t ) (t )
q = q q!
# 1 & # # !tl & "! x # !tl & "! y # !tl & "! z # !tl & &
q! = q % !tl, "! ( = % cos %
$ 2 (' l %$ ( %$ ( %$ (
, sin , sin , sin
$ l ' $ 2 ' l 2 ' l 2 ' ('
(t+!t ) (t )
q = q q!
qa ( inertial)
= q qa(t ) ( body ) (t )!1
q (
, qa = 0, a! x , a! y , a! z )
! qa( body ) ,qa( inertial) are vector quaternions !
Tilt Correction with Quaternions!
! 6DOF sensor fusion to stabilize drift w.r.t. tilt (pitch and roll)!
Tilt Correction with Quaternions!
!1
( inertial)
1.! compute accelerometer in inertial coords! qa = q(t )qa( body )q(t )
( inertial)
2.! get normalized vector part of vector quaternion! qa
$# qa ) '
'&
Tilt Correction with Quaternions!
4.! compute normalized rotation axis between v and UP with
cross product!
# vz vx &
vtilt = v ! ( 0,1,0 ) = % " 2 2 ,0, 2 2 (
$ v x + vz v x + vz '
(t+!t )
qtilt _ corrected = q (( ) tilt ) gyro 0 ! " ! 1
1" # $ ,v q (t+!t )
(t+!t )
where qgyro = qtilt
(t )
_ corrected q!
is the updated rotation
quaternion from only the gyro measurements (see slide 42)!
Complementary Filter!
(t+!t )
qtilt _ corrected = q (( ) tilt ) gyro 0 ! " ! 1
1" # $ ,v q (t+!t )
y !x !z
y
lh
ln IMU!
ln
!z x
pitch around base of neck!! roll around base of neck!!
Head and Neck Model!
Note: I found that none of these papers alone are free of errors or follow the
coordinate system we use, so its best to use them as general guidelines but follow
our notation in class!!