This repo has been deprecated and archived.
Consider signing up for our SDK email list to be notified when we release new and updates to our SDKs.
Visit our SDK website to find more information about the SDK and the API!
Visit our community forum to get help, share your project, or help others!
This project shows Windows 8.1 developers how to integrate Sphero into their Apps and games!
- Adding the RobotKit.dll to your Visual Studio solution
- Discovering & Connecting Sphero
- Changing Sphero's color
- Using the Sphero UI elements
- Driving Sphero
- Sensor Streaming
From within your solution on Visual Studio 2013
- Right click on References and "Add Reference"
- Choose "Browse" and select the RobotKit.dll
<wb:DeviceCapability Name="bluetooth.rfcomm">
<wb:Device Id="any">
<wb:Function Type="serviceId:00001101-0000-1000-8000-00805F9B34FB" />
</wb:Device>
</wb:DeviceCapability>
private void setupRobot(){
RobotProvider provider = RobotProvider.GetSharedProvider();
provider.DiscoveredRobotEvent += OnRobotDiscovered;
provider.NoRobotsEvent += OnNoRobotsEvent;
provider.ConnectedRobotEvent += OnRobotConnected;
provider.FindRobots();
}
Handle the Events...
private void OnRobotDiscovered(object sender, Robot robot) {
Debug.WriteLine(string.Format("Discovered \"{0}\"", robot.BluetoothName));
if (m_robot == null) {
RobotProvider provider = RobotProvider.GetSharedProvider();
provider.ConnectRobot(robot);
//...
}
}
private void OnNoRobotsEvent(object sender, EventArgs e) {
MessageDialog dialog = new MessageDialog("No Sphero Paired");
//...
}
Sphero's main LED colors are controlled by web standard RGB. Best practice is to use hex values to stay within the valid range of 0-255.
public void turnSpheroWhite(){
int red = 0xFF;
int green = 0xFF
int blue = 0xFF
m_robot.SetRGBLED(red, green, blue);
}
From within the BasicDriveApp sample, copy the RobotKitUI code for the Joystick and Calibration controls. Sphero needs to be calibrated so that the 'back LED" is aimed toward the driver. The easiest way to accomplish this is to use the 'CalibrateElement.cs'.
Driving Sphero is super simple. Just give it a direction in degrees where 0 is directly ahead and increases clockwise where 90 degrees is right and a velocity between 0.0 and 1.0.
public void hangRightAtHalfSpeed(){
int heading = 90; // right
float velocity = .5; // half speed
m_sphero.Roll(heading, velocity);
}
Sphero is capable of being used as a simple game controller or other input device using it's embedded sensors. Sphero has the following sensors.
- Accelerometer
- Gyrometer
- Location in X,Y from a relative starting point
- Velocity
- Attitude in both Quaternions and Euler angles
The robot SensorControl manages the listeners for Accelerometer, Gyro, Location, Attitude in Eulers and Quaternion Attitude. The SensorControl.Hz
value is between 1 and 400 and affects all sensors.
{
m_robot.SensorControl.Hz = 60; // stream at 60Hz for ALL sensors that are enabled
m_robot.SensorControl.AccelerometerUpdatedEvent += OnAccelerometerUpdated;
}
private void OnAccelerometerUpdated(object sender, AccelerometerReading reading) {
// expects AccelerometerX,Y,Z to be defined as fields
AccelerometerX.Text = "" + reading.X;
AccelerometerY.Text = "" + reading.Y;
AccelerometerZ.Text = "" + reading.Z;
}