‘imuf’ uses complementary filtering to estimate the orientation of an inertial measurement unit (IMU) with a 3-axis accelerometer and a 3-axis gyroscope. It takes the IMU’s accelerometer and gyroscope readings, time duration, its initial orientation, and a ‘gain’ factor as inputs, and provides an estimate of the final orientation as outputs.
‘imuf’ adopts the north-east-down (NED) coordinate system. The initial and final orientations are expressed as quaternions in (w, x, y, z) convention.
install.packages("imuf")
You can install the development version of imuf from GitHub with:
# install.packages("pak")
::pak("gitboosting/imuf") pak
This is a basic example which shows you how to solve a common problem:
library(imuf)
#
<- c(0, 0, -1) # accelerometer NED readings in g (~ 9.81 m/s^2)
acc <- c(1, 0, 0) # gyroscope NED readings in radians per second
gyr <- 0.1 # time duration in seconds
deltat <- c(1, 0, 0, 0) # initial orientation expressed as a quaternion
initq <- 0.1 # a weight (0-1) given to the accelerometer readings
gain #
# final orientation expressed as a quaternion
<- compUpdate(acc, gyr, deltat, initq, gain))
(final #> [1] 0.99898767 0.04498481 0.00000000 0.00000000
#
#
# rotate a vector pointing east by 90 deg about north
<- c(cos(pi/4), sin(pi/4), 0, 0) # quaternion to rotate 90 deg about north
q <- c(0, 1, 0) # vector in east direction
vin <- rotV(q, vin)) # after rotation, vector is in down direction
(vout #> [1] 0.000000e+00 2.220446e-16 1.000000e+00