如何在获得加速度计测量的同时获得方位角!方向与加速度计
我正在做这个应用程序,它的工作原理就像计步器计算步数,但我希望它显示每个步骤的方向。
我正在做的是注册两个事件侦听器,然后对于每个 onsensorchanged
事件,我都会获取 sensor.TYPE_ORIENTATION
的值来获取方位角,以及sensor.TYPE_ACCELEROMETER
,我可以在其中查看是否给出了步骤。
此时我得到了正确的值,但我只想在步数完成后达到方位角角的峰值!我该如何做到这一点?
我认为这将在 OnSensorChanged
方法内完成,但我不知道当加速计传感器被激活并且步数计数时如何仅调用方向传感器
。代码里面会是这样的: 注册两个侦听器后,ACCELEROMETER
和 ORIENTATION
OnSensorChanged(SensorEvent event)
{
if((event.sensor.getType()==Sensor.TYPE_ACCELEROMETER))
accValues=event.values;
// NOW get the orientation azimuth value at this time..
orientationValues=event.values;
}
希望有人能澄清我这一点。
I'm doing this application that works like a pedometer counting steps, but I want it to show orientation for each step.
What i'm doing is registering two event listeners and than for each onsensorchanged
event I'm picking up the values of the sensor.TYPE_ORIENTATION
to get the azimuth angle, and of the sensor.TYPE_ACCELEROMETER
, where I see if a step is given or not.
At this time I'm getting the values correctly but I want to peak only the azimuth angla when the step count is done!How do I do this ?
I'm supposing that it will be done inside the OnSensorChanged
method, but I'm not getting an idea on how to just call Orientation sensor, when Accelerometer Sensor is activated and a step is count..
Looking inside the code it will be something like this:
after registering the two listeners, ACCELEROMETER
and ORIENTATION
OnSensorChanged(SensorEvent event)
{
if((event.sensor.getType()==Sensor.TYPE_ACCELEROMETER))
accValues=event.values;
// NOW get the orientation azimuth value at this time..
orientationValues=event.values;
}
Hope that someone can clarify me on this..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嘿,如果您想要方位角,您可以使用加速度计和磁力计传感器获得。首先获取加速度计数据和磁力计数据。接下来使用SensorManager.getRotationMatrix(Rotation_data, Inclination_data, acc_data, mag_data)函数。您必须提供 acc_data 和 mag_data 作为输入,并获得 Rotation_data 和 Inclination_data 作为输出。最初只需将它们作为空数组传递即可。获得 Rotation_data 后,使用 SensorManager.getOrientation(Rotation_data, Angles) 。 angles 是作为输出获得的数组。最初也将其作为空数组传递。函数调用后,您将得到 angles[0] 作为方位角,angles[1] 为俯仰角,angles[3] 为横滚角。使用的所有数组都是 3 个元素的一维数组。
hey if you want the azimuthal angle you can get it using the ACCELEROMETER and MAGNETOMETER sensors. First get the accelerometer data and the magnetometer data .Next use SensorManager.getRotationMatrix(Rotation_data, Inclination_data, acc_data, mag_data) function. you have to give acc_data and mag_data as input and you get Rotation_data and Inclination_data as output. Just pass them as empty arrays initially. once you have get the Rotation_data use SensorManager.getOrientation(Rotation_data, angles) . angles is an array you get as output.Pass it also as an empty array initially. after the function call you get angles[0] as azimuthal,angles[1] is pitch and angles[3] is roll. All the arrays used are a single dimension array of 3 elements.