Log in

View Full Version : Accelerometer class - isn't reading zero at rest?


oddjob
02-02-2009, 12:44
Do we have a bad KoP board or the code is wrong or missing some setup?


...

// Declare variables for the 3 axis accelerometer (2 channels wired)
Accelerometer *m_accelerometerX;
Accelerometer *m_accelerometerY;

...

// create accelerometers
m_accelerometerX = new Accelerometer(2);
m_accelerometerY = new Accelerometer(3);

...

//m_accelerometerX->SetSensitivity(0.0);
//m_accelerometerY->SetSensitivity(0.0);
//m_accelerometerX->SetZero(0.0);
//m_accelerometerY->SetZero(0.0);

...

accX = m_accelerometerX->GetAcceleration();
accY = m_accelerometerY->GetAcceleration();
...



The accX and accY values are about 1.5 each when the board is at rest. Do we need to use SetZero? I tried putting in 1.5 for the value and then accX went to an entirely different non zero value, -2.5 or something like that. Can I just use AnalogChannel and do the scaling in the code?

EricVanWyk
02-02-2009, 12:47
You certainly can.

Before you do, be sure you are telling the class that your center point is 1.5V and your sensitivity is 300mV/g. I *think* the class assumes a different model.

kiettyyyy
02-02-2009, 14:09
The classes aren't really documented.

How do you set the center point to 1.5V? How do you set the sensitivity to 300mV/g?

From what I can tell, the accelerometer class contains the function calls of SetZero() and SetSensitivity().

How do you use these?

Jared Russell
02-02-2009, 17:11
If you read the WPILib source code, it gives you some hints.


/**

* Set the accelerometer sensitivity.

*

* This sets the sensitivity of the accelerometer used for calculating the acceleration.

* The sensitivity varys by accelerometer model. There are constants defined for various models.

*

* @param sensitivity The sensitivity of accelerometer in Volts per G.

*/

void Accelerometer::SetSensitivity(float sensitivity)

{

m_voltsPerG = sensitivity;

}

...

/**

* Set the voltage that corresponds to 0 G.

*

* The zero G voltage varys by accelerometer model. There are constants defined for various models.

*

* @param zero The zero G voltage.

*/

void Accelerometer::SetZero(float zero)

{

m_zeroGVoltage = zero;

}


So for the KoP accelerometer (zero G = 1.5V, sensitivity = 300mV/G), call:


myAccelerometer->SetZero(1.5);
myAccelerometer->SetSensitivity(0.3);