现在我想做一个应用程序来测试静止不动的人或钛的运动。我使用加速度计和3轴x,y,z的操作加速度。我必须用公式测试那个问题..!< / p>
答案 0 :(得分:1)
首先,通过公式accel = sqrt(accel_x^2 + accel_y^2 + accel_z^2)
获得与移动方向无关的标量加速度,其中^2
表示 2的幂,sqrt
表示平方根。之后,应用一些低通滤波器来消除随机噪声。 Here是一个很好的算法,使用alpha=0.8
是一个很好的方法。现在,您可以看到滤波加速度是否大于某个阈值(灵敏度取决于此阈值)。祝你好运!
答案 1 :(得分:1)
另一种选择是使用GPS。
var win = Ti.UI.createWindow({ backgroundColor: 'white' });
// WARNING: This will only work well outside, where the phone can get a good GPS signal.
var label = Ti.UI.createLabel({ text: 'Traveled 0 ft' });
win.add(label);
// Set up the geolocation code
Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_BEST;
Ti.Geolocation.distanceFilter = 0.1;
Ti.Geolocation.purpose = 'To track how far you have traveled!';
var lastLocation = null, totalFtTraveled = 0;
/**
* This function is called by the phone every time we have new geolocation data. It writes out where the user currently is.
* @param e An argument given to us by the phone with information such as accuracy, latitude, and longitude.
*/
function reportPosition(e) {
if (!e.success || e.error) {
label.text = 'error: ' + JSON.stringify(e.error);
}
else {
if (lastLocation != null) {
var lat1 = lastLocation.latitude, lon1 = lastLocation.longitude;
var lat2 = e.coords.latitude, lon2 = e.coords.longitude;
var kmTraveled = 3963.0 * Math.acos(
Math.sin(lat1 / 57.2958) * Math.sin(lat2 / 57.2958)
+ Math.cos(lat1 / 57.2958) * Math.cos(lat2 / 57.2958)
* Math.cos(lon2 / 57.2958 - lon1 / 57.2958)
);
var ftTraveled = kmTraveled * 3280.8399;
totalFtTraveled += ftTraveled;
label.text = 'Traveled ' + totalFtTraveled + 'ft';
}
lastLocation = e.coords;
}
}
// This will get the location right now, and will get the phone ready to listen for the user's current location.
Ti.Geolocation.getCurrentPosition(reportPosition);
// And this fires whenever the "distance filter" is surpassed -- with a filter of 1, this happens every 1 meter or so.
Ti.Geolocation.addEventListener('location', reportPosition);
var reset = Ti.UI.createButton({ title: 'Reset', bottom: 10, height: 50, width: 200 });
reset.addEventListener('click', function() {
totalFtTraveled = 0;
label.text = 'Traveled 0ft';
});
win.add(reset);
win.open();