加速度计在运行几分钟后同时触发多次 [英] Accelerometer triggers multiple times at the same time after some minutes running

查看:30
本文介绍了加速度计在运行几分钟后同时触发多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 Flutter 开发了一个移动应用.我正在使用 - 1

这是大约 4 分钟后的样子:

- 2

此图显示了每次流被触发并为我提供新数据之间的时间(以毫秒为单位)(经过的毫秒之间的差异 time[i+1]-time[i]).橙色为正常状态(图 1).几分钟后的蓝色显示为损坏状态(图 2).

当一切正常(橙色线)时,每 5 到 15 毫秒就会有新数据到来.

但几分钟后(蓝线)流同时被触发多次(时间差以及此时的图表为零)然后中断大约 70 毫秒(图中的峰值)然后再次被触发多次.

这对应于图 2 所示的图表.在那里您还可以看到这些时间跳跃和同时多个值.

我的问题是:什么可能导致这种情况?我该如何解决?

我很高兴听到任何关于一般改进的建议(例如标题).非常感谢您的帮助.如果需要更多信息来帮助我,请告诉我!我很绝望.

这是监听事件的代码:

void startSensors() async {accelstream = 等待 SensorManager().sensorUpdates(sensorId:传感器.加速度计,间隔:持续时间(毫秒:10),);stopWatch.start();accelstream.listen((SensorEvent 事件) {设置状态((){Vector3 accel = Vector3(event.data[0], event.data[1], event.data[2]);新数据(accel.z,stopWatch.elapsedMilliseconds)},);});}

我的一些发现:国家随着时间的推移而发展.启动应用程序后,采样率平均为 100Hz(每 10 毫秒)(图中的橙色).并不是说流每 10 毫秒不断触发一次.相反,有时加速度计需要"(不知道正确的术语是什么,我道歉)15 毫秒,然后可能下一次只有 5 毫秒.随着时间的推移,差异越来越大.例如,在 30 秒后,流在 2 毫秒到 18 毫秒之间触发,但平均仍为 10 毫秒(100 赫兹).传感器运行的时间越长,间隙就越大(例如 0ms 和 60ms).我发现的另一件事是,随着时间的推移,操作系统 (ig) 将采样率从最初的 100Hz 降低到 20Hz.

解决方案

您不应该尝试自己确定时间(使用秒表).事件数据包含事件发生时间的时间戳.您需要改用它,因为可能会有一些延迟(取决于其他情况).

只存储最后一个事件的时间戳,然后计算新事件到来时的增量.

I have developed a mobile app with Flutter. I am reading the acceleration data with the flutter_sensors package and every time the stream gets triggered and outputs new acceleration data I take the elapsed milliseconds with the Stopwatch class and store and plot both the acceleration data and the corresponding timestamps.

accelerationZ = [12.79, 9.93, 8.43, 15.96, …, 5.13, 9.61, 12.81] in m/s^2
time = [145922, 145923, 145952, 145960, …, 147900, 147913, 147936] in ms since start

After some minutes something strange happens.

This is how the acceleration over time graph looks right after starting the sensors:

- 1

This is how it looks after around 4 minutes:

- 2

This plot shows the time in milliseconds between every time the stream got triggered and gave me new data (the difference between the elapsed milliseconds time[i+1]-time[i]). In orange the normal state (picture 1). In blue the broke state after some minutes (picture 2).

When every thing is fine (orange line) there is new data coming every 5 to 15ms.

But after some minutes (blue line) the stream gets triggered multiple times at the same time (the difference in time and therefore the graph at this point are zero) and then makes a break for around 70ms (the spikes in the graph) before again getting triggered multiple times.

This corresponds to the graph shown in picture 2. There you can also see these jumps in time and multiple values at the same time.

My questions are: What could cause that? And how do I fix that?

I am happy to hear any suggestions for general improvements (for example for the title). Thank you very much for your help. If need more information to help me please let me know! I am desperate.

This is the code listening for events:

void startSensors() async {
    accelstream = await SensorManager().sensorUpdates(
      sensorId: Sensors.ACCELEROMETER,
      interval: Duration(milliseconds: 10),
    );

    stopWatch.start();

    accelstream.listen((SensorEvent event) {
      setState(
        () {
          Vector3 accel = Vector3(event.data[0], event.data[1], event.data[2]);
          newData(accel.z, stopWatch.elapsedMilliseconds)
        },
      );
    });
}

Some of my discoveries: The state develops over time. Right after starting the app the sampling rate is in average 100Hz (every 10ms) (orange in the graph). It's not that the stream triggers constantly every 10ms. Instead sometimes the accelerometer "takes" (idk what the right terms are I apologize) 15ms and then maybe the next time only 5ms. Over time the differences grow. For example after 30s the streams triggers between 2ms and 18ms but still averages at 10ms (100Hz). The longer the sensor runs the bigger the gap gets (e.g. 0ms and 60ms). Another thing I discovered is that over time the operating system (ig) drops the sampling rate from initial 100Hz to 20Hz.

解决方案

You should not be attempting to determine the timing yourself (using the stopwatch). The event data contains a timestamp of when the event occurred. You need to use that instead as there can be some latency (depending on what else is going on).

Just store the timestamp of the last event, then compute the delta when the new event comes in.

这篇关于加速度计在运行几分钟后同时触发多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆