View Single Post
  #6   Spotlight this post!  
Unread 15-01-2006, 12:56
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: Dual-Axis Accelerometer

Quote:
Originally Posted by sciguy125
I'm sure that you need to figure out the bias. However, you also might want to make sure that it's level. Remember that gravity will register on an accelerometer.
Here's my first-cut at code that will give an angle relative to the gravity vector, which points down. I'm working on a calibration routine for the bias,
but for now, just assume it's at the 2.5v mid-point. This code will work with the ADC code on my website. I imagine this code would work great for knowing what angle your ball launcher was at.

-Kevin

Code:
 
int Accel_Angle(void)
{
int x_axis;
int y_axis;
int angle;
 
x_axis = (int)Get_ADC_Result(X_AXIS_CHANNEL) - X_AXIS_BIAS;
 
y_axis = (int)Get_ADC_Result(Y_AXIS_CHANNEL) - Y_AXIS_BIAS;
 
angle = (int)(ANGULAR_CONVERSION * atan2((float)y_axis, (float)x_axis));
 
return(angle);
}
 
 
Here are the constants:

Code:
// Analog channel on the robot controller that's hooked-up to
// the x-axis accelerometer
#define X_AXIS_CHANNEL 1

 
// Analog channel on the robot controller that's hooked-up to
// the y-axis accelerometer
#define Y_AXIS_CHANNEL 2
 
// 800Hz sample rate & 16 samples averaged per update (see adc.h)

#define X_AXIS_BIAS 2048

#define Y_AXIS_BIAS 2048
 

// Pick the angular unit by removing the // from one of these two lines.
// #define MILLIRADIANS
// #define TENTHS_OF_A_DEGREE
#define DEGREES
 
 
#ifdef MILLIRADIANS
#define ANGULAR_CONVERSION 1000.0// milliradians per radian
#endif
 
#ifdef TENTHS_OF_A_DEGREE
#define ANGULAR_CONVERSION 573.0// tenths of a degree per radian
#endif
 
#ifdef DEGREES
#define ANGULAR_CONVERSION 57.3// degrees per radian
#endif
 
// function prototypes
int Accel_Angle(void);
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org