Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何实时(Java)计算加速计数据(jerk)的时间导数?_Java_Android_Timedelta_Acceleration_Differentiation - Fatal编程技术网

如何实时(Java)计算加速计数据(jerk)的时间导数?

如何实时(Java)计算加速计数据(jerk)的时间导数?,java,android,timedelta,acceleration,differentiation,Java,Android,Timedelta,Acceleration,Differentiation,我试图通过onReceive()循环Android方法中的流式加速计数据计算加速度的时间导数(jerk) 我假设,从一个传感器更新到下一个传感器更新,我可以通过简单地计算增量加速度(x,y,z)和相关的增量时间来近似这一点。为了确保最大的准确性,我使用了System.nanoTime()方法(并除以10e8) 一切似乎都很愉快,突然出现了数据,但我认为检查所有delta\u时间s(sumDeltaTime)的总和是否接近last\u时间和first\u时间之间的差异是明智的。令我惊讶的是,两者之

我试图通过onReceive()循环Android方法中的流式加速计数据计算加速度的时间导数(jerk)

我假设,从一个传感器更新到下一个传感器更新,我可以通过简单地计算增量加速度(x,y,z)和相关的增量时间来近似这一点。为了确保最大的准确性,我使用了
System.nanoTime()
方法(并除以10e8)

一切似乎都很愉快,突然出现了数据,但我认为检查所有
delta\u时间
s(
sumDeltaTime
)的总和是否接近
last\u时间
first\u时间
之间的差异是明智的。令我惊讶的是,两者之间的差异是几千倍。即使将
System.nanoTime()
替换为
System.currentTimeMillis()
(除以10e2),也不会改变这种差异。这是我的密码:

// calculate jerk (time derivative of acceleration)

accel_count++;

if (accel_count == 1) {
    first_time = new_time = System.nanoTime() / 10e8; // captures first time value (in seconds)
    newAccel[0] = accel[0]; // x
    newAccel[1] = accel[1]; // y
    newAccel[2] = accel[2]; // z
    } else {
    prev_time = new_time; // assigns previous time value
    new_time = System.nanoTime() / 10e8; // immediately updates to the new time value (in seconds)
    prevAccel[0] = newAccel[0]; // x
    prevAccel[1] = newAccel[1]; // y
    prevAccel[2] = newAccel[2]; // z
    // set up for next iteration
    newAccel[0] = accel[0]; // x
    newAccel[1] = accel[1]; // y
    newAccel[2] = accel[2]; // z
    }
float[] delta_accel; // difference in acceleration between consecutive sensor measurements
delta_accel = new float[] {
    (newAccel[0] - prevAccel[0]), // x
    (newAccel[1] - prevAccel[1]), // y
    (newAccel[2] - prevAccel[2])  // z
    };
double delta_time = (new_time - prev_time); // time difference between consecutive sensor measurements (in seconds)

float[] jerk;
jerk = new float[] {
    (float) (delta_accel[0] / delta_time), // x
    (float) (delta_accel[1] / delta_time), // y
    (float) (delta_accel[2] / delta_time)  // z
    };

total_time = new_time - first_time; // total time duration of entire recording (in seconds)
sumDeltaTime += delta_time; // testing sum of deltas

有人能看出我做错了什么吗?谢谢

您在第一次通过时没有初始化
prev\u time
accel\u count==1
),因此第一次计算
delta\u time
时可能是0。这使得第一个
delta\u时间
异常大,因为
new\u时间
比0大得多,正如
System.nanoTime()
比0大得多。

您在第一次通过时没有初始化
prev\u时间(
accel\u count==1
),因此,您第一次计算
delta\u时间时,它可能是0。这使得第一个
delta\u时间
异常大,因为
new\u时间
比0大得多,正如
System.nanoTime()
比0大得多。

10e2==100,10e8==100000000,因此您的计算结果相差10倍。另外,使用
SensorEvent.timestamp
。我尝试从10e3和10e9开始,奇怪的是,总时间没有返回秒。试试看;奇怪的非常感谢您提供有关SensorEvent.timestamp.10e2==100,10e8==100000000的建议,因此您的计算结果相差10倍。另外,使用
SensorEvent.timestamp
。我尝试从10e3和10e9开始,奇怪的是,总时间没有返回秒。试试看;奇怪的非常感谢您提供有关SensorEvent.timestamp.Yes的建议!这就成功了——非常感谢!总时间和增量时间之和现在是完美的匹配:)(我投了更高的票,但我的票不会显示,因为我的分数不够高)是的!这就成功了——非常感谢!总时间和增量时间之和现在是完美的匹配:)(我投了更高的票,但我的票不会显示,因为我的分数不够高)