macbook中的加速度计检测 [英] Accelerometer detection in macbook

查看:87
本文介绍了macbook中的加速度计检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建Mac桌面应用程序,当它检测到MacBook突然移动时播放声音。

刚看到文章说当我使用SMSLib(突发动作传感器)时,该应用程序可以检测到加速度计。



有人可以帮助吗我知道如何检测MacBook的突然移动吗?

SMSLib库对此有帮助吗?



我尝试过:



我正在尝试使用SMSLib,但我不知道这会有所帮助。

I want to create Mac desktop app that plays sound when it detects sudden movement of MacBook.
Just I saw the article that when I use SMSLib (Sudden Motion Sensor), the app can detect accelerometer.

Can someone please help me to know how to detect sudden movement of MacBook?
Is SMSLib library helpful for this?

What I have tried:

Just I am trying to use SMSLib, but I don't know this can be helpful.

推荐答案

应该可以通过周期性地轮询传感器并将传感器数据与先前轮询的数据进行比较。但是,轮询需要大量的系统资源,以便在短时间间隔内进行,这对于检测短暂的突然移动是必要的。



大多数加速度计都可以选择在特定条件下产生中断。但是使用这些设备需要设备(MacBook)支持它们,加速度计可以使用库进行编程(库源应该显示是否可行)。



如果MacBook正在放置在工作台上,则传感器数据对于X和Y轴应接近零,对于Z轴(或-1.0)应接近1.0。当它移动时,数据会相应地改变。



因为数据有噪声,所以当检测到慢速和小的移动时可能需要对它们进行过滤。简单过滤器使用低于1.0的因子(对于每个轴):

It should be possible by polling the sensor periodically and compare the sensor data with the data from the previous poll. However, polling requires a significant amount of system resources when peformed in short intervals which are necessary to detect short sudden movements.

Most accelerometers have options to generate interrupts on specific conditions. But using these requires that the device (the MacBook) supports them and the accelerometer can be programmed using the library (the library sources should show if this is possible).

If the MacBook is laying on the table the sensor data should be near zero for the X and Y axis and 1.0 for the Z axis (or -1.0). When it is moved, the data will change accordingly.

Because the data are noisy it might be necessary to filter them when slow and small movements should be detected. A simple filter uses a factor below 1.0 (for each axis):
filtered = actual_value * factor - prev_value * (1 - factor)
prev_value = filtered_value





然后你可以选择计算音高和滚动:



You can then optionally calculate the pitch and roll:

x_norm = x / sqrt(x^2 + y^2 + z^2)
y_norm = y / sqrt(x^2 + y^2 + z^2)
pitch = asin(x_norm)
roll = asin(y_norm / cos(pitch))





我建议编写一个简单的应用程序来轮询传感器并打印输出原始值和计算值。然后你可以玩它来找到移动时所需的限制。



I suggest to write a simple application that polls the sensor and prints out the raw and calculated values. Then you can play with it to find out the required limits when moving.


这篇关于macbook中的加速度计检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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