# Sensors

Real-time values that comes from the robot's sensors. For example, "if accelerometer z-axis > 3G's, then set LED's to green."

### Speed

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

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

### Orientation

The tilt angle along a given axis measured by the Gyroscope.

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 angle, from -180° to 180°.

### Gyroscope

The rate of rotation around a given axis, 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.

### Accelerometer

Motion acceleration along a given axis.

getAcceleration().x is the left-to-right acceleration, on a scale of -8 to 8 g's.

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

getAcceleration().z is the up-and-down acceleration, on a scale of -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, on a scale of 0 to 14 g's.

### Vertical Acceleration

getVerticalAcceleration is the up-and-down acceleration regardless of the robot's orientation, on a scale of -8 to 8 g's.

### Velocity

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

getVelocity().x is the left (-) or right (+) 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.

### Location

Estimated location (or distance) from the origin of a program measured by the motor encoders, in centimeters.

getLocation().x is the left or right location in context to the origin, in centimeters.

getLocation().y is the forward or back location in context to the origin, in centimeters.

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

### Time Elapsed

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 count_407 = 0; count_407 < 4; count_407++) {
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);
}
}