Sensing#

Monitor Sensors#

To add a sensor’s value to the Monitor Console, use the monitor_sensor() command.

Functions#

Timer#

brain.timer_reset()#

The brain.timer_reset() command is used to reset the Brain’s timer back to 0 seconds.

This is a non-blocking command and allows any subsequent commands to execute without delay.

Returns: None.

def main():
    # Wait 10 seconds.
    wait(10, SECONDS)
    # Reset the Brain's timer from 10 seconds back to 0.
    brain.timer_reset()

brain.timer_time()#

The brain.timer_time(units) command is used to report the value of the Brain’s timer in seconds.

This is a non-blocking command and allows any subsequent commands to execute without delay.

Parameters

Description

units

The unit of the returned value, SECONDS or MSEC (Milliseconds).

Returns: This returns a numerical value.

def main():
    # Wait 3 seconds.
    wait(3, SECONDS)
    # Set the numeric variable "brain_timer" to the Brain timer's
    # current value in seconds.
    brain_timer = brain.timer_time(SECONDS)
    # Print the value of "brain_timer".
    brain.print(brain_timer)

drivetrain#

drivetrain.is_done()#

The drivetrain.is_done() command is used to return a True or False value if the Drivetrain has completed its movement.

This is a non-blocking command and allows any subsequent commands to execute without delay.

Returns: This returns a Boolean value.

def main():
    # Drive forward for 20 inches.
    drivetrain.drive_for(FORWARD, 20, INCHES)
    # Check if the Drivetrain has stopped moving.
    if drivetrain.is_done():
        # Print that the Drivetrain has finished moving.
        brain.print("Drivetrain has finished moving!")

drivetrain.is_moving()#

The drivetrain.is_moving() command is used to return a True or False value if the Drivetrain is currently moving.

This is a non-blocking command and allows any subsequent commands to execute without delay.

Returns: This returns a Boolean value.

def main():
    # Drive forward for 20 inches and allow subsequent commands to execute.
    drivetrain.drive_for(FORWARD, 20, INCHES, wait=False)
    # Wait 10 Milliseconds for Drivetrain to start moving.
    wait(10, MSEC)
    # Check if the Drivetrain is moving.
    if drivetrain.is_moving():
        # Print that the Drivetrain is moving.
        brain.print("Drivetrain is moving!")

drivetrain.heading()#

The drivetrain.heading(units) command returns the direction that the Drivetrain is facing by using the Gyro sensor’s current angular position. The numerical value from 0.00 to 359.99 (the DEGREES) will increase when rotating clockwise and decrease when rotating counter-clockwise.

This is a non-blocking command and allows any subsequent commands to execute without delay.

The drivetrain.heading(units) command returns a range from 0.00 to 359.99 degrees.

Parameters

Description

units

The unit of the returned value, DEGREES.

Returns: This returns a numerical value.

def main():
    # Turn to the right for 400 degrees.
    drivetrain.turn_for(RIGHT, 400, DEGREES)
    # Print the VR Robot's current heading.
    brain.print(drivetrain.heading(DEGREES))

drivetrain.rotation()#

The drivetrain.rotation(units) command returns the Drivetrain’s angle of rotation. The numerical value (the DEGREES) will increase when rotating clockwise and a decrease when rotating counter-clockwise.

This is a non-blocking command and allows any subsequent commands to execute without delay.

Parameters

Description

units

The unit of the returned value, DEGREES.

Returns: This returns a numerical value.

def main():
    # Turn to the right for 400 degrees.
    drivetrain.turn_for(RIGHT, 400, DEGREES)
    # Print the VR Robot's current angle of rotation.
    brain.print(drivetrain.rotation(DEGREES))

bumper#

To identify which Bumper Sensors your VR Robot can utilize, please consult your Playground’s detail page.

bumper.pressing()#

The bumper.pressing() returns if the specified bumper is pressed.

This is a non-blocking command and allows any subsequent commands to execute without delay.

Returns: This returns a Boolean value.

def main():
    # Drive forward.
    drivetrain.drive(FORWARD)
    # Continuously check the if statement every 5 Milliseconds.
    while True:
        wait(5, MSEC)
        # Check if the Left Bumper is Pressed.
        if left_bumper.pressing():
            # Stop the Drivetrain.
            drivetrain.stop()

distance#

To identify which Distance Sensors your VR Robot can utilize, please consult your Playground’s detail page.

distance.found_object()#

The distance.found_object() command reports whether the built-in Distance Sensor sees an object or surface within 3000 mm.

This is a non-blocking command and allows any subsequent commands to execute without delay.

Returns: This reports a Boolean value.

def main():
    # Print if the Front Distance Sensor has detected something.
    brain.print(front_distance.found_object())

distance.get_distance()#

The distance.get_distance(units) command the distance of the nearest object from the Distance Sensor.

This is a non-blocking command and allows any subsequent commands to execute without delay.

Parameters

Description

units

The unit of the returned value, MM or INCHES.

Returns: This returns a numeric value.

def main():
    # Print the distance from the Front Sensor to the nearest object in inches.
    brain.print(front_distance.get_distance(INCHES))

eye#

To identify which Eye Sensors your VR Robot can utilize, please consult your Playground’s detail page.

eye.near_object()#

The eye.near_object() command is used to report a Boolean value if the Color Sensor Eye is close enough to an object to detect a color.

This is a non-blocking command and allows any subsequent commands to execute without delay.

Returns: This reports a Boolean value.

def main():
    # Print if the Down Eye Sensor is detecting a color.
    brain.print(down_eye.near_object())

eye.detect()#

The eye.detect(color) command is used to report if the Color Sensor Eye is close enough to an object to detect a color.

This is a non-blocking command and allows any subsequent commands to execute without delay.

Parameters

Description

color

The color that the Color Sensor Eye will detect: NONE, BLACK, RED, GREEN, BLUE.

Returns: This returns a Boolean value.

def main():
    # Print if the Down Eye Sensor is detecting the color blue.
    brain.print(down_eye.detect(BLUE))

eye.brightness()#

The eye.brightness(units) command is used to report the brightness of an object from one of the Color Sensor Eyes.

This is a non-blocking command and allows any subsequent commands to execute without delay.

Parameters

Description

units

The unit of the returned value, PERCENT.

Returns: This returns a numeric value.

def main():
    # Print the brightness of the object in front of the VR Robot.
    brain.print(front_eye.brightness(PERCENT))

location#

location.position()#

The location.position(axis, units) command is used to report the X or Y coordinate position of the Robot.

This is a non-blocking command and allows any subsequent commands to execute without delay.

Parameters

Description

axis

The axis of the coordinates, X or Y.

units

The unit for the coordinates, MM (Millimeters) or INCHES.

Returns: This returns a numeric value.

def main():
    # Print the current Y coordinate of the VR Robot in Millimeters.
    brain.print(location.position(Y, MM))

location.position_angle()#

The location.position_angle(units) command is used to report the current angle of the VR Robot.

This is a non-blocking command and allows any subsequent commands to execute without delay.

Parameters

Description

units

The unit for the VR Robot’s angle, DEGREES.

Returns: This returns a numeric value.

def main():
    # Print the current angle of the VR Robot.
    brain.print(location.position_angle(DEGREES))