Sensors

Querying sensor data allows you to react to real-time values coming from the robots’ physical sensors. For example, "if accelerometer z-axis > 3G's, then set LED's to green."


Accelerometer

Provides motion acceleration data along a given axis measured by the Accelerometer, in g's, where g = 9.80665 m/s^2.

getAcceleration().x is the left-to-right acceleration, from -8 to 8 g's.

getAcceleration().y is the forward-to-back acceleration, from of -8 to 8 g's.

getAcceleration().z is the upward-to-downward acceleration, from -8 to 8 g's.

Math.sqrt((getAcceleration().x ** 2) + (getAcceleration().y ** 2) + (getAcceleration().z ** 2)) is the combined vector acceleration of all 3 axes, from 0 to 14 g's.

getVerticalAcceleration() is the upward or downward acceleration regardless of the robot's orientation, from -8 to 8 g's.

5 accel


Orientation

Provides the tilt angle along a given axis measured by the Gyroscope, in degrees.

getOrientation().pitch is the forward or backward tilt angle, from -180° to 180°.

getOrientation().roll is left or right tilt angle, from -90° to 90°.

getOrientation().yaw is the spin (twist) angle, from -180° to 180°.

5 orientation


Gyroscope

Provides the rate of rotation around a given axis measured by the gyroscope, from -2,000° to 2,000° per second.

getGyroscope().pitch is the rate of forward or backward spin, from -2,000° to 2,000° per second.

getGyroscope().roll is the rate of left or right spin, from -2,000° to 2,000° per second.

getGyroscope().yaw is the rate of sideways spin, from -2,000° to 2,000° per second.

5 gyro


Velocity

Provides the velocity along a given axis measured by the motor encoders, in centimeters per second.

getVelocity().x is the right (+) or left (-) velocity, in centimeters per second.

getVelocity().y is the forward (+) or back (-) velocity, in centimeters per second.

Math.sqrt((getVelocity().x ** 2) + (getVelocity().y ** 2)) is the combined vector velocity of both axes which will always be a positive value, in centimeters per second.

5 velocity


Location

Provides the location where the robot is in space (x,y) relative to the origin, in centimeters. This is not the distance traveled during the program, it is the offset from the origin (program start).

getLocation().x is the right (+) or left (-) distance from the origin of the program start, in centimeters.

getLocation().y is the forward (+) or backward (-) distance from the origin of the program start, in centimeters.

Math.sqrt((getLocation().x ** 2) + (getLocation().y ** 2)) is the total distance from the origin of the program start, which will always be a positive value, in centimeters.

5 location


Distance

getDistance() is the total distance traveled in the program, in centimeters.

5 distance


Speed

getSpeed() is the current target speed of the robot, from -255 to 255, where positive is forward, negative is backward, and 0 is stopped. 5 sense speed


Heading

getHeading() is the target directional angle, in degrees. Assuming you aim the robot with the blue tail light facing you, then 0° heading is forward, 90° is right, 180° is backward, and 270° is left. 5 sense heading

5 heading diabram


Main LED

getMainLed() is the RGB color of the main LEDs, from 0 to 255 for each color channel.

getMainLed().r is the red channel, from 0 - 255.

getMainLed().g is the green channel, from 0 - 255.

getMainLed().b is the blue channel, from 0 - 255.

5 sense main led


Back LED - Blue Only

getBackLed().b is the brightness of the back LED, from 0 to 255. For Sphero BOLT, use getBackLed() to get the RGB value.

1 sense back led


Time Elapsed

5 sense time

getElapsedTime() is the amount of time that the program has run for, in seconds. For example, you could use getElapsedTime() to swap between forward and backward movements every 4s in an ocean buoy animation using:

var lastTime = 0;
var loopCount = 0;

async function startProgram() {
	setBackLed(255);
	for (var _i1 = 0; _i1 < 4; _i1++) {
		await Sound.Water.Waves.play(false);
		if ((loopCount % 2) === 1) {
			while (!(((getElapsedTime() - lastTime) >= 4))) {
				setMainLed({ r: 11, g: 255, b: 0 });
				await rawMotor(1000, 1000, 0.4);
				setMainLed({ r: 0, g: 0, b: 0 });
				await delay(0.5);
			}
			lastTime = getElapsedTime();
		} else {
			while (!(((getElapsedTime() - lastTime) >= 4))) {
				setMainLed({ r: 255, g: 41, b: 16 });
				await rawMotor(-1000, -1000, 0.4);
				setMainLed({ r: 0, g: 0, b: 0 });
				await delay(0.5);
			}
			lastTime = getElapsedTime();
		}
		loopCount = (loopCount + 1);
		await delay(0.025);
	}
}

Sphero BOLT Sensors


Compass Direction

getCompassDirection() is the real-world offset between the aim heading and the last compass north reading. 0° is due north, 90° is due east, 180° is due south, and 270° is due west. Requires the Calibrate Compass command to be run before you can get this value. Metallic and magnetic objects affect the accuracy of the compass reading.

sensor - compass direction

compass modal


Luminosity

getLuminosity() is the light intensity from 0 - 100,000 lux, where 0 lux is full darkness and 30,000-100,000 lux is direct sunlight. You may need to adjust a condition based on luminosity in different environments as light intensity can vary greatly between rooms.

luminosity


Last Message Received

getLastIRMessage() returns which channel the last infrared message was received on. You need to declare the onIRMessage() event for each IR message you plan to see returned.

sensors - last message received


Back LED

getBackLed() is the RGB color of the back LED, from 0 to 255 for each color channel.

back LED


Front LED

getFrontLed() is the RGB color of the front LED, from 0 to 255 for each color channel.

fornt LED




R2-D2 & R2-Q5 Sensors


Back LED

getBackLed() is the RGB color of the back LED, from 0 to 255 for each color channel.

back LED


Front LED

getFrontLed() is the RGB color of the front LED, from 0 to 255 for each color channel.

fornt LED


Dome LEDs

getDomeLeds() is the brightness of the Dome LEDs, from 0 to 15.

5 sense dome led


Holo Projector LED

getHoloProjectorLed() is the brightness of the Holographic Projector LED, from 0 to 255.

5 sense holo projector leds


Logic Display LEDs

getLogicDisplayLeds() is the brightness of the white Logic Display LEDs, from 0 to 255.

5 sense logic display leds