sphero-inc / Sphero-Mac-SDK

🚫 DEPRECATED: Sphero SDK for the Mac platform.
https://developer.gosphero.com
68 stars 28 forks source link
archived deprecated obsolete

This repo has been deprecated and archived.

Want to be updated when new SDKs are released?

Consider signing up for our SDK email list to be notified when we release new and updates to our SDKs.

For more information and documentation

Visit our SDK website to find more information about the SDK and the API!

Where to get help

Visit our community forum to get help, share your project, or help others!

iosdeveloperheader.jpg

Mac Developer Quick Start Guide

Resources

Class Documentation



Community and Help

Overview

This Guide walks you through the basics of creating Mac apps that leverage the Orbotix Sphero SDK. The examples in this guide were built using Objective-C and have been tested with the current released OSX and current version of Xcode. The goal of this developer guide along with sample code is to give the developer a taste of the wide variety of things Sphero can do, respond to, and keep track of.

The Mac SDK is a direct port from the iOS SDK. Therefore, we tried to keep the syntax identical to it's iOS counterpart.

In general this guide will walk you through:

Samples


The first step to using our SDK is to run the samples we have included. It is the easiest way to get started. Simply open the .xcodeproject file of any of our samples and run in Xcode to see a few examples of what Sphero can do. Currently, we have these samples:

Integrating into an existing project

Notice: The Sphero Mac SDK should work for OSX 10.6+

There are always those cases where you already developed an awesome game or app and want to integrate Sphero functionality or controllability into the project. For those cases we have made it possible to integrate our libraries into your existing project, including some nifty pre-built user interface tools.

Build Phases


Copy Files

You need to add the build phase "Copy Files" to your Xcode project, if it is not already there. Once you add it, you must move it above "Link Binaries With Libraries" build phase. This is so the dynamic library RobotKit.framework gets copied into the executable directory of our project before the app tries to find it at runtime. Without this build phase you will get the runtime error "dyld: Library not loaded: RobotKit.framework… Reason: image not found".

Link Binary With Libraries

To integrate the Sphero SDK into your project, you must add the RobotKit.Framework from the framework directory of the SDK into "Link Binary With Libraries" and make sure this Build Phase is below "Copy Files" build phase.

Build Phases tab of your project should now look like this:

sendingIn.png

Code to Connect to Sphero

The HelloSphero example has all the necessary code needed to create and maintain a connection to Sphero, and can be used as a guide in best practices. In general you will need to:


Using the Sphero Mac SDK


This command is described in section 3 in more detail but it is a good exercise at this point to change these values and try it out, play around a little bit.

For example, try changing the following command in AppDelegate.m from

[RKRGBLEDOutputCommand sendCommandWithRed:0.0 green :0.0 blue :1.0];

to

[RKRGBLEDOutputCommand sendCommandWithRed:0.0 green :1.0 blue :0.0];

Notice the change from green of 0.0 to a green of 1.0. Run it and you should have a Green Sphero!

Sending Roll Commands

So, you got the LED to blink… thats Awesome! But let's also take advantage of the amazing technology inside Sphero and drive the ball around a little bit.

In order to move Sphero you will need to send a RollCommand. The RollCommand takes two parameters.

  1. Heading in degrees from 0° to 360°
  2. Speed from 0.0 to 1.0.

For example, a heading of 90° at a speed of 0.5 will tell Sphero to turn clockwise 90° at half speed (1.0 is full speed). Once this command is issued Sphero will continue at this heading and speed until it hits something or runs out of range, so you will need to stop the ball using the RollCommand and sendStop().

Now, it's time to modify the code. Let's send Sphero forward for 2 seconds. Next we will create 2 new methods, one to Move Sphero, and Delay. And another to Stop Sphero.

        - (void)stop {
            [RKRollCommand sendStop];
        }

        - (void)driveforward {
            [RKRollCommand sendCommandWithHeading:0.0 velocity:0.5];            
            [self performSelector:@selector(stop) withDelay:2.0];
        }

Next add the following code in place of the RGB command that was sent before.

        [self driveforward];

Run the application on an Mac, if all went well Sphero should have moved forward just a little.


Where is Sphero going?


If you have successfully completed the quick start guide then Sphero should have moved after running the modified code. What is interesting to note here is that Sphero just went in a random direction. The direction was not random at all, Sphero believe it or not has a front and a back. It is necessary for the application to determine what direction forward is for the user from the point of view of the ball. We call this step Calibration and it is required to properly drive Sphero in a predictable direction. To learn more about calibration and using the BackLED to set Sphero's orientation please check out the KeyDrive Sample project.