libec
libec

Reputation: 1554

Gyroscope driven sphero

I'm working on sphero app and want to add a gysorcope based driving. As far as I understand I need to create CMMotionManager, get the yaw value and pass it as a parameter to instance of RKTiltDriveAlgorithm. What I don't understand is where do I pass the RKTiltDriveAlgorithm instance. Documentation says to pass the instance to RKRobotControl which doesn't seem to be accessible from anywhere. RKRobotProvider has a property for RKRobotControl but it's not assignable. Here's my code so far

RKTiltDriveAlgorithm *tilt = [[RKTiltDriveAlgorithm alloc] initWithOrientation:[UIApplication sharedApplication].statusBarOrientation];
...
[self.motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:^(CMDeviceMotion *motion, NSError *error) {
    float yaw = (180/M_PI) * motion.attitude.yaw;
    tilt.orientationAngle = yaw;
}];

Would appreciate some hints, thanks :)

Upvotes: 1

Views: 325

Answers (1)

jhthorp
jhthorp

Reputation: 171

I am quite sorry for the confusion regarding this. We have actually been streamlining the Tilt Controls to make integration easier. Please see the RobotUISample [https://github.com/orbotix/Sphero-iOS-SDK/tree/master/samples/RobotUISample] for an example of how the new system is being used.

In short, we moved Tilt under the hood of RKDriveControl [https://github.com/orbotix/Sphero-iOS-SDK/blob/master/frameworks/RobotKit.framework/Headers/RKDriveControl.h], which is a singleton. Now, you just create and use this singleton instance to drive the Sphero. We even tap directly into the CMMotionManager for you now. All that you need to provide is the Drive Type and tell it to start driving.

/*Call when Robot is connected*/
- (void)startDriving {    
    //Drive with Tilt
    [[RKDriveControl sharedDriveControl] startDriving:RKDriveControlTilt];
}

Upvotes: 1

Related Questions