0

我有一个带有 1 个滑块的视图。我想将 Sphero 球握在手中,因此当向左或向右倾斜球时,滑块会向左或向右移动。

解决这个问题的最佳示例项目是什么?

4

2 回答 2

1

我会使用https://github.com/orbotix/Sphero-iOS-SDK/tree/master/samples/SensorStreaming

在 handleAsyncData 中添加对滑块的引用:

- (void)handleAsyncData:(RKDeviceAsyncData *)asyncData
{
   if ([asyncData isKindOfClass:[RKDeviceSensorsAsyncData class]]) {
       packetCounter++;
       if( packetCounter > (TOTAL_PACKET_COUNT-PACKET_COUNT_THRESHOLD)) {
           [self sendSetDataStreamingCommand];
       }

       // Received sensor data, so display it to the user.
       RKDeviceSensorsAsyncData *sensorsAsyncData = (RKDeviceSensorsAsyncData *)asyncData;
       RKDeviceSensorsData *sensorsData = [sensorsAsyncData.dataFrames lastObject];
       RKAccelerometerData *accelerometerData = sensorsData.accelerometerData;
       RKAttitudeData *attitudeData = sensorsData.attitudeData;

        // this Assumes your Slider has been hooked up in the Interface Builder
        // With float values between 1.0 and 0.0
       [MyAccelerometerSlider setFloatValue:accelerometerData.acceleration.x];
       // You could also set it to the Roll value which is better for controller stuff
       [MyOtherSlider setDoubleValue:attitudeData.roll];
   }
}

只需将要监视的轴从 x 更改为 y 或 z。您还可以使用 Streaming 示例中的其他流式处理函数。IE。高度和四元数。

这是 Sphero 加速度计传感器的示意图:

球头航向图

于 2013-04-29T15:53:06.477 回答