(iOS)Accelerometer Graph(将g-force转换为 -128)粒度

(iOS)Accelerometer Graph(将g-force转换为 -128)粒度,第1张

概述我正在使用Apple的这个 Accelerometer graph并试图将他们的G-force代码转换为计算/ – 128. 下图显示标签中的x,y,z值与图表上的输出不匹配:(请注意,addX:y:z值是图表上方标签中显示的值) 视图控制器 从蓝牙外设接收x,y,z值,然后使用以下转换: // Updates LABELS- (void)didReceiveRawAcceleromaterDa 我正在使用Apple的这个 Accelerometer graph并试图将他们的G-force代码转换为计算/ – 128.

下图显示标签中的x,y,z值与图表上的输出不匹配:(请注意,addX:y:z值是图表上方标签中显示的值)

视图控制器

从蓝牙外设接收x,z值,然后使用以下转换:

// Updates LABELS- (voID)dIDReceiveRawAcceleromaterDataWithX:(NSInteger)x Y:(NSInteger)y Z:(NSInteger)z{    dispatch_async(dispatch_get_main_queue(),^{        _labelAccel.text = [Nsstring stringWithFormat:@"x:%li  y:%li  z:%li",(long)x,(long)y,(long)z];    });}// Updates GRAPHS- (voID)dIDReceiveAcceleromaterDataWithX:(NSInteger)x Y:(NSInteger)y Z:(NSInteger)z{    dispatch_async(dispatch_get_main_queue(),^{        float xx = ((float)x) / 8192;        float yy = ((float)y) / 8192;        float zz = ((float)z) / 8192;        [_xGraph addX:xx y:0 z:0];        [_yGraph addX:0 y:yy z:0];        [_zGraph addX:0 y:0 z:zz];    });}

GraphVIEw

- (BOol)addX:(UIaccelerationValue)x y:(UIaccelerationValue)y z:(UIaccelerationValue)z{    // If this segment is not full,then we add a new acceleration value to the history.    if (index > 0)    {        // First decrement,both to get to a zero-based index and to flag one fewer position left        --index;        xhistory[index] = x;        yhistory[index] = y;        zhistory[index] = z;        // And inform Core Animation to redraw the layer.        [layer setNeedsdisplay];    }    // And return if we are Now full or not (really just avoIDs needing to call isFull after adding a value).    return index == 0;}- (voID)drawLayer:(CALayer*)l inContext:(CGContextRef)context{    // Fill in the background    CGContextSetFillcolorWithcolor(context,kUIcolorlightGray(1.f).CGcolor);    CGContextFillRect(context,layer.bounds);    // Draw the grID lines    DrawGrIDlines(context,0.0,32.0);    // Draw the graph    CGPoint lines[64];    int i;    float _granularity = 16.f; // 16    NSInteger _granualCount = 32; // 32    // X    for (i = 0; i < _granualCount; ++i)    {        lines[i*2].x = i;        lines[i*2+1].x = i + 1;        lines[i*2].y = xhistory[i] * _granularity;        lines[i*2+1].y = xhistory[i+1] * _granularity;    }    CGContextSetstrokecolorWithcolor(context,_xcolor.CGcolor);    CGContextstrokelinesegments(context,lines,64);    // Y    for (i = 0; i < _granualCount; ++i)    {        lines[i*2].y = yhistory[i] * _granularity;        lines[i*2+1].y = yhistory[i+1] * _granularity;    }    CGContextSetstrokecolorWithcolor(context,_ycolor.CGcolor);    CGContextstrokelinesegments(context,64);    // Z    for (i = 0; i < _granualCount; ++i)    {        lines[i*2].y = zhistory[i] * _granularity;        lines[i*2+1].y = zhistory[i+1] * _granularity;    }    CGContextSetstrokecolorWithcolor(context,_zcolor.CGcolor);    CGContextstrokelinesegments(context,64);}

如何计算上述代码以精确显示图表上的正确加速度计值?

解决方法 我发布这个作为aswer而不是评论,因为我没有足够的声誉,但我写的可能足以让你朝着正确的方向发送,它甚至可以算作答案……

您的问题仍然不包括真正重要的内容.我假设xx / yy / zz的计算没有问题.虽然我不知道8192应该是什么意思.

我想这个问题出现在你将值映射到像素坐标的部分……
lines []包含您的值,范围是标签中值的1/8192.所以你的x值-2应该在-0.0000像素的像素位置,所以稍微(远小于1像素)在视图上方…因为你看到线条进一步向下,必须有一些翻译到位(没有在你的代码中显示)

重要但未显示的第二部分是DrawGrIDlines.可能有一种不同的方法将值映射到像素坐标…

使用调试器检查绘制127行时获得的像素坐标,以及在历史数组中插入值127时获得的像素坐标

在阅读代码时需要改进一些想法:1.)将图形放在它自己的绘制一个图形的类中(并且只有一个历史.不知何故,你似乎已经部分已经存在(否则我无法弄清楚你的_xGraph / _yGraph / _zGraph)但另一方面你绘制所有一个drawLayer中的3个值???目前你似乎有3 * 3历史缓冲区,其中3 * 2填充零…2.)使用一个地方进行Y的计算,用于绘制网格和绘制线条……3.)使用CGContextMovetoPoint(); CGContextAddlinetoPoint();而不是用这些丑陋的2 * i 1个版本复制到行[] …

总结

以上是内存溢出为你收集整理的(iOS)Accelerometer Graph(将g-force转换为/ -128)粒度全部内容,希望文章能够帮你解决(iOS)Accelerometer Graph(将g-force转换为/ -128)粒度所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1028438.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存