传感#

监控传感器#

要将传感器的值添加到监视控制台,请使用 monitor_sensor() 命令。

功能#

Timer#

brain.timer_reset()#

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

这是一个非等待命令,允许任何后续命令无延迟地执行。

**返回:**无。

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.

这是一个非等待命令,允许任何后续命令无延迟地执行。

参数

描述

单位

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

**返回:**这将返回一个数值。

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#

传动系统.is_done()#

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

这是一个非等待命令,允许任何后续命令无延迟地执行。

**返回:**这将返回一个布尔值。

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!")

传动系统.正在移动()#

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

这是一个非等待命令,允许任何后续命令无延迟地执行。

**返回:**这将返回一个布尔值。

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!")

传动系统.航向()#

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.

这是一个非等待命令,允许任何后续命令无延迟地执行。

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

参数

描述

单位

The unit of the returned value, DEGREES.

**返回:**这将返回一个数值。

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))

传动系统.旋转()#

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.

这是一个非等待命令,允许任何后续命令无延迟地执行。

参数

描述

单位

The unit of the returned value, DEGREES.

**返回:**这将返回一个数值。

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#

要确定您的 VR 机器人可以使用哪种保险杠传感器,请查阅您的游乐场的详细信息页面。

保险杠.按下()#

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

这是一个非等待命令,允许任何后续命令无延迟地执行。

**返回:**这将返回一个布尔值。

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#

要确定您的 VR 机器人可以使用哪些距离传感器,请查阅您的游乐场的详细信息页面。

距离.found_object()#

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

这是一个非等待命令,允许任何后续命令无延迟地执行。

**返回:**报告一个布尔值。

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

距离.获取距离()#

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

这是一个非等待命令,允许任何后续命令无延迟地执行。

参数

描述

单位

The unit of the returned value, MM or INCHES.

**返回:**这将返回一个数值。

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

eye#

要确定您的 VR 机器人可以使用哪种眼部传感器,请查阅您的游乐场的详细信息页面。

眼睛.近物体()#

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.

这是一个非等待命令,允许任何后续命令无延迟地执行。

**返回:**报告一个布尔值。

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

眼睛.检测()#

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

这是一个非等待命令,允许任何后续命令无延迟地执行。

参数

描述

颜色

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

**返回:**这将返回一个布尔值。

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

眼睛.亮度()#

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

这是一个非等待命令,允许任何后续命令无延迟地执行。

参数

描述

单位

The unit of the returned value, PERCENT.

**返回:**这将返回一个数值。

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

location#

位置.position()#

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

这是一个非等待命令,允许任何后续命令无延迟地执行。

参数

描述

The axis of the coordinates, X or Y.

单位

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

**返回:**这将返回一个数值。

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

位置.位置角度()#

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

这是一个非等待命令,允许任何后续命令无延迟地执行。

参数

描述

单位

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

**返回:**这将返回一个数值。

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