oval

Get Started

Sphero created Oval as a subset of the C-language to communicate with our robots, and we now offer it to anyone in the world to use it as a fun tool to learn computer programming. This site is a guide to programming Sphero robots using Oval in the Lightning Lab App. If you're learning to program for the first time the best place to start is our Text Series of Activities. If you are a developer interested in building an app for Sphero use our SDK documentation.

How is Oval used?

Oval is used to control nearly everything on Sphero, Ollie and BB-8 with a standard set of commands. A few of the coolest features in our apps that Oval brings to life are:

apps


Lightning Lab - Powers the draw, blocks and text canvases to write custom programs.

BB-8 - Powers Watch With Me animations during Star Wars: The Force Awakens™.

Ollie - Powers the trick pad to make Ollie a trick machine.

Hello World!

Your first program will set the LED color to blue and roll the robot straight forward for 1s. On your device with the Lightning Lab app, open a new text program, click the ? button in the upper right, and use the Copy button below to copy and paste these code samples. Tap the Start button and see what happens:

void startProgram() // don't forget to aim your bot
{
    setRgbLed(0, 0, 255);
    controlSystemTargetSpeed = 60;
    delay(1);
    controlSystemTargetSpeed = 0;
}

Hello Square!

Let's transform your first program into a Square with more logic. Now run this program:

int _loopCount_1 = 0; // 1 is the unique value for this loop

void startProgram()
{
    controlSystemTargetYaw = 270;
    while (_loopCount_1 < 4) // 4 is the # of loops
    {
        _loopCount_1 = _loopCount_1 + 1;
        playSound(2, 6); // engine drive by sound
        delay(0.05);
        setRgbLed(0, 0, 255);
        controlSystemTargetYaw = controlSystemTargetYaw + 90; //add 90° 
        delay(1);
        controlSystemTargetSpeed = 60;
        delay(1);
        controlSystemTargetSpeed = 0;
    }
}

Oval Virtual Machine

Most computer languages run on a computer, mobile device, or server, but Oval runs on Sphero robots on a Virtual Machine that we call the Oval Virtual Machine (OVM). The OVM emulates the concept of a "computer" on Sphero robots enabling us to execute complex code. When you run a program from Lightning Lab, the Oval code compiles into binary (1's & 0's), and then travels wirelessly over Bluetooth to run via the OVM on the robot.

Oval is a streaming language that you can interact with in real-time. For example, the trick pad in the Ollie App has lots of pre-defined trick functions written in Oval. Tricks are "called" when you drag the trick pad a certain way, like Steam Roll, which interrupts driving commands to perform the trick. Tricks and can be continuously called.

ollie small


Syntax


Syntax is the rule set for how programs are constructed.

Character Case

Oval identifiers are tough to describe with one word, so most are 2-4 words known as "compound identifiers." Programming langauges generally don't allow spaces in identifers, so character case is the method by which you join compound identifiers to deliminate words. While there are hundreds of programming languages in the world, nearly all of them use one of these four joining methods: thisIsCamelCase, ThisIsPascalCase, this-is-spinal-Case, and this_is_snake_case. Oval is case sensitive and uses camelCase, such as controlSystemTargetSpeed to set the speed.

Punctuation

Code needs to be structured so it can be interpreted by the robot, just like the way humans have agreed on punctation standards in writing. If authors did not write with consistent punctation, readers would find it difficult to learn new rules in every book they read. Pay very close attention to the use of these characters or your robot will not be able to "read" your program:

void startProgram() starts a program

{ and } contain all program code, except for global functions and variables

// indicates a comment but does not affect the program logic

; ends a statement

( ) contains a value

, separates values

_____ a tab space starts the first statement in a program, and subsequent conditions must indent further

Highlighting

Notice in your Hello World! program that the words and characters are different colors. Syntax highlighting is the scheme to determine which commands display in which color. This scheme is different than the simplified one used in the block canvas.

native oval identifers
data types
syntax characters, comparators, operators, custom identifiers
values
controls
comments
errors

Errors

Errors tell you when the robot can't interpret your syntax. In the below example, notice a ; is missing after the speed value. In this case the robot is missing the context for the end of the statement and the red error message will display below the error line:

void startProgram()
{
    controlSystemTargetSpeed = 188
//!Syntax error! 
    setRgbLed(13, 255, 33);
    delay(2);
}

Data types

There are different types of data in programming that describe how much space a number occupies in storage and how it's interpreted. The memory on Sphero robots is quite small compared to a computer, so Oval is designed to use tiny amounts of space and only supports subsets of the data types in the C-Language:

Supported - Basic Types
int are whole numbers without a decimal, aka integers, such as 2
float are numbers with a decimal or remainder, such as 2.1

Unsupported - Enumerated Void Types
pointer
array
structure
union
function

About Oval

Oval was created in 2014 and is a subset of the C-language. C was created in the 1970's at Bell Labs and is the foundation of several modern languages like Python, Javascript, Objective-C, Java, and Ruby. We make learning Oval easy and interactive, and these skills will make learning other languages simpler.

The name "Oval" originates from a sketch drawn on a late night when discussing our software architecture; notice the oval shape on the header image at the top of the page. We needed a language that most developers already knew and others wanted to learn (C), that could continuously stream between a device and robot, and could be extended to include custom robot commands.

You might have already used Oval because it powers the block programming canvas in the Lightning Lab app, and you could view Oval code behind those blocks. Now you will graduate from blocks to text and write the code yourself. We hope you find learning to program with Sphero very rewarding as your code comes to life in our robots.