GPS传感器#
介绍#
V5 GPS(游戏定位系统™)传感器可为 VEX 场地上的机器人提供精确的位置和方向跟踪。它利用场地周边的 GPS 场地代码实时计算机器人的 X 和 Y 坐标以及航向。
GPS 传感器使用在“设备”窗口中配置 GPS 传感器时输入的偏移量自动计算出的参考点来返回机器人的位置。
有关 GPS 传感器的更多信息,请阅读 VEX 库中的 将 GPS 传感器与 VEX V5 一起使用。
参考点作为 GPS 传感器自身的 (0, 0) 位置,GPS 方法返回的所有坐标、航向和运动都相对于此配置点。

This page uses gps_sensor as the example GPS Sensor name. Replace it with your own configured name as needed.
以下是可用方法列表:
calibrate– Calibrates the GPS Sensor to set its heading as the current drivetrain heading.set_origin– Sets the position of the reference point on the robot.set_location– Sets both the reference point’s position and heading on the Field.x_position– Returns the reference point’s x coordinate on the Field.y_position– Returns the reference point’s y coordinate on the Field.heading– Returns the reference point’s heading based on the Field orientation.acceleration– Returns the robot’s acceleration on a selected axis.gyro_rate– Returns the robot’s rotational speed on a selected axis.orientation– Returns the robot’s roll, pitch, or yaw orientation in degrees.quality– Returns the signal strength of the GPS Sensor.changed– Registers a function to be called whenever the GPS Sensor detects a change in heading.
构造函数 - 手动初始化 GPS 传感器。
Gps– Creates a GPS Sensor.
校准#
calibrate calibrates the reference point, setting its configured heading as the current drivetrain heading. During this time, the robot must remain completely still as movement during calibration will produce inaccurate results.
Usage:
gps_sensor.calibrate()
参数 |
描述 |
|---|---|
此方法没有参数。 |
设置原点#
set_origin sets the position of the reference point on the robot manually. This can be done so to manually set a GPS Sensor’s location on a robot instead of doing so in the configuration settings.
Usage:
gps_sensor.set_origin(x, y, distance_units)
参数 |
描述 |
|---|---|
x |
机器人上参考点的 x 坐标。 |
是 |
机器人上参考点的y坐标。 |
距离单位 |
The unit of measurement for the x and y coordinates:
|
# GPS Sensor is mounted 25mm forward
# from the reference point on a robot
gps.set_origin(0, 25, MM)
设置位置#
set_location sets the position and heading of the reference point on the Field manually. This can be done to help reduce inaccuracies if the GPS Sensor is too close to the Field’s walls on startup to get a sufficient amount of the GPS Field Code in its view.

Usage:
gps_sensor.set_location(x, y, distance_units, heading, heading_units)
参数 |
描述 |
|---|---|
x |
场上参考点的 x 坐标。 |
是 |
场上参考点的 y 坐标。 |
距离单位 |
The unit of measurement for the x and y coordinates:
|
标题 |
参考点相对于绝对场航向的航向,范围从 0 度到 359.9 度。 |
标题单位 |
The unit of measurement for the heading:
|
x_position#
x_position returns the reference point’s x coordinate on the Field.
Usage:
gps_sensor.x_position(units)
参数 |
描述 |
|---|---|
单元 |
The unit of measurement:
|
y 位置#
y_position returns the reference point’s y coordinate on the Field.
Usage:
gps_sensor.y_position(units)
参数 |
描述 |
|---|---|
单元 |
The unit of measurement:
|
标题#
heading returns the reference point’s heading based on the Field’s orientation from 0 to 359.9 degrees.
该航向对应于绝对航向,其范围为顺时针方向的 0º 至 359.9º。0º 位于 12 点钟位置。

Usage:
gps_sensor.heading()
参数 |
描述 |
|---|---|
此方法没有参数。 |
加速度#
acceleration returns the robot’s acceleration on a specified axis from -4.0 to 4.0 Gs.
Usage:
gps_sensor.acceleration(axis)
参数 |
描述 |
|---|---|
轴 |
Which axis to use:
|
陀螺仪速率#
gyro_rate returns the robot’s rotational speed on a selected axis.
Usage:
gps_sensor.gyro_rate(axis, units)
参数 |
描述 |
|---|---|
轴 |
Which axis to use:
|
单位 |
The unit of measurement:
|
方向#
orientation returns the robot’s roll, pitch, or yaw orientation in degrees.
Usage:
gps_sensor.orientation(axis, units)
参数 |
描述 |
|---|---|
轴 |
Which orientation to use:
|
单位 |
The unit of measurement:
|
质量#
quality returns the signal strength of the GPS Sensor as a percent.
可能的值 |
描述 |
|---|---|
100 |
GPS传感器报告的所有位置和航向数据均有效。 |
约90 |
位置数据不再通过捕获 GPS 场代码信息来计算,而是通过其他方式计算。 |
0-80 |
只有 GPS 传感器的航向值是有效的,但随着时间的推移,GPS 传感器扫描到的 GPS 场码不足以准确确定位置和航向信息,报告的信号质量将持续下降,直到 0,此时所有 GPS 传感器数据实际上都被冻结,不再有效。 |
Usage:
gps_sensor.quality()
参数 |
描述 |
|---|---|
此方法没有参数。 |
已更改#
changed registers a function to be called whenever the GPS Sensor detects a change in heading.
Usage:
gps_sensor.changed(callback, arg)
参数 |
描述 |
|---|---|
|
先前定义的 函数,当 GPS 传感器的航向发生变化时执行。 |
|
可选。包含要传递给回调函数的参数的元组。有关更多信息,请参阅使用带参数的函数。 |
def my_function():
brain.screen.print("GPS heading changed")
# Call my_function whenever gps_sensor's heading changes
gps_sensor.changed(my_function)
构造函数#
Constructors are used to manually create Gps objects, which are necessary for configuring a GPS Sensor outside of VEXcode.
Gps#
Gps creates a GPS Sensor.
Usage:
Gps(smartport)
范围 |
描述 |
|---|---|
|
The Smart Port that the GPS Sensor is connected to, written as |
# Create a GPS Sensor in Port 10
gps_sensor = Gps(Ports.PORT10)