惯性#

介绍#

GO Brain 包含一个内置惯性传感器,可以让机器人跟踪其方向、航向和加速度。

以下是所有方法的列表:

方向

  • get_heading – Returns the current heading.

  • get_rotation – Returns the current rotation.

  • get_yaw – Returns the current yaw.

  • get_roll – Returns the current roll.

  • get_pitch – Returns the current pitch.

  • calibrate – Calibrates the Inertial Sensor for stable heading tracking.

  • reset_heading – Sets the heading of the Inertial Sensor to 0.

  • reset_rotation – Sets the rotation of the Inertial Sensor to 0.

  • set_heading – Sets the Inertial Sensor’s heading to a specified value.

  • set_rotation – Sets the Inertial Sensor’s rotation to a specified value.

运动

  • get_acceleration – Returns the linear acceleration along the x, y, or z axis.

方向#

get_heading#

get_heading 以度为单位返回惯性传感器的当前航向。

**注意:**如果配置了动力传动系统,此命令将变为 drivetrain.get_heading()

用法:
inertial.get_heading()

参数

描述

该方法没有参数。

# Build Used: Super Code Base 2.0
def main():
    # Display the heading after turning
    drivetrain.turn_for(RIGHT, 450)
    console.print("Heading: ")
    console.print(inertial.get_heading())


# Start threads — Do not delete
start_thread(main)

get_rotation#

get_rotation 返回惯性传感器的当前旋转角度(以度为单位)。

**注意:**如果配置了动力传动系统,此命令将变为 drivetrain.get_rotation()

用法:
inertial.get_rotation()

参数

描述

该方法没有参数。

# Build Used: Super Code Base 2.0
def main():
    # Display the rotation after turning
    drivetrain.turn_for(RIGHT, 450)
    console.print("Rotation: ")
    console.print(inertial.get_rotation())

# Start threads — Do not delete
start_thread(main)

get_yaw#

get_yaw 返回惯性传感器的当前偏航角(以度为单位)。

**注意:**如果配置了动力传动系统,此命令将变为 drivetrain.get_yaw()

用法:
inertial.get_yaw()

参数

描述

该方法没有参数。

# Build Used: Super Code Base 2.0
def main():
    # Change the LED color based on the yaw while
    # moving the robot by hand
    monitor_sensor("inertial.get_yaw")
    while True:
        if inertial.get_yaw() > 0:
            bumper.set_color(GREEN)
        elif inertial.get_yaw() < 0:
            bumper.set_color(RED)
        else:
            bumper.set_color(NONE)

# Start threads — Do not delete
start_thread(main)

get_roll#

get_roll 返回惯性传感器的当前滚动角度(以度为单位)。

**注意:**如果配置了动力传动系统,此命令将变为 drivetrain.get_roll()

用法:
inertial.get_roll()

参数

描述

该方法没有参数。

# Build Used: Super Code Base 2.0
def main():
    # Change the LED color based on the roll while
    # moving the robot by hand
    monitor_sensor("inertial.get_roll")
    while True:
        if inertial.get_roll() > 0:
            bumper.set_color(GREEN)
        elif inertial.get_roll() < 0:
            bumper.set_color(RED)
        else:
            bumper.set_color(NONE)

# Start threads — Do not delete
start_thread(main)

get_pitch#

get_pitch 以度为单位返回惯性传感器的当前俯仰角。

**注意:**如果配置了动力传动系统,此命令将变为 drivetrain.get_pitch()

用法:
inertial.get_pitch()

参数

描述

该方法没有参数。

# Build Used: Super Code Base 2.0
def main():
    # Change the LED color based on the pitch while
    # moving the robot by hand
    monitor_sensor("inertial.get_pitch")
    while True:
        if inertial.get_pitch() > 0:
            bumper.set_color(GREEN)
        elif inertial.get_pitch() < 0:
            bumper.set_color(RED)
        else:
            bumper.set_color(NONE)

# Start threads — Do not delete
start_thread(main)

calibrate#

calibrate 校准惯性传感器。所有后续行都将等待校准完成后再执行。校准是一个内部过程,用于测量并补偿指定时间段内的传感器噪声和漂移。在此期间,Brain 必须保持完全静止(即,在稳定的表面上,没有任何外部运动)。校准期间的移动会导致结果不准确。

**注意:**如果配置了动力传动系统,则此方法不可用。

用法:
inertial.calibrate()

参数

描述

该方法没有参数。

# Build Used: Super Code Base 2.0
def main():
    # Calibrate the robot
    console.print("Calibrating...")
    console.new_line()
    inertial.calibrate()
    console.print("Done!")

# Start threads — Do not delete
start_thread(main)

reset_heading#

reset_heading 将惯性传感器的航向重置为 0 度。

**注意:**如果配置了动力传动系统,则此方法不可用。

用法:
inertial.reset_heading()

参数

描述

该方法没有参数。

# Build Used: Super Code Base 2.0
def main():
    # Turn the robot before and after resetting the heading
    drivetrain.turn_to_heading(90)
    wait(0.5, SECONDS)
    inertial.reset_heading()
    drivetrain.turn_to_heading(90)

# Start threads — Do not delete
start_thread(main)

reset_rotation#

reset_rotation 将惯性传感器的旋转重置为 0 度。

**注意:**如果配置了动力传动系统,则此方法不可用。

用法:
inertial.reset_rotation()

参数

描述

该方法没有参数。

# Build Used: Super Code Base 2.0
def main():
    # Turn the robot before and after resetting the rotation
    drivetrain.turn_to_rotation(-90)
    wait(0.5, SECONDS)
    inertial.reset_rotation()
    drivetrain.turn_to_rotation(-90)

# Start threads — Do not delete
start_thread(main)

set_heading#

set_heading 将惯性传感器的航向设置为指定值。

**注意:**如果配置了动力传动系统,此命令将变为 drivetrain.set_heading()

用法:
inertial.set_heading(heading)

参数

描述

heading

以度为单位设置的航向值。

# Build Used: Super Code Base 2.0
def main():
    # Turn the robot around
    inertial.set_heading(180)
    drivetrain.turn_to_heading(0)

# Start threads — Do not delete
start_thread(main)

set_rotation#

set_rotation 将惯性传感器的旋转设置为指定值。

**注意:**如果配置了动力传动系统,此命令将变为 drivetrain.set_rotation()

用法:

inertial.set_rotation(rotation)

参数

描述

rotation

用于新旋转的度数值。

# Build Used: Super Code Base 2.0
def main():
    # Turn the robot around
    inertial.set_rotation(-180)
    drivetrain.turn_to_rotation(0)

# Start threads — Do not delete
start_thread(main)

运动#

get_acceleration#

get_acceleration 返回惯性传感器的加速度。

用法:
inertial.get_acceleration(axis)

参数

描述

axis

返回加速度的轴:

  • X
  • Y
  • Z
# Build Used: Super Code Base 2.0
def main():
    # Display the acceleration after moving
    drivetrain.set_drive_velocity(100)
    console.print("Resting: ")
    console.new_line()
    console.print(inertial.get_acceleration(X), precision=2)
    console.new_line()
    wait(1, SECONDS)
    drivetrain.drive_for(FORWARD, 500, MM, wait=False)
    wait(0.20,SECONDS)
    console.print("Startup: ")
    console.new_line()
    console.print(inertial.get_acceleration(X), precision=2)

# Start threads — Do not delete
start_thread(main)