View Single Post
  #4   Spotlight this post!  
Unread 07-02-2009, 00:07
oddjob oddjob is offline
Registered User
no team
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Earth
Posts: 118
oddjob is a splendid one to beholdoddjob is a splendid one to beholdoddjob is a splendid one to beholdoddjob is a splendid one to beholdoddjob is a splendid one to beholdoddjob is a splendid one to beholdoddjob is a splendid one to behold
Re: Converting accelerometer values???

I'm using Windriver, not LabView. The basic idea is to integrate the accelerometer output to get velocity, and integrate velocity to get distance.

Code:
#define X_ACC_ZERO 1.5
#define Y_ACC_ZERO 1.5

  AnalogChannel *m_accelerometerX;
  AnalogChannel *m_accelerometerY;
  m_accelerometerX = new AnalogChannel(2);
  m_accelerometerY = new AnalogChannel(3);

// initialize:
  XVelocity = 0.0;
  YVelocity = 0.0;
  XDistance = 0.0;
  YDistance = 0.0;

// periodic:
		XVelocity += m_accelerometerX->GetVoltage() - X_ACC_ZERO;
		YVelocity += m_accelerometerY->GetVoltage() - Y_ACC_ZERO;
		XDistance += XVelocity;
		YDistance += YVelocity;
You'll probably have to add code to manage drift, shocks due to collisions, etc., which will cause the velocity and distance variables to diverge from the actual robot velocity and distance traveled. Depending on what you need the numbers for, you might need to convert the units e.g. to actual velocity in m/s. Note that 1G is 9.81 m/(s*s) so that's a start.

Last edited by oddjob : 07-02-2009 at 00:12.