VEX GPS Sensor C API module

Contents

Files

file gps.hpp

Classes

class pros::v5::Gps

Functions

Gps(const std::uint8_t port)
Creates a GPS object for the given port.
Gps(const Device& device)
Gps(const std::uint8_t port, double xInitial, double yInitial, double headingInitial) explicit
Creates a GPS object for the given port.
Gps(const std::uint8_t port, double xOffset, double yOffset) explicit
Creates a GPS object for the given port.
Gps(const std::uint8_t port, double xInitial, double yInitial, double headingInitial, double xOffset, double yOffset) explicit
Creates a GPS object for the given port.
std::int32_t initialize_full(double xInitial, double yInitial, double headingInitial, double xOffset, double yOffset) const virtual
Set the GPS's offset relative to the center of turning in meters, as well as its initial position.
std::int32_t set_offset(double xOffset, double yOffset) const virtual
Set the GPS's offset relative to the center of turning in meters.
static std::vector<Gps> get_all_devices()
Gets all GPS sensors.
pros::gps_position_s_t get_offset() const virtual
Get the GPS's cartesian location relative to the center of turning/origin in meters.
std::int32_t set_position(double xInitial, double yInitial, double headingInitial) const virtual
Sets the robot's location relative to the center of the field in meters.
std::int32_t set_data_rate(std::uint32_t rate) const virtual
Set the GPS sensor's data rate in milliseconds, only applies to IMU on GPS.
double get_error() const virtual
Get the possible RMS (Root Mean Squared) error in meters for GPS position.
pros::gps_status_s_t get_position_and_orientation() const virtual
Gets the position and roll, yaw, and pitch of the GPS.
pros::gps_position_s_t get_position() const virtual
Gets the x and y position on the field of the GPS in meters.
double get_position_x() const virtual
Gets the X position in meters of the robot relative to the starting position.
double get_position_y() const virtual
Gets the Y position in meters of the robot relative to the starting position.
pros::gps_orientation_s_t get_orientation() const virtual
Gets the pitch, roll, and yaw of the GPS relative to the starting orientation.
double get_pitch() const virtual
Gets the pitch of the robot in degrees relative to the starting oreintation.
double get_roll() const virtual
Gets the roll of the robot in degrees relative to the starting oreintation.
double get_yaw() const virtual
Gets the yaw of the robot in degrees relative to the starting oreintation.
double get_heading() const virtual
Get the heading in [0,360) degree values.
double get_heading_raw() const virtual
Get the heading in the max double value and min double value scale.
pros::gps_gyro_s_t get_gyro_rate() const virtual
Get the GPS's raw gyroscope value in z-axis.
double get_gyro_rate_x() const virtual
Get the GPS's raw gyroscope value in x-axis.
double get_gyro_rate_y() const virtual
Get the GPS's raw gyroscope value in y-axis.
double get_gyro_rate_z() const virtual
Get the GPS's raw gyroscope value in z-axis.
pros::gps_accel_s_t get_accel() const virtual
Get the GPS's raw accelerometer values.
double get_accel_x() const virtual
Get the GPS's raw accelerometer value in x-axis.
double get_accel_y() const virtual
Get the GPS's raw accelerometer value in y-axis.
double get_accel_z() const virtual
Get the GPS's raw accelerometer value in z-axis.
static Gps get_gps()
Gets a gps sensor that is plugged in to the brain.

Function documentation

Gps(const std::uint8_t port)

Creates a GPS object for the given port.

Parameters
port The V5 port number from 1-21 Example: pros::Gps gps(1);

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Gps(const Device& device)

Gps(const std::uint8_t port, double xInitial, double yInitial, double headingInitial) explicit

Creates a GPS object for the given port.

Parameters
port The V5 port number from 1-21
xInitial Cartesian 4-Quadrant X initial position (meters)
yInitial Cartesian 4-Quadrant Y initial position (meters)
headingInitial Initial heading (degrees)

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example: pros::Gps gps(1, 1.30, 1.20, 90);

Gps(const std::uint8_t port, double xOffset, double yOffset) explicit

Creates a GPS object for the given port.

Parameters
port The V5 port number from 1-21
xOffset Cartesian 4-Quadrant X offset from center of turning (meters)
yOffset Cartesian 4-Quadrant Y offset from center of turning (meters)

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example: pros::Gps gps(1, 1.30, 1.20);

Gps(const std::uint8_t port, double xInitial, double yInitial, double headingInitial, double xOffset, double yOffset) explicit

Creates a GPS object for the given port.

Parameters
port The V5 port number from 1-21
xInitial Initial 4-Quadrant X Position, with (0,0) being at the center of the field (meters)
yInitial Initial 4-Quadrant Y Position, with (0,0) being at the center of the field (meters)
headingInitial Initial Heading, with 0 being North, 90 being East, 180 being South, and 270 being West (degrees)
xOffset Cartesian 4-Quadrant X offset from center of turning (meters)
yOffset Cartesian 4-Quadrant Y offset from center of turning (meters)

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example: pros::Gps gps(1, 1.30, 1.20, 180, 1.30, 1.20);

std::int32_t initialize_full(double xInitial, double yInitial, double headingInitial, double xOffset, double yOffset) const virtual

Set the GPS's offset relative to the center of turning in meters, as well as its initial position.

Parameters
xInitial Initial 4-Quadrant X Position, with (0,0) being at the center of the field (meters)
yInitial Initial 4-Quadrant Y Position, with (0,0) being at the center of the field (meters)
headingInitial Heading with 0 being north on the field, in degrees [0,360) going clockwise
xOffset Cartesian 4-Quadrant X offset from center of turning (meters)
yOffset Cartesian 4-Quadrant Y offset from center of turning (meters)
Returns 1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
    Gps gps(GPS_PORT, 1.1, 1.2, 180, .4, .4);
 // this is equivalent to the above line
 gps.initialize_full(1.1, 1.2, 180, .4, .4);
  while (true) {
    delay(20);
  }
}

std::int32_t set_offset(double xOffset, double yOffset) const virtual

Set the GPS's offset relative to the center of turning in meters.

Parameters
xOffset Cartesian 4-Quadrant X offset from center of turning (meters)
yOffset Cartesian 4-Quadrant Y offset from center of turning (meters)
Returns 1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
    Gps gps(GPS_PORT, 1.1, 1.2, 180, .4, .4);
 // this is equivalent to the above line
 gps.set_offset(.4, .4);
  while (true) {
    delay(20);
  }
}

static std::vector<Gps> get_all_devices()

Gets all GPS sensors.

Returns A vector of Gps sensor objects.

Example

void opcontrol() {
  std::vector<Gps> gps_all = pros::Gps::get_all_devices();  // All GPS sensors that are connected
}

pros::gps_position_s_t get_offset() const virtual

Get the GPS's cartesian location relative to the center of turning/origin in meters.

Returns A struct (gps_position_s_t) containing the X and Y values if the operation failed, setting errno.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
  gps_position_s_t pos;
    Gps gps(GPS_PORT);
  while (true) {
    pos = gps.get_offset();
    screen_print(TEXT_MEDIUM, 1, "X Offset: %4d, Y Offset: %4d", pos.x, pos.y);
    delay(20);
  }
}

std::int32_t set_position(double xInitial, double yInitial, double headingInitial) const virtual

Sets the robot's location relative to the center of the field in meters.

Parameters
xInitial Initial 4-Quadrant X Position, with (0,0) being at the center of the field (meters)
yInitial Initial 4-Quadrant Y Position, with (0,0) being at the center of the field (meters)
headingInitial Heading with 0 being north on the field, in degrees [0,360) going clockwise
Returns 1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
    Gps gps(GPS_PORT);
 gps.set_position(1.3, 1.4, 180);
  while (true) {
    printf("X: %f, Y: %f, Heading: %f\n", gps.get_position().x,
       gps.get_position().y, gps.get_position().heading);
    delay(20);
  }
}

std::int32_t set_data_rate(std::uint32_t rate) const virtual

Set the GPS sensor's data rate in milliseconds, only applies to IMU on GPS.

Parameters
rate Data rate in milliseconds (Minimum: 5 ms)
Returns 1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
    Gps gps(GPS_PORT);
 gps.set_data_rate(10);
  while (true) {
    printf("X: %f, Y: %f, Heading: %f\n", gps.get_position().x,
       gps.get_position().y, gps.get_position().heading);
    delay(10);
  }
}

double get_error() const virtual

Get the possible RMS (Root Mean Squared) error in meters for GPS position.

Returns Possible RMS (Root Mean Squared) error in meters for GPS position. If the operation failed, returns PROS_ERR_F and errno is set.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
    Gps gps(GPS_PORT);
 double error = gps.get_error();
 printf("Error: %f\n", error);
 pros::delay(20);
}

pros::gps_status_s_t get_position_and_orientation() const virtual

Gets the position and roll, yaw, and pitch of the GPS.

Returns A struct (gps_status_s_t) containing values mentioned above. If the operation failed, all the structure's members are filled with PROS_ERR_F and errno is set.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
    Gps gps(GPS_PORT);
 gps_status_s_t status;
  while (true) {
    status = gps.get_position_and_orientation();
    printf("X: %f, Y: %f, Roll: %f, Pitch: %f, Yaw: %f\n",
       status.x, status.y, status.roll, status.pitch, status.yaw);
    delay(20);
  }
}

pros::gps_position_s_t get_position() const virtual

Gets the x and y position on the field of the GPS in meters.

Returns A struct (gps_position_s_t) containing values mentioned above. If the operation failed, all the structure's members are filled with PROS_ERR_F and errno is set.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
    Gps gps(GPS_PORT);
 gps_position_s_t position;
  while (true) {
  position = gps.get_position();
    printf("X: %f, Y: %f\n", position.x, position.y);
    delay(20);
  }
}

double get_position_x() const virtual

Gets the X position in meters of the robot relative to the starting position.

Returns The X position in meters. If the operation failed, returns PROS_ERR_F and errno is set.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
    Gps gps(GPS_PORT);
 while(true) {
    double pos_x = gps.get_position_x();
    printf("X: %f\n", pos_x);
    pros::delay(20);
 }
}

double get_position_y() const virtual

Gets the Y position in meters of the robot relative to the starting position.

Returns The Y position in meters. If the operation failed, returns PROS_ERR_F and errno is set.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
    Gps gps(GPS_PORT);
 while(true) {
    double pos_y = gps.get_position_y();
    printf("Y: %f\n", pos_y);
    pros::delay(20);
 }
}

pros::gps_orientation_s_t get_orientation() const virtual

Gets the pitch, roll, and yaw of the GPS relative to the starting orientation.

Returns A struct (gps_orientation_s_t) containing values mentioned above. If the operation failed, all the structure's members are filled with PROS_ERR_F and errno is set.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
    Gps gps(GPS_PORT);
 gps_orientation_s_t orientation;
  while (true) {
  orientation = gps.get_orientation();
    printf("pitch: %f, roll: %f, yaw: %f\n", orientation.pitch,
        orientation.roll, orientation.yaw);
    delay(20);
  }
}

double get_pitch() const virtual

Gets the pitch of the robot in degrees relative to the starting oreintation.

Returns The pitch in [0,360) degree values. If the operation failed, returns PROS_ERR_F and errno is set.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
    Gps gps(GPS_PORT);
 while(true) {
    double pitch = gps.get_pitch();
    printf("pitch: %f\n", pitch);
    pros::delay(20);
 }
}

double get_roll() const virtual

Gets the roll of the robot in degrees relative to the starting oreintation.

Returns The roll in [0,360) degree values. If the operation failed, returns PROS_ERR_F and errno is set.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
    Gps gps(GPS_PORT);
 while(true) {
    double roll = gps.get_roll();
    printf("roll: %f\n", roll);
    pros::delay(20);
 }
}

double get_yaw() const virtual

Gets the yaw of the robot in degrees relative to the starting oreintation.

Returns The yaw in [0,360) degree values. If the operation failed, returns PROS_ERR_F and errno is set.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
    Gps gps(GPS_PORT);
 while(true) {
    double yaw = gps.get_yaw();
    printf("yaw: %f\n", yaw);
    pros::delay(20);
 }
}

double get_heading() const virtual

Get the heading in [0,360) degree values.

Returns The heading in [0,360) degree values. If the operation failed, returns PROS_ERR_F and errno is set.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
    Gps gps(GPS_PORT);
 while(true) {
    double heading = gps.get_heading();
    printf("Heading: %f\n", heading);
    pros::delay(20);
 }
}

double get_heading_raw() const virtual

Get the heading in the max double value and min double value scale.

Returns The heading in [DOUBLE_MIN, DOUBLE_MAX] values. If the operation fails, returns PROS_ERR_F and errno is set.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
    Gps gps(GPS_PORT);
 while(true) {
    double heading = gps.get_heading_raw();
    printf("Heading: %f\n", heading);
    pros::delay(20);
 }
}

pros::gps_gyro_s_t get_gyro_rate() const virtual

Get the GPS's raw gyroscope value in z-axis.

Returns The raw gyroscope value in z-axis. If the operation fails, returns PROS_ERR_F and errno is set.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
  Gps gps(GPS_PORT);
 while(true) {
      double gyro_z = gps.get_gyro_z();
      printf("gyro_z: %f\n", gyro_z);
  pros::delay(20);
 }
}

double get_gyro_rate_x() const virtual

Get the GPS's raw gyroscope value in x-axis.

Returns The raw gyroscope value in x-axis. If the operation fails, returns PROS_ERR_F and errno is set.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
    Gps gps(GPS_PORT);
 while(true) {
    double gyro_x = gps.get_gyro_x();
    printf("gyro_x: %f\n", gyro_x);
    pros::delay(20);
 }
}

double get_gyro_rate_y() const virtual

Get the GPS's raw gyroscope value in y-axis.

Returns The raw gyroscope value in y-axis. If the operation fails, returns PROS_ERR_F and errno is set.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
    Gps gps(GPS_PORT);
 while(true) {
    double gyro_y = gps.get_gyro_y();
    printf("gyro_y: %f\n", gyro_y);
    pros::delay(20);
 }
}

double get_gyro_rate_z() const virtual

Get the GPS's raw gyroscope value in z-axis.

Returns The raw gyroscope value in z-axis. If the operation fails, returns PROS_ERR_F and errno is set.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as a GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
  Gps gps(GPS_PORT);
 while(true) {
      double gyro_z = gps.get_gyro_z();
      printf("gyro_z: %f\n", gyro_z);
  pros::delay(20);
 }
}

pros::gps_accel_s_t get_accel() const virtual

Get the GPS's raw accelerometer values.

Returns The raw accelerometer values. If the operation failed, all the structure's members are filled with PROS_ERR_F and errno is set.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as an GPS EAGAIN - The sensor is still calibrating

double get_accel_x() const virtual

Get the GPS's raw accelerometer value in x-axis.

Returns The raw accelerometer value in x-axis. If the operation fails, returns PROS_ERR_F and errno is set.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as an GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
    Gps gps(GPS_PORT);
 while(true) {
    double accel_x = gps.get_accel_x();
    printf("accel_x: %f\n", accel_x);
    pros::delay(20);
 }
}

double get_accel_y() const virtual

Get the GPS's raw accelerometer value in y-axis.

Returns The raw accelerometer value in y-axis. If the operation fails, returns PROS_ERR_F and errno is set.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as an GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
    Gps gps(GPS_PORT);
 while(true) {
    double accel_y = gps.get_accel_y();
    printf("accel_y: %f\n", accel_y);
    pros::delay(20);
 }
}

double get_accel_z() const virtual

Get the GPS's raw accelerometer value in z-axis.

Returns The raw accelerometer value in z-axis. If the operation fails, returns PROS_ERR_F and errno is set.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as an GPS EAGAIN - The sensor is still calibrating

Example

#define GPS_PORT 1

void opcontrol() {
    Gps gps(GPS_PORT);
 while(true) {
    double accel_z = gps.get_accel_z();
    printf("accel_z: %f\n", accel_z);
    pros::delay(20);
 }
}

static Gps get_gps()

Gets a gps sensor that is plugged in to the brain.

Returns A gps object corresponding to a port that a gps sensor is connected to the brain If no gps sensor is plugged in, it returns a gps sensor on port PROS_ERR_BYTE

This functions uses the following values of errno when an error state is reached: ENODEV - No gps sensor is plugged into the brain