机器人专用 Python#
所有标准 VEXcode VR 命令均可在 VIQRC 虚拟技能 - Pitching In 游乐场中使用。
运动#
电机.旋转()#
motor.spin(direction)
命令用于无限旋转电机。
这是一个非等待命令,允许任何后续命令无延迟地执行。
要使用此命令,请将“motor”替换为所需的电机或电机组,例如:“intake_motor.spin(direction)”。
对象 |
描述 |
---|---|
|
旋转快照的进气口以从场地拾取球。 |
|
升起或降低弹射器。 |
|
提高或降低弹射器的张力,影响球被弹射的距离。 |
参数 |
描述 |
---|---|
方向 |
电机转动的方向:“前进”或“后退”。 |
**返回:**无。
def main():
# Spin the intake motor forward.
intake_motor.spin(FORWARD)
# Wait half a second.
wait(0.5, SECONDS)
# Stop spinning the intake motor group.
intake_motor.stop()
电机.spin_for()#
motor.spin_for(direction, distance, units, wait)
命令用于使电机旋转给定的度数或圈数。
这可以是非等待或等待命令,取决于是否使用了“wait”参数。
要使用此命令,请将“motor”替换为所需的电机或电机组,例如:“intake_motor_group.spin_for(direction, distance, units, wait)”。
对象 |
描述 |
---|---|
|
旋转快照的进气口以从场地拾取球。 |
|
升起或降低弹射器。 |
|
提高或降低弹射器的张力,影响球被弹射的距离。 |
参数 |
描述 |
---|---|
方向 |
电机转动的方向:“前进”或“后退”。 |
距离 |
电机移动的距离,为整数。 |
单位 |
电机将使用的单位:“度”或“圈”。 |
等待 |
可选。 wait 参数决定命令是否阻止后续命令( |
**返回:**无。
def main():
# Spin the intake motor forward for 1 turn.
intake_motor.spin_for(FORWARD, 1, TURNS)
电机.旋转到位置()#
motor.spin_to(angle, unit, wait)
命令用于将电机旋转到给定位置。
这可以是非等待或等待命令,取决于是否使用了“wait”参数。
要使用此命令,请将“motor”替换为所需的电机或电机组,例如:“intake_motor_group.spin_for(angle, unit, wait)”。
对象 |
描述 |
---|---|
|
旋转快照的进气口以从场地拾取球。 |
|
升起或降低弹射器。 |
|
提高或降低弹射器的张力,影响球被弹射的距离。 |
参数 |
描述 |
---|---|
角度 |
电机旋转的特定角度或圈数。 |
单位 |
电机将使用的单位:“度”或“圈”。 |
等待 |
可选。 wait 参数决定命令是否阻止后续命令( |
**返回:**无。
def main():
# Spin the intake motor to 55 degrees.
intake_motor.spin_to_position(55, DEGREES)
电机停止()#
motor.stop()
命令用于停止电机。
这是一个非等待命令,允许任何后续命令无延迟地执行。
要使用此命令,请将“motor”替换为所需的电机或电机组,例如:“intake_motor_group.stop()”。
对象 |
描述 |
---|---|
|
旋转快照的进气口以从场地拾取球。 |
|
升起或降低弹射器。 |
|
提高或降低弹射器的张力,影响球被弹射的距离。 |
**返回:**无。
def main():
# Spin the intake motor forward.
intake_motor.spin(FORWARD)
# Wait one second.
wait(1, SECONDS)
# Stop spinning the intake motor group.
intake_motor.stop()
电机.设置位置()#
motor.set_position(position, units)
命令用于将电机的编码器位置设置为给定的位置值。
这是一个非等待命令,允许任何后续命令无延迟地执行。
要使用此命令,请将“motor”替换为所需的电机或电机组,例如:“intake_motor_group.set_position(position, units)”。
对象 |
描述 |
---|---|
|
旋转快照的进气口以从场地拾取球。 |
|
升起或降低弹射器。 |
|
提高或降低弹射器的张力,影响球被弹射的距离。 |
参数 |
描述 |
---|---|
位置 |
IQ 电机编码器的具体整数设置。 |
单位 |
电机使用的单位:“度”或“圈”。 |
**返回:**无。
def main():
# Set the current motor position to 90 degrees.
intake_motor.set_position(90, DEGREES)
# Spin the intake motor back to 0 degrees.
intake_motor.spin_to_position(0, DEGREES)
电机.设置速度()#
motor.set_velocity(velocity, units)
命令用于设置电机的速度。
这是一个非等待命令,允许任何后续命令无延迟地执行。
要使用此命令,请将“motor”替换为所需的电机或电机组,例如:“intake_motor_group.set_velocity(velocity, units)”。
对象 |
描述 |
---|---|
|
旋转快照的进气口以从场地拾取球。 |
|
升起或降低弹射器。 |
|
提高或降低弹射器的张力,影响球被弹射的距离。 |
参数 |
描述 |
---|---|
速度 |
IQ 电机旋转的速度,范围从 -100 到 100。 |
单位 |
电机速度的单位“百分比”。 |
**返回:**无。
def main():
# Set the intake motor velocity to 75 percent.
intake_motor.set_velocity(75, PERCENT)
# Spin the intake motor to 180 degrees.
intake_motor.spin_to_position(180, DEGREES)
电机.设置超时()#
motor.set_timeout(value, units)
命令用于设置电机运动命令的时间限制。
这可以防止未到达预定位置的运动命令阻止后续命令运行。
这是一个非等待命令,允许任何后续命令无延迟地执行。
要使用此命令,请将“motor”替换为所需的电机或电机组,例如:“intake_motor_group.set_timeout(value, units)”。
对象 |
描述 |
---|---|
|
旋转快照的进气口以从场地拾取球。 |
|
升起或降低弹射器。 |
|
提高或降低弹射器的张力,影响球被弹射的距离。 |
参数 |
描述 |
---|---|
价值 |
电机停止前等待的时间。 |
单位 |
电机计时器的单位“秒”。 |
**返回:**无。
def main():
# Set the intake motor's timeout to 2 seconds.
intake_motor.set_timeout(2, SECONDS)
# Spin the intake motor to 270 degrees.
intake_motor.spin_to_position(270, DEGREES)
活动#
进气保险杠.按下()#
intake_bumper.pressed(callback)
与 bumper.pressed(callback)
是相同的命令。
该命令仅使用Fling特定的bumper传感器‘intake_bumper’来替换标准命令中的‘bumper’。
intake_bumper.released()#
intake_bumper.released(callback)
与 bumper.released(callback)
是相同的命令。
该命令仅使用Fling特定的bumper传感器‘intake_bumper’来替换标准命令中的‘bumper’。
传感#
电机.is_done()#
如果选定的电机已完成其运动,则 motor.is_done()
命令用于返回 True 或 False 值。
要使用此命令,请将“motor”替换为所需的电机或电机组,例如:“intake_motor_group.is_done()”。
对象 |
描述 |
---|---|
|
旋转快照的进气口以从场地拾取球。 |
|
升起或降低弹射器。 |
|
提高或降低弹射器的张力,影响球被弹射的距离。 |
**返回:**这将返回一个布尔值。
def main():
# Move the Arm so it doesn't block the Front Distance Sensor.
intake_motor.spin_to_position(1000, DEGREES)
# Wait until the intake_motor has finished moving.
if intake_motor.is_done():
# Print the distance from the Front Distance Sensor to the closest
# object in front of it.
brain.screen.print(front_distance.object_distance(MM))
电机正在旋转()#
如果选定的电机正在移动,则使用 motor.is_spinning()
命令返回 True 或 False 值。
要使用此命令,请将“motor”替换为所需的电机或电机组,例如:“intake_motor_group.is_spinning()”。
对象 |
描述 |
---|---|
|
旋转快照的进气口以从场地拾取球。 |
|
升起或降低弹射器。 |
|
提高或降低弹射器的张力,影响球被弹射的距离。 |
**返回:**这将返回一个布尔值。
# Example coming soon.
电机位置()#
motor.position(units)
命令用于返回所选电机的当前旋转位置。
要使用此命令,请将“motor”替换为所需的电机或电机组,例如:“intake_motor_group.position(units)”。
对象 |
描述 |
---|---|
|
旋转快照的进气口以从场地拾取球。 |
|
升起或降低弹射器。 |
|
提高或降低弹射器的张力,影响球被弹射的距离。 |
参数 |
描述 |
---|---|
单位 |
返回值的单位, |
**返回:**这将返回一个数值。
def main():
# Print the current position of the intake_motor_group in degrees.
brain.screen.print(intake_motor_group.position(DEGREES))
电机.速度()#
motor.velocity(units)
命令用于返回所选电机的当前速度。
要使用此命令,请将“motor”替换为所需的电机或电机组,例如:“intake_motor_group.velocity(units)”。
对象 |
描述 |
---|---|
|
旋转快照的进气口以从场地拾取球。 |
|
升起或降低弹射器。 |
|
提高或降低弹射器的张力,影响球被弹射的距离。 |
参数 |
描述 |
---|---|
单位 |
电机速度的单位,“百分比”。 |
**返回:**这将返回一个数值。
def main():
# Print the current velocity of the intake_motor.
brain.screen.print(intake_motor_group.velocity(PERCENT))
intake_bumper.pressing()#
intake_bumper.pressing()
与 bumper.pressing()
是相同的命令。
该命令仅使用Fling专用的Bumper传感器“intake_bumper”来替换标准命令中的“bumper”。
距离.对象距离()#
distance.object_distance(units)
命令用于报告距离距离传感器最近物体的距离。
这是一个非等待命令,允许任何后续命令无延迟地执行。
参数 |
描述 |
---|---|
单位 |
报告距离的单位为“英寸”或“MM”(毫米)。 |
**返回:**这将返回一个数值。
def main():
# Print the current distance to the nearest object in MM.
brain.print(distance.object_distance(MM))
距离.is_object_detected()#
如果距离传感器在其视野内看到一个物体,则使用“distance.is_object_detected()”命令报告布尔值。
这是一个非等待命令,允许任何后续命令无延迟地执行。
**返回:**报告一个布尔值。
def main():
# Print if the Distance Sensor detects an object in its Field of View.
brain.print(distance.is_object_detected())
颜色.靠近物体()#
如果颜色传感器距离物体足够近以检测到颜色,则使用“color.is_near_object()”命令报告布尔值。
这是一个非等待命令,允许任何后续命令无延迟地执行。
**返回:**报告一个布尔值。
def main():
# Print if the Color Sensor is detecting a color.
brain.print(color.is_near_object())
颜色.颜色()#
color.color()
命令用于返回 VEX IQ 光学传感器检测到的颜色。
这是一个非等待命令,允许任何后续命令无延迟地执行。
以下颜色可用于与 IQ 光学传感器检测到的颜色进行比较:
颜色.RED
颜色.绿色
颜色.蓝色
颜色.黄色
颜色.橙色
颜色.紫色
颜色.青色
**返回:**这将返回一个布尔值。
def main():
# Print the color of the object that the Front Optical Sensor sees.
brain.print(color.color())
颜色.亮度()#
color.brightness()
命令用于报告 VEX IQ 光学传感器检测到的 0 到 100% 范围内的光量。
这是一个非等待命令,允许任何后续命令无延迟地执行。
**返回:**这将返回一个数值。
def main():
# Print the brightness of the object in front of Fling.
brain.print(color.brightness())
颜色.色调()#
color.brightness()
命令用于报告 VEX IQ 光学传感器检测到的物体的色调,范围在 0 到 359 之间。该数字表示检测到的颜色在色轮上的位置。
这是一个非等待命令,允许任何后续命令无延迟地执行。
**返回:**这将返回一个数值。
def main():
# Print the hue of the object in front of Fling.
brain.screen.print("Hue: ", optical.hue())