This must be an obvious and stupid question... I'm working on an Raspberry Pi 3 wired with an BerryIMU (9 ways of freedom). I'm getting the RAW values from the Accelerometer, but what the meaning of those values ?
(x, y)
(-57, 573)
(-56, 567)
(-64, 571)
(-59, 580)
(-56, 569)
(-30, 579)
(-59, 569)
(-61, 567)
(-34, 575)
(-59, 587)
(-43, 573)
(-74, 579)
(-56, 568)
(-58, 569)
If I had well understand, those are the acceleration in x and y. But what I'm not sure is what the unit ? m/s² ? (couldn't find on ozzmaker documentation...) Moreover, those values are taken while being stationary and I'm not sure of those values. I know that there is noise (I should use Kalman filter) that why the values aren't the same on each iteration. If those values are acceleration in m/s², I'm trying to calculate the velocity. Following is my current code :
import smbus
import time
import math
from LSM9DS0 import *
import datetime
bus = smbus.SMBus(1)
def writeACC(register,value):
bus.write_byte_data(ACC_ADDRESS, register, value)
return -1
def readACCx():
acc_l = bus.read_byte_data(ACC_ADDRESS, OUT_X_L_A)
acc_h = bus.read_byte_data(ACC_ADDRESS, OUT_X_H_A)
acc_combined = (acc_l | acc_h <<8)
return acc_combined if acc_combined < 32768 else acc_combined - 65536
def readACCy():
acc_l = bus.read_byte_data(ACC_ADDRESS, OUT_Y_L_A)
acc_h = bus.read_byte_data(ACC_ADDRESS, OUT_Y_H_A)
acc_combined = (acc_l | acc_h <<8)
return acc_combined if acc_combined < 32768 else acc_combined - 65536
def readACCz():
acc_l = bus.read_byte_data(ACC_ADDRESS, OUT_Z_L_A)
acc_h = bus.read_byte_data(ACC_ADDRESS, OUT_Z_H_A)
acc_combined = (acc_l | acc_h <<8)
return acc_combined if acc_combined < 32768 else acc_combined - 65536
def millis():
current_milli_time = int(round(time.time() * 1000))
return current_milli_time
#initialise the accelerometer
writeACC(CTRL_REG1_XM, 0b01100111) #z,y,x axis enabled, continuos update, 100Hz data rate
writeACC(CTRL_REG2_XM, 0b00100000) #+/- 16G full scale
velocity = 0.0
prevAcc = 0
prevTime = millis()
while True:
#Read the accelerometer,gyroscope and magnetometer values
ACCx = readACCx()
ACCy = readACCy()
ACCz = readACCz()
currTime = millis()
velocity += (ACCx + prevAcc) / 2 * (currTime - prevTime) / 1000
prevAcc = ACCx
prevTime = currTime
print("Vx:", velocity)
time.sleep(0.25)
The problem is, the velocity is increasing while the sensors is being stationary.
Thanks for your help.