Accelerometers and gyroscopes can detect device's angle and acceleration on the 3 axes.
Since the acceleration itself does not tell you the speed nor distance, you can know them.
BUT if you know the device's speed is currently 0, and it begins to accelerate, you can know its speed and distance by basic physics equations: You track the device acceleration. lets make the tracking resolution to be milliseconds. So each millisecond, speed += Acceleration * 0.001 and distance += (speed * 0.001) + (Acceleration * 0.001 * 0.001 /2). This tracks movement in a single direction.
Notice that you have to decide what is the direction of the acceleration, speed and distance, which will be a Vector3. Then use some maths transformations to transform the current acceleration vector to your direction. I suggest that the direction will be flat comparing to the earth. Makes stuff easier later.
This can be used to tell if the device is moving (speed!=0, although if the movement is exactly perpendicular to your vector, the device might be moving but speed==0 is true) and which direction is the movement
Accelerometers detect acceleration, not constant motion. So your accelerometer will detect motion as it starts and stops, but can't tell you how far your device moved.
I detect speed, movement of device using accelerometer. But i have trouble when using LINEAR_ACCELEROMETER sensor. Anyway, it's impossible to calculate movement without calibration at start point.
发布评论
评论(4)
加速计和陀螺仪可以检测设备在 3 个轴上的角度和加速度。
由于加速度本身并不能告诉您速度或距离,因此您可以知道它们。
但是如果你知道设备的速度当前为 0,并且它开始加速,你可以通过基本物理方程知道它的速度和距离:
您跟踪设备加速度。让我们将跟踪分辨率设置为毫秒。因此,每毫秒,
速度 += 加速度 * 0.001
和距离 += (速度 * 0.001) + (加速度 * 0.001 * 0.001 /2)
。这会跟踪单一方向的运动。请注意,您必须确定加速度、速度和距离的方向,这将是一个 Vector3。然后使用一些数学转换将当前加速度矢量转换为您的方向。我建议与地球相比,方向将是平坦的。让以后的事情变得更容易。
这可用于判断设备是否正在移动(
speed!=0
,尽管如果移动完全垂直于您的矢量,则设备可能正在移动,但speed==0
为 true)以及运动方向Accelerometers and gyroscopes can detect device's angle and acceleration on the 3 axes.
Since the acceleration itself does not tell you the speed nor distance, you can know them.
BUT if you know the device's speed is currently 0, and it begins to accelerate, you can know its speed and distance by basic physics equations:
You track the device acceleration. lets make the tracking resolution to be milliseconds. So each millisecond,
speed += Acceleration * 0.001
anddistance += (speed * 0.001) + (Acceleration * 0.001 * 0.001 /2)
. This tracks movement in a single direction.Notice that you have to decide what is the direction of the acceleration, speed and distance, which will be a Vector3. Then use some maths transformations to transform the current acceleration vector to your direction. I suggest that the direction will be flat comparing to the earth. Makes stuff easier later.
This can be used to tell if the device is moving (
speed!=0
, although if the movement is exactly perpendicular to your vector, the device might be moving butspeed==0
is true) and which direction is the movement加速度计检测加速度,而不是恒定运动。因此,您的加速计将在开始和停止时检测运动,但无法告诉您设备移动了多远。
Accelerometers detect acceleration, not constant motion. So your accelerometer will detect motion as it starts and stops, but can't tell you how far your device moved.
请看看这个帖子: Android TYPE_LINEAR_ACCELERATION 传感器 - 它有什么作用显示?
我使用加速度计检测设备的速度和移动。但我在使用 LINEAR_ACCELEROMETER 传感器时遇到了麻烦。
无论如何,如果没有在起点进行校准,就不可能计算运动。
please, look at this thread: Android TYPE_LINEAR_ACCELERATION sensor - what does it show?
I detect speed, movement of device using accelerometer. But i have trouble when using LINEAR_ACCELEROMETER sensor.
Anyway, it's impossible to calculate movement without calibration at start point.
Android 开发者网站上有一个很好的示例,说明如何从常规 Sensor.TYPE_ACCELEROMETER 计算线性加速度:
http://developer.android.com/reference/android/hardware/SensorEvent.html#values
There's a good example of how to calculate linear acceleration from a regular Sensor.TYPE_ACCELEROMETER on the Android Developer site:
http://developer.android.com/reference/android/hardware/SensorEvent.html#values