[英]How to calculate speed with steps and distance TYPE_STEP_COUNTER
I need to calculate speed with the information of steps and distance cover ! 我需要根据步数和距离覆盖范围的信息来计算速度! Can anyone please guide me how can i do that one way i think of as using formula
S = VT
but in this case i need time per step in order to calculate the velocity
per step ..I have already looked at stackoverflow but did not solve the issue. 谁能指导我如何使用公式
S = VT
来实现这一目标,但是在这种情况下,我需要每一步的时间才能计算出每一步的velocity
..我已经研究过stackoverflow但没有解决问题。 Thanks. 谢谢。
In this block of code i am calculating step count by TYPE_COUNTER_STEP and distance by taking person height and multiply it by 0.45 and then multiply it with steps 在此代码块中,我要通过TYPE_COUNTER_STEP和距离来计算步数,方法是将人的身高乘以0.45,然后将其乘以步数
public void registerForSensorEvents() { SensorManager sManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); 公共无效registerForSensorEvents(){SensorManager sManager =(SensorManager)getSystemService(Context.SENSOR_SERVICE);
// Step Counter
sManager.registerListener(new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
float steps = event.values[0];
arrayList.add((int)steps);
getCurrentStepValue = (int) steps ;
stepValue.setText(getCurrentStepValue - arrayList.get(0) + "");
double distaneCovered = step_length * (getCurrentStepValue - arrayList.get(0));
distanceValue.setText("" + distaneCovered);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}, sManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER),
SensorManager.SENSOR_DELAY_NORMAL);
} }
You should take an initial stamp with first step, in second step take the difference between "now" and initial stamp, then you'll have time/step, reset initial stamp to "now" and do the same in following steps. 您应该首先进行初始标记,第二步进行“现在”和初始标记之间的区别,然后您将有时间/步骤,将初始标记重置为“现在”,然后在后续步骤中进行相同的操作。
As well you can simply have a timer and calculate number of steps (so distance) in X seconds instead of having time/step, it would depend on what you really need to do. 同样,您可以简单地使用一个计时器并以X秒为单位计算步数(即距离),而不用时间/步数,这取决于您真正需要做的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.