我正在开发一个连接到TiSensorTag设备的应用程序,并将其陀螺仪和加速度计一起用于检测位置和移动。我之前的问题是,当我检索加速度计和陀螺仪数据时,我得到的值永远不会被修复,但会在一小段值之间波动。 我应用了一个低通滤波器,但显然我的值继续振荡,即使我的传感器设备是静止的。 所以,我无法识别我的TiSesorTag是否真的被修复了。
你能告诉我一个克服这个问题的方法吗?感谢
以下是我获取值的代码:
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:[self.d.setupData valueForKey:@"Accelerometer data UUID"]]]) {
float xf= [sensorKXTJ9 calcXValue:characteristic.value];
float yf= [sensorKXTJ9 calcYValue:characteristic.value];
float zf= [sensorKXTJ9 calcZValue:characteristic.value];
NSMutableArray *newValues= [[NSMutableArray alloc] initWithObjects:
[NSNumber numberWithFloat:xf],
[NSNumber numberWithFloat:yf],
[NSNumber numberWithFloat:zf],
nil];
self.currentVal.accX = [[newValues objectAtIndex:0] floatValue];
self.currentVal.accY = [[newValues objectAtIndex:1] floatValue];;
self.currentVal.accZ = [[newValues objectAtIndex:2] floatValue];;
[self applyLowPassFilter:newValues];
NSLog(@"Accelerometer: X: % 0.1fG Y: % 0.1fG Z: % 0.1fG", self.currentVal.accX, self.currentVal.accY, self.currentVal.accZ);
}
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:[self.d.setupData valueForKey:@"Gyroscope data UUID"]]]) {
float x = [self.gyroSensor calcXValue:characteristic.value];
float y = [self.gyroSensor calcYValue:characteristic.value];
float z = [self.gyroSensor calcZValue:characteristic.value];
self.currentVal.gyroX = x;
self.currentVal.gyroY = y;
self.currentVal.gyroZ = z;
NSLog(@"Gyroscope: X: % 0.1f°/S Y: % 0.1f°/S Z: % 0.1f°/S", self.currentVal.gyroX, self.currentVal.gyroY, self.currentVal.gyroZ);
}
}