我正在开发一个应用程序,以查找Android手机相对于我正在从事的机器人项目的某个起点的位置。机器人可以行驶的最大范围是12平方英尺乘12平方英尺。我也乐于接受其他方法。目前,我正在使用加速度计来查找机器人在现场的位置,但是机器人上的噪音干扰了积分计算。这是我的代码的副本。

   double currentVelocity;
   double currentPosition;
   float noise[] = new float[3];
   float alpha = (float) 0.1;
   private static final double timeInterval = .25;

public void onSensorChanged(SensorEvent sensorEvent) {
    Sensor mySensor = sensorEvent.sensor;

    if (mySensor.getType() == Sensor.TYPE_LINEAR_ACCELERATION) {
        //X,Y,Z values for the acceleration in meters per second squared
        float xAccelCurrent_RAW = sensorEvent.values[0];
        float yAccelCurrent_RAW = sensorEvent.values[1];
        float zAccelCurrent_RAW = sensorEvent.values[2];

        noise[0] = alpha * noise[0] + (1 - alpha) * sensorEvent.values[0];
        noise[1] = alpha * noise[1] + (1 - alpha) * sensorEvent.values[1];
        noise[2] = alpha * noise[2] + (1 - alpha) * sensorEvent.values[2];

        float xAccelCurrent_filtered = xAccelCurrent_RAW - noise[0];
        float yAccelCurrent_filtered = yAccelCurrent_RAW - noise[1];
        float zAccelCurrent_filtered = zAccelCurrent_RAW - noise[2];

        String xPositionString = Double.toString(findPosition(findVelocity(xAccelCurrent_filtered, timeInterval), timeInterval));
        String yPositionString = Double.toString(findPosition(findVelocity(yAccelCurrent_filtered, timeInterval), timeInterval));
        String zPositionString = Double.toString(findPosition(findVelocity(zAccelCurrent_filtered, timeInterval), timeInterval));

        xAccelTextView.setText(xPositionString);
        yAccelTextView.setText(yPositionString);
        zAccelTextView.setText(zPositionString); }}

最佳答案

低通滤波器是您的解决方案https://en.wikipedia.org/wiki/Low-pass_filter

protected float[] lowPass( float[] input, float[] output ) {
    if ( output == null ) return input;
    for ( int i=0; i<input.length; i++ ) {
        output[i] = output[i] + ALPHA * (input[i] - output[i]);
    }
    return output;
}

10-08 17:28