mardi 30 mai 2017

Accelerometer, Android, Simulate replace current Data with Old one

  1. I need a way to replace real accelerometer data from phone sensor with other one old data (x,y,z) that currently i have at Excel table and array at Android. Maybe i need to write my own class Sensor or?

    Because i want to test my app with them

  2. Does i calculate linear acceleration right.

    private float timeConstant = 0.18f;
    private float alpha = 0.7f;
    private float dt = 0;
    // Timestamps for the low-pass filter
    private float timestamp = System.nanoTime();
    private float timestampOld = System.nanoTime();
    
    

    (...)

    @Override public void onSensorChanged(SensorEvent sensorEvent) { Sensor accSensor = sensorEvent.sensor;

    if (accSensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        System.arraycopy(sensorEvent.values, 0, this.accelerationOnAxis, 0, sensorEvent.values.length);
    
        x_accelerometer = sensorEvent.values[0];
        y_accelerometer = sensorEvent.values[1];
        z_accelerometer = sensorEvent.values[2];
        //timestampOld = timestamp;
        timestamp = System.nanoTime();
    
        float deltaTime = timestamp - timestampOld;
    
        dt = 1 / (count / ((deltaTime) / 1000000000.0f));
    
        count++;
    
        alpha = timeConstant / (timeConstant + dt);
        // long tDelta = currentUpdate.getTime() - lastUpdate.getTime();
        // long t = 1 / (2 * Math.PI * fc);
        //alpha = t / (t + tDelta);
    
        x_gravity = alpha * x_gravity + (1 - alpha) * x_accelerometer;
        y_gravity = alpha * y_gravity + (1 - alpha) * y_accelerometer;
        z_gravity = alpha * z_gravity + (1 - alpha) * z_accelerometer;
    
        x_linear_acceleration = x_accelerometer - x_gravity;
        y_linear_acceleration = y_accelerometer - y_gravity;
        z_linear_acceleration = z_accelerometer - z_gravity;
    
        gravityOnAxis = new float[]{x_gravity, y_gravity, z_gravity};
        linearAcceleration = new float[]{x_linear_acceleration, y_linear_acceleration, z_linear_acceleration};
    
        int length = linearAcceleration.length - 1;
        Log.d("LinearAccelOnAxes", "on x-" + x_linear_acceleration +
                "on y-" + y_linear_acceleration +
                "on z-" + z_linear_acceleration);
    
        allAccelData.add(linearAcceleration);
    
    

    /// } } currentAcceleration = (float) (Math.pow(x_linear_acceleration, 2) + Math.pow(y_linear_acceleration, 2)+ Math.pow(z_linear_acceleration, 2));

}

Thank You

Aucun commentaire:

Enregistrer un commentaire