How to calculate running speed using accelerometer sensor ?

asked 2015-12-14 07:24:38 -0500

Hakan Bey gravatar image

Hi guys,

I am working with accelerometer sensor. I would like to turn speed value that you got. what should I do ? can you help me

Me code;

 #include<Wire.h>
const int MPU_addr=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;

void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
  Serial.begin(57600);
}
void loop(){
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 registers
  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)    
  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
  GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
  GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
  GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
  Serial.print("AcX = "); Serial.print(AcX);
  Serial.print(" | AcY = "); Serial.print(AcY);
  Serial.print(" | AcZ = "); Serial.print(AcZ);
  Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53);  //equation for temperature in degrees C from datasheet
  Serial.print(" | GyX = "); Serial.print(GyX);
  Serial.print(" | GyY = "); Serial.print(GyY);
  Serial.print(" | GyZ = "); Serial.println(GyZ);

Serial.print("HIZ:");Serial.println(sqrt( AcX^2 + AcY^2 + AcZ^2));      


  delay(333);
}

And me values Arduino com;

AcX = 0 | AcY = 0 | AcZ = 0 | Tmp = 36.53 | GyX = 0 | GyY = 0 | GyZ = 0
HIZ:1.41
AcX = 1112 | AcY = 15716 | AcZ = -3776 | Tmp = 26.27 | GyX = -624 | GyY = 2157 | GyZ = -1428
HIZ:nan
AcX = 976 | AcY = 15700 | AcZ = -4280 | Tmp = 26.46 | GyX = -493 | GyY = 266 | GyZ = -177
HIZ:nan
AcX = 900 | AcY = 15660 | AcZ = -4176 | Tmp = 26.46 | GyX = -522 | GyY = 287 | GyZ = -157
HIZ:nan
edit retag flag offensive close merge delete

Comments

2

I didn't read through your code, but just giving a heads up that calculating velocity by integrating acceleration from an accelerometer will not be accurate at all. Here are some sources: http://www.chrobotics.com/library/acc... , http://stackoverflow.com/questions/782

Airuno2L gravatar image Airuno2L  ( 2015-12-14 07:55:57 -0500 )edit

Only way to do this that I can think about is to wear the accelerometer and run with many different speeds, thus collecting a lot of data. Then you can try applying some motion segmentation algorithms to recognize one running stride, isolate this data and do some machine learning to learn speed.

Mehdi. gravatar image Mehdi.  ( 2015-12-14 09:01:39 -0500 )edit

Opps, my second link was cut short and I can't edit it. Here it is: http://stackoverflow.com/questions/78...

Airuno2L gravatar image Airuno2L  ( 2015-12-14 09:25:57 -0500 )edit

Okey, I will try thanks.

Hakan Bey gravatar image Hakan Bey  ( 2015-12-15 02:49:16 -0500 )edit

First: This is not ros-related, but Arduino stuff. Second, there are far better approaches to do this. Accelerometer data is not suitable to be integrated. You will have to have some kind of reference system if you wanna do that. For intermediate precision you could use an GPS-based approach

segmentation_fault gravatar image segmentation_fault  ( 2018-08-22 06:40:35 -0500 )edit

Another way to approach is to permanently meassure the distance between your feets and also count the steps that you're doing.

segmentation_fault gravatar image segmentation_fault  ( 2018-08-22 06:44:39 -0500 )edit