1

现在我想做一个应用程序来测试人们在钛合金中静止不动或运动..我使用加速度计并在 3 轴 x、y、z 上操作加速度..我必须使用公式来测试这个问题..!

4

2 回答 2

1

首先,通过公式获得与运动方向无关的标量加速度,accel = sqrt(accel_x^2 + accel_y^2 + accel_z^2)其中^2表示2 的幂,表示sqrt平方根。之后,应用一些低通滤波器来消除随机噪声。是一个很好的算法,使用alpha=0.8它将是一个很好的方法。现在,您可以查看过滤后的加速度是否大于某个阈值(灵敏度取决于此阈值)。祝你好运!

于 2012-07-11T11:12:54.193 回答
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();
于 2012-07-11T15:01:25.810 回答