机器人专用 Python#
介绍#
Rover Rescue 游乐场具有 VR Rover 独有的方法,包括自定义的 Drivetrain、Sensing 和 Actions 类别方法。
VR Rover 可以访问标准的 VR 事件、控制、变量和功能命令。
以下是所有可用的 Playground 特定方法列表:
动力系统 - 移动和监控虚拟现实漫游车。
操作
drive- Drives the VR Rover continuously forward or in reverse.drive_for- Drives the VR Rover for a set distance.turn- Turns the VR Rover continuously left or right.turn_for- Turns the VR Rover a specific number of degrees.turn_to_heading- Turns the VR Rover to face a specific heading.drive_to- Drives the VR Rover straight toward the selected object.turn_to- Turns the VR Rover to face the selected object.go_to- Turns and drives the VR Rover to the selected object.stop- Stops all rover movement.
变异因子
set_heading- Sets the rover’s heading value.set_timeout- Limits how long drivetrain methods wait to reach their target.set_drive_velocity- Sets the speed used by drive methods.set_turn_velocity- Sets the speed used by turn methods.
Getters
感知 - 使用探测车的距离传感器探测附近物体。
距离
found_object- Returns whether the Distance Sensor detects an object.get_distance- Returns the distance to the nearest detected object.
操作 - 与探测车的资源、敌人和内置人工智能系统进行互动。
操作
pickup- Picks up minerals.drop- Drops minerals.use- Uses minerals to restore energy.absorb_radiation- Absorbs radiation from an enemy.standby- Puts the VR Rover into standby mode until a battery threshold is reached.
Getters
angle- Returns the direction to an object in degrees.get_distance- Returns the distance to an object in millimeters or inches.location- Returns the X or Y coordinate of an object in millimeters or inches.battery- Returns the VR Rover’s battery level.minerals_stored- Returns how many minerals the VR Rover is carrying.storage_capacity- Returns the VR Rover’s carrying capacity.level- Returns the VR Rover’s current level.exp- Returns the VR Rover’s current experience points.enemy_level- Returns the level of the closest detected enemy.enemy_radiation- Returns the radiation of the closest detected enemy.detects- Returns whether the VR Rover detects minerals or enemies in its detect radius.sees- Returns whether the VR Rover sees an object in its vision range.under_attack- Returns whether the VR Rover is currently under attack.
回调函数
on_under_attack- Runs a callback when the VR Rover is attacked.on_level_up- Runs a callback when the VR Rover levels up.
本页示例使用 Playground 的默认起始位置。
传动系统#
行动#
驾驶#
drive drives the VR Rover continuously forward or in reverse.
Usage:
drivetrain.drive(direction)
参数 |
描述 |
|---|---|
|
The direction the robot drives:
|
def main():
drivetrain.drive(FORWARD)
wait(2, SECONDS)
drivetrain.stop()
# VR threads — Do not delete
vr_thread(main)
驱动#
drive_for drives the VR Rover for a set distance.
Usage:
drivetrain.drive_for(direction, distance, units, wait=True)
参数 |
描述 |
|---|---|
|
The direction the robot drives:
|
|
行驶距离,以整数或小数表示。 |
|
The unit of measurement:
|
|
Optional.
|
def main():
drivetrain.drive_for(FORWARD, 200, MM)
# VR threads — Do not delete
vr_thread(main)
转动#
turn turns the VR Rover continuously left or right.
Usage:
drivetrain.turn(direction)
参数 |
描述 |
|---|---|
|
The direction the robot turns:
|
def main():
drivetrain.turn(RIGHT)
wait(2, SECONDS)
drivetrain.stop()
# VR threads — Do not delete
vr_thread(main)
转弯#
turn_for turns the VR Rover a specific number of degrees.
Usage:
drivetrain.turn_for(direction, angle, units, wait=True)
参数 |
描述 |
|---|---|
|
The direction the robot turns:
|
|
要转出的金额,以整数或小数表示。 |
|
The unit of measurement. In this Playground, use |
|
Optional.
|
def main():
drivetrain.turn_for(RIGHT, 90, DEGREES)
# VR threads — Do not delete
vr_thread(main)
转向航向#
turn_to_heading turns the VR Rover to face a specific heading.
Usage:
drivetrain.turn_to_heading(heading, units, wait=True)
参数 |
描述 |
|---|---|
|
要转向的方向,范围从 -360 到 360。 |
|
The unit of measurement. In this Playground, use |
|
Optional.
|
def main():
drivetrain.turn_to_heading(90, DEGREES)
# VR threads — Do not delete
vr_thread(main)
驱动到#
drive_to drives the VR Rover straight toward the selected object.
Usage:
drivetrain.drive_to(object, wait=True)
参数 |
描述 |
|---|---|
|
Which object the VR Rover will drive to:
|
|
Optional.
|
If a mineral or enemy is not detected in the VR Rover’s visual range when drive_to is called, the rover will not drive. The base can always be targeted.
def main():
drivetrain.drive_to(MINERALS)
# VR threads — Do not delete
vr_thread(main)
转向#
turn_to turns the VR Rover to face the selected object.
Usage:
drivetrain.turn_to(object, wait=True)
参数 |
描述 |
|---|---|
|
Which object the VR Rover will turn toward:
|
|
Optional.
|
If a mineral or enemy is not detected in the VR Rover’s visual range when turn_to is called, the rover will not turn. The base can always be targeted.
def main():
drivetrain.turn_to(MINERALS)
# VR threads — Do not delete
vr_thread(main)
跳转到#
go_to turns and drives the VR Rover to the selected object.
Usage:
drivetrain.go_to(object, wait=True)
参数 |
描述 |
|---|---|
|
Which object the VR Rover will turn and drive to:
|
|
Optional.
|
If a mineral or enemy is not detected in the VR Rover’s visual range when go_to is called, the rover will not drive. The base can always be targeted.
def main():
drivetrain.go_to(MINERALS)
# VR threads — Do not delete
vr_thread(main)
停止#
stop stops all movement of the drivetrain.
Usage:
drivetrain.stop()
参数 |
描述 |
|---|---|
此方法没有参数。 |
def main():
drivetrain.drive(FORWARD)
wait(2, SECONDS)
drivetrain.stop()
# VR threads — Do not delete
vr_thread(main)
变异体#
设置标题#
set_heading sets the rover’s current heading value.
Usage:
drivetrain.set_heading(heading, units)
参数 |
描述 |
|---|---|
|
要分配的标题值。 |
|
The unit of measurement. In this Playground, use |
def main():
drivetrain.set_heading(0, DEGREES)
# VR threads — Do not delete
vr_thread(main)
设置超时#
set_timeout sets a time limit for how long drivetrain methods wait to reach their target.
Usage:
drivetrain.set_timeout(value, units)
参数 |
描述 |
|---|---|
|
动力传动系统停止运转前等待的时间。 |
|
The unit used to represent the timeout:
|
def main():
drivetrain.set_timeout(1, SECONDS)
# VR threads — Do not delete
vr_thread(main)
设置驱动速度#
set_drive_velocity sets the default movement speed used by drive methods.
Usage:
drivetrain.set_drive_velocity(velocity, units)
参数 |
描述 |
|---|---|
|
默认驱动速度范围为 0 到 100。 |
|
The unit used to represent the velocity. In this Playground, use |
def main():
drivetrain.set_drive_velocity(50, PERCENT)
# VR threads — Do not delete
vr_thread(main)
设置转弯速度#
set_turn_velocity sets the default speed used by turn methods.
Usage:
drivetrain.set_turn_velocity(velocity, units)
参数 |
描述 |
|---|---|
|
默认转弯速度范围为 0 到 100。 |
|
The unit used to represent the velocity. In this Playground, use |
def main():
drivetrain.set_turn_velocity(50, PERCENT)
# VR threads — Do not delete
vr_thread(main)
获取器#
标题#
heading returns the drivetrain’s current heading.
Usage:
drivetrain.heading(units)
参数 |
描述 |
|---|---|
|
The unit used to report the heading. In this Playground, use |
def main():
print(drivetrain.heading(DEGREES))
# VR threads — Do not delete
vr_thread(main)
已完成#
is_done returns whether the drivetrain is no longer moving.
Usage:
drivetrain.is_done()
参数 |
描述 |
|---|---|
此方法没有参数。 |
def main():
drivetrain.drive_for(FORWARD, 200, MM, wait=False)
wait(0.1, SECONDS)
if drivetrain.is_done():
print("Drive complete")
# VR threads — Do not delete
vr_thread(main)
正在移动#
is_moving returns whether the drivetrain is currently moving.
Usage:
drivetrain.is_moving()
参数 |
描述 |
|---|---|
此方法没有参数。 |
def main():
drivetrain.drive_for(FORWARD, 200, MM, wait=False)
wait(0.1, SECONDS)
if drivetrain.is_moving():
print("Still moving")
# VR threads — Do not delete
vr_thread(main)
传感#
距离#
找到的对象#
found_object returns whether the Distance Sensor detects an object.
Usage:
distance.found_object()
参数 |
描述 |
|---|---|
此方法没有参数。 |
def main():
if distance.found_object():
print("Object detected")
# VR threads — Do not delete
vr_thread(main)
获取距离#
get_distance returns the distance to the nearest detected object from the Distance Sensor.
Usage:
distance.get_distance(units)
参数 |
描述 |
|---|---|
|
The unit of measurement:
|
def main():
print(distance.get_distance(MM))
# VR threads — Do not delete
vr_thread(main)
行动#
行动#
捡起#
pickup picks up minerals.
Usage:
rover.pickup(object)
参数 |
描述 |
|---|---|
|
The object the VR Rover can pick up:
|
def main():
rover.pickup(MINERALS)
# VR threads — Do not delete
vr_thread(main)
降低#
drop drops carried minerals.
Usage:
rover.drop(object)
参数 |
描述 |
|---|---|
|
The object the VR Rover can drop:
|
def main():
rover.drop(MINERALS)
# VR threads — Do not delete
vr_thread(main)
使用#
use uses minerals to restore energy. Minerals must be on the ground to be used.
Usage:
rover.use(object)
参数 |
描述 |
|---|---|
|
The object the VR Rover can use:
|
def main():
rover.use(MINERALS)
# VR threads — Do not delete
vr_thread(main)
吸收辐射#
absorb_radiation absorbs radiation from an enemy.
Usage:
rover.absorb_radiation(object)
参数 |
描述 |
|---|---|
|
The object the VR Rover can absorb radiation from:
|
def main():
rover.absorb_radiation(ENEMY)
# VR threads — Do not delete
vr_thread(main)
支持#
standby puts the VR Rover into standby mode until the specified battery threshold is reached.
Usage:
rover.standby(percent)
参数 |
描述 |
|---|---|
|
The battery threshold that causes the VR Rover to exit standby mode, from |
如果选定的阈值等于或高于当前电池电量,VR Rover 将不会进入待机模式。
def main():
rover.standby(50)
# VR threads — Do not delete
vr_thread(main)
获取器#
角度#
angle returns the direction in degrees to the selected object.
Usage:
rover.angle(object)
参数 |
描述 |
|---|---|
|
The object to report the direction of:
|
对于矿物和敌方目标,目标必须位于虚拟现实探测车的视野范围内,且距离在 1000 毫米以内。基地位置始终可以报告。
def main():
print(rover.angle(MINERALS))
# VR threads — Do not delete
vr_thread(main)
获取距离#
get_distance returns the distance from the VR Rover to the selected object.
Usage:
rover.get_distance(object, units=MM)
参数 |
描述 |
|---|---|
|
The object to report distance to:
|
|
Optional. The unit used to report the distance:
|
对于矿物和敌方目标,目标必须位于虚拟现实探测车的视野范围内,且距离在 1000 毫米以内。基地位置始终可以报告。
For obstacles and hazards, the method reports the visible object distance. If none is in view, it returns 1000 mm or 39.37 inches.
def main():
print(rover.get_distance(MINERALS, MM))
# VR threads — Do not delete
vr_thread(main)
地点#
location returns the X or Y coordinate location of the selected object.
Usage:
rover.location(object, axis, units)
参数 |
描述 |
|---|---|
|
The object to report the location of:
|
|
Which coordinate to return:
|
|
The unit used to report the location:
|
对于矿物和敌方目标,目标必须位于虚拟现实探测车的视野范围内,且距离在 1000 毫米以内。基地位置始终可以报告。
def main():
print(rover.location(MINERALS, X, MM))
# VR threads — Do not delete
vr_thread(main)
电池#
battery returns the current battery level of the VR Rover.
Usage:
rover.battery()
参数 |
描述 |
|---|---|
此方法没有参数。 |
def main():
print(rover.battery())
# VR threads — Do not delete
vr_thread(main)
储存的矿物#
minerals_stored returns the current amount of minerals the VR Rover has in storage.
Usage:
rover.minerals_stored()
参数 |
描述 |
|---|---|
此方法没有参数。 |
def main():
print(rover.minerals_stored())
# VR threads — Do not delete
vr_thread(main)
存储容量#
storage_capacity returns the carrying capacity of the VR Rover.
Usage:
rover.storage_capacity()
参数 |
描述 |
|---|---|
此方法没有参数。 |
def main():
print(rover.storage_capacity())
# VR threads — Do not delete
vr_thread(main)
等级#
level returns the current level of the VR Rover.
Usage:
rover.level()
参数 |
描述 |
|---|---|
此方法没有参数。 |
def main():
print(rover.level())
# VR threads — Do not delete
vr_thread(main)
经验#
exp returns the number of Experience Points the VR Rover has at the current level.
Usage:
rover.exp()
参数 |
描述 |
|---|---|
此方法没有参数。 |
def main():
print(rover.exp())
# VR threads — Do not delete
vr_thread(main)
敌方等级#
enemy_level returns the level of the closest enemy detected by the VR Rover.
Usage:
rover.enemy_level()
参数 |
描述 |
|---|---|
此方法没有参数。 |
When no enemy is detected within the rover’s detect radius, this method returns 0.
def main():
print(rover.enemy_level())
# VR threads — Do not delete
vr_thread(main)
敌方辐射#
enemy_radiation returns the radiation of the closest enemy detected by the VR Rover.
Usage:
rover.enemy_radiation()
参数 |
描述 |
|---|---|
此方法没有参数。 |
When no enemy is detected within the rover’s detect radius, this method returns 0.
def main():
print(rover.enemy_radiation())
# VR threads — Do not delete
vr_thread(main)
检测#
detects returns whether the VR Rover detects minerals or enemies in its detect radius.
Usage:
rover.detects(object)
参数 |
描述 |
|---|---|
|
The object to detect:
|
VR Rover的探测半径为800毫米。
def main():
if rover.detects(MINERALS):
print("Minerals detected")
# VR threads — Do not delete
vr_thread(main)
看到#
sees returns whether the VR Rover sees the selected object in its vision range.
Usage:
rover.sees(object)
参数 |
描述 |
|---|---|
|
The object to see:
|
VR Rover 可以看到 1000 毫米范围内、40 度视野内的物体。
def main():
if rover.sees(MINERALS):
print("Minerals in view")
# VR threads — Do not delete
vr_thread(main)
遭受攻击#
under_attack returns whether the VR Rover is currently under attack from an enemy.
Usage:
rover.under_attack()
参数 |
描述 |
|---|---|
此方法没有参数。 |
def main():
if rover.under_attack():
print("The rover is under attack!")
# VR threads — Do not delete
vr_thread(main)
回调函数#
遭受攻击#
on_under_attack registers a callback function that runs when the VR Rover takes damage from an enemy.
Usage:
rover.on_under_attack(callback)
参数 |
描述 |
|---|---|
|
VR Rover 遭受攻击时要运行的函数。 |
def under_attack():
print("The rover is under attack!")
def main():
rover.on_under_attack(under_attack)
wait(0.15, SECONDS)
# VR threads — Do not delete
vr_thread(main)
升级#
on_level_up registers a callback function that runs when the VR Rover moves from one level to the next.
Usage:
rover.on_level_up(callback)
参数 |
描述 |
|---|---|
|
VR Rover升级时要运行的函数。 |
def level_up():
print("The rover leveled up!")
def main():
rover.on_level_up(level_up)
wait(0.15, SECONDS)
# VR threads — Do not delete
vr_thread(main)