OpenVex  0.5.0
Functions
Accelerometer functions

Functions

void read_accelerometer_axis (unsigned char port, int base_val, int scaling_factor, int *acceleration, long *velocity, long *position)
 

Detailed Description

These functions provide a high-level interface to the Vex accelerometer. Each axis of the accelerometer can also be read as a standard analog sensor using io_read_analog().

Function Documentation

◆ read_accelerometer_axis()

void read_accelerometer_axis ( unsigned char  port,
int  base_val,
int  scaling_factor,
int *  acceleration,
long *  velocity,
long *  position 
)

This function is unfinished. Velocity and position data are currently very unreliable. Filtering will be needed to correct this.

Return the current acceleration, velocity, and position along an axis for the accelerometer on the given analog port.

The accelerometer sensor provides the acceleration detected along each axis to a separate analog input port.

The integral of acceleration (area under the acceleration curve) is velocity. ( Acceleration is the derivative of velocity, i.e. acceleration = velocity / time. )

The integral of velocity (area under the velocity curve) is position. ( Velocity is the derivative of position, i.e. velocity = position / time. )

This function computes approximate velocity and position by summing acceleration * dt and velocity * dt, respectively. The dt term is the time of the function call minus the time of the previous call.

Since the computed area for each slice is a trapezoid that only approximates the area under the curve, a larger dt will produce greater errors. Hence, the more often this function is called, the better the approximations of velocity and position. ( Consult the introduction to integration in any calculus text for a detailed explanation with pretty pictures and everything. )

Since the velocity and position are sums of approximate slice areas, their inaccuracy increases over time. This makes minimizing dt all the more important.

The information returned by this function can use used in a PID loop to maintain position or velocity, for collision detection, tilt detection, etc.

Parameters
portAnalog port to which accelerometer is attached.
base_valThe value returned for this axis when no acceleration is present. This parameter is used to calibrate so that acceleration in both directions is measured equally.
scaling_factorValue to divide velocity and position by before returning them. You should determine this value by trial and error. It depends how much precision you want in these terms and how large you want to allow them to grow.
accelerationAddress of int variable to receive acceleration.
velocityAddress of int variable to receive velocity.
positionAddress of int variable to receive position.