Learn R Programming

animalTrack (version 1.0.0)

pitch2: Calculate pitch angle.

Description

calculate pitch angle using measurements from a three-axis accelerometer and roll angle.

Usage

pitch2(x, y, z, roll)

Arguments

x
a numeric vector of x-axis values.
y
a numeric vector of y-axis values.
z
a numeric vector of z-axis values.
roll
numeric vector of roll angles. ($-\pi \le$ roll $\le \pi$)

Value

  • an object of pitch values (in radians) from $-\pi/2 \le$ pitch $\le \pi/2$

Details

pitch2() will return a pitch angle (in radians) representing the posterior-anterior axis position of the animal. This angle is the difference between the posterior-anterior axis (vector) of the animal and the horizon. This angle is calculated assuming the NED (north, east, down) frame of reference. Typically, this is measured with an accelerometer and is scaled from -1 to +1. Using the NED frame of reference means that when the accelerometer is measuring 1g, this is equal to -9.8 $m/s^2$. Also, if the axis is aligned with the earth gravity vector (i.e. down, towards the center of the earth), it should have a value of +1. Pitch angle is calculated by $$pitch = atan(-x/(y*sin(roll)+(z*cos(roll))) )$$ A positive pitch value indicates that the nose of the animal (x-axis) is pitched upward (toward the sky). Conversely, a negative pitch angle indicates that the animal is pitched downward. (Note: axis values must be converted to NED frame of reference prior to using this function)

References

Ozyagcilar, T. (2012), Implementing a tilt-compensated eCompass using accelerometer and magnetometer sensors. Freescale semiconductor, AN 4248, Rev. 3. Smith, K. J. (1998), Essentials of Trigonometry. Pacific Grove, CA: Brooks/Cole.

See Also

pitch atan

Examples

Run this code
## 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