iphone 陀螺仪 测试软件,iPhone-如何查找陀螺仪和加速度计的行进距离?

该博客探讨了在Unity3D项目中如何处理加速度计的误报问题。作者尝试使用低通滤波器和趋势分析来过滤反弹,以消除由于设备倾斜导致的不准确数据。通过记录和分析加速度计的点,计算平均趋势,并在检测到与趋势匹配的点时进行过滤,以提高数据准确性。尽管遇到挑战,但作者愿意分享其代码和进一步的细节,以帮助其他开发者解决类似问题。
摘要由CSDN通过智能技术生成

我对此表示怀疑并放弃了(晚上晚了,似乎什么都没得到)。 这用于Unity3d项目。

如果有人想在我离开的地方接机,我将很乐于详细介绍所有这些东西。

基本上在发现某些误报之后,我想我会尝试使用低通滤波器对其进行过滤,然后尝试通过查找趋势来消除反弹,然后(acc_x [i-1] + acc_x [i] )/ 2。

看来误报仍然来自倾斜,我尝试将其消除。

如果此代码有用或将您引向某个地方,请告诉我!

using UnityEngine;

using System.Collections.Generic;

///

/// rbi.noli@gmail.com

///

public class AccelerometerInput : MonoBehaviour

{

Transform myTransform;

Gyroscope gyro;

GyroCam gyroCam;

void Awake()

{

gyroCam= FindObjectOfType ();

myTransform = transform;

if (SystemInfo.supportsGyroscope) {

gyro = Input.gyro;

gyro.enabled = true;

}

}

bool shouldBeInitialized = false;

void Update ()

{

transform.Translate (GetAccelerometer ());// * Time.deltaTime * speed);

//GetComponent ().AddForce (GetAccelerometer ());

}

public float speed = 10.0F;

public Vector3 dir;

public float f;

Vector3 GetAccelerometer()

{

dir = Input.acceleration;

dir.x *= gyro.attitude.x;

dir.z *= gyro.attitude.z;

if (Mathf.Abs (dir.x) < .001f)

dir.x = 0;

dir.y = 0;

if (Mathf.Abs (dir.z) < .001f)

dir.z = 0;

RecordPointsForFilter (dir);

//print ("Direction : " + dir.ToString("F7"));

return TestPointsForVelocity();

}

Vector3[] points = new Vector3[20];

int index;

void RecordPointsForFilter(Vector3 recentPoint)

{

if (index >= 20)

index = 0;

points [index] = EvaluateTrend (recentPoint);;

index++;

}

//try to remove bounces

float xTrend = 0;

float zTrend = 0;

float lastTrendyX = 0;

float lastTrendyZ = 0;

Vector3 EvaluateTrend(Vector3 recentPoint)

{

//if the last few points were positive, and this point is negative, don't pass it along

//accumulate points into a trend

if (recentPoint.x > 0)

xTrend += .01f;

else

xTrend -= .1f;

if (recentPoint.z > 0)

zTrend += .1f;

else

zTrend -= .1f;

//if point matches trend, keep it

if (xTrend > 0) {

if (recentPoint.x > 0)

lastTrendyX = recentPoint.x;

} else // xTrend < 0

if (recentPoint.x < 0)

lastTrendyX = recentPoint.x;

if (zTrend > 0) {

if (recentPoint.z > 0)

lastTrendyZ = recentPoint.z;

} else // xTrend < 0

if (recentPoint.z < 0)

lastTrendyZ = recentPoint.z;

return new Vector3( lastTrendyX, 0, lastTrendyZ);

}

Vector3 TestPointsForVelocity()

{

float x = 0;

float z = 0;

float xAcc = 0;

float zAcc = 0;

int successfulHits = 0;

for(int i = 0; i < points.Length; i++)

{

if(points[i]!=null)

{

successfulHits ++;

xAcc += points[i].x;

zAcc += points[i].z;

}

}

x = xAcc / successfulHits;

z = zAcc / successfulHits;

return new Vector3 (x, 0, z);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值