## Import the yaw, pitch and roll simulated calibration dataset. For
## an explanation of the data use help(yprsim).
data(yprsim)
## Accelerometer axes
ax <- yprsim$ax
ay <- yprsim$ay
az <- yprsim$az
## Calculate roll
theta <- roll(ay, az)
## Calculate pitch (the nose/x-axis is rotated downward through 2 full rotations)
phi <- pitch2(ax, ay, az, theta)
## Plot
plot(phi*(180/pi),type='l',lty=1,lwd=2,xlab="time (s)",ylab="pitch (degrees)",
main="Pitch2 Calculation (2 pitch rotations)")
abline(v=c(126,252),lty=3,lwd=2)
legend(-10,70,legend=c("Pitch","Change in
Rotation"),
col=c("black","black"),lty=c(1,3),bty="n")
text(50,-70,"Yaw");text(175,-70,"Pitch");text(320,-70,"Roll")
Run the code above in your browser using DataLab