VEX Inertial Sensor C API module

Files

file imu.h

Namespaces

namespace pros::c

Classes

struct pros::imu_raw_s
struct quaternion_s_t
struct imu_gyro_s_t
struct imu_accel_s_t
struct euler_s_t

Functions

int32_t imu_reset(uint8_t port)
Calibrate IMU.
int32_t imu_reset_blocking(uint8_t port)
Calibrate IMU and Blocks while Calibrating.
int32_t imu_set_data_rate(uint8_t port, uint32_t rate)
Set the Inertial Sensor's refresh interval in milliseconds.
double imu_get_rotation(uint8_t port)
Get the total number of degrees the Inertial Sensor has spun about the z-axis.
double imu_get_heading(uint8_t port)
Get the Inertial Sensor's heading relative to the initial direction of its x-axis.
quaternion_s_t imu_get_quaternion(uint8_t port)
Get a quaternion representing the Inertial Sensor's orientation.
euler_s_t imu_get_euler(uint8_t port)
Get the Euler angles representing the Inertial Sensor's orientation.
imu_gyro_s_t imu_get_gyro_rate(uint8_t port)
Get the Inertial Sensor's raw gyroscope values.
imu_accel_s_t imu_get_accel(uint8_t port)
Get the Inertial Sensor's raw acceleroneter values.
imu_status_e_t imu_get_status(uint8_t port)
Get the Inertial Sensor's status.
double imu_get_pitch(uint8_t port)
Get the Inertial Sensor's pitch angle bounded by (-180,180)
double imu_get_roll(uint8_t port)
Get the Inertial Sensor's roll angle bounded by (-180,180)
double imu_get_yaw(uint8_t port)
Get the Inertial Sensor's yaw angle bounded by (-180,180)

Value Reset Functions

int32_t imu_tare_heading(uint8_t port)
Resets the current reading of the Inertial Sensor's heading to zero.
int32_t imu_tare_rotation(uint8_t port)
Resets the current reading of the Inertial Sensor's rotation to zero.
int32_t imu_tare_pitch(uint8_t port)
Resets the current reading of the Inertial Sensor's pitch to zero.
int32_t imu_tare_roll(uint8_t port)
Resets the current reading of the Inertial Sensor's roll to zero.
int32_t imu_tare_yaw(uint8_t port)
Resets the current reading of the Inertial Sensor's yaw to zero.
int32_t imu_tare_euler(uint8_t port)
Reset all 3 euler values of the Inertial Sensor to 0.
int32_t imu_tare(uint8_t port)
Resets all 5 values of the Inertial Sensor to 0.

Value Set Functions

int32_t imu_set_euler(uint8_t port, euler_s_t target)
Sets the current reading of the Inertial Sensor's euler values to target euler values.
int32_t imu_set_rotation(uint8_t port, double target)
Sets the current reading of the Inertial Sensor's rotation to target value.
int32_t imu_set_heading(uint8_t port, double target)
Sets the current reading of the Inertial Sensor's heading to target value Target will default to 360 if above 360 and default to 0 if below 0.
int32_t imu_set_pitch(uint8_t port, double target)
Sets the current reading of the Inertial Sensor's pitch to target value Will default to +/- 180 if target exceeds +/- 180.
int32_t imu_set_roll(uint8_t port, double target)
Sets the current reading of the Inertial Sensor's roll to target value Will default to +/- 180 if target exceeds +/- 180.
int32_t imu_set_yaw(uint8_t port, double target)
Sets the current reading of the Inertial Sensor's yaw to target value Will default to +/- 180 if target exceeds +/- 180.
imu_orientation_e_t imu_get_physical_orientation(uint8_t port)
Returns the physical orientation of the IMU.

Enums

enum imu_status_e { E_IMU_STATUS_READY = 0, E_IMU_STATUS_CALIBRATING = 1, E_IMU_STATUS_ERROR = 0xFF }
enum imu_orientation_e { E_IMU_Z_UP = 0, E_IMU_Z_DOWN = 1, E_IMU_X_UP = 2, E_IMU_X_DOWN = 3, E_IMU_Y_UP = 4, E_IMU_Y_DOWN = 5, E_IMU_ORIENTATION_ERROR = 0xFF }

Typedefs

using imu_gyro_s_t = struct imu_raw_s
using imu_accel_s_t = struct imu_raw_s

Variables

quaternion_s_t
double x
double y
double z
euler_s_t

Defines

#define IMU_MINIMUM_DATA_RATE

Function documentation

int32_t imu_reset(uint8_t port)
#include <pros/imu.h>

Calibrate IMU.

Parameters
port The V5 Inertial Sensor port number from 1-21
Returns 1 if the operation was successful or PROS_ERR if the operation failed setting errno.

Calibration takes approximately 2 seconds, but this function only blocks until the IMU status flag is set properly to E_IMU_STATUS_CALIBRATING, with a minimum blocking time of 5ms.

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 Inertial Sensor EAGAIN - The sensor is already calibrating, or time out setting the status flag.

Example

#define IMU_PORT 1

void initialize() {
  imu_reset(IMU_PORT);
  int time = millis();
  int iter = 0;
  while (imu_get_status(IMU_PORT) & E_IMU_STATUS_CALIBRATING) {
    printf("IMU calibrating... %d\n", iter);
    iter += 10;
    delay(10);
  }
  // should print about 2000 ms
  printf("IMU is done calibrating (took %d ms)\n", iter - time);
}

int32_t imu_reset_blocking(uint8_t port)
#include <pros/imu.h>

Calibrate IMU and Blocks while Calibrating.

Parameters
port The V5 Inertial Sensor port number from 1-21
Returns 1 if the operation was successful or PROS_ERR if the operation failed (timing out or port claim failure), setting errno.

Calibration takes approximately 2 seconds and blocks during this period, with a timeout for this operation being set a 3 seconds as a safety margin. Like the other reset function, this function also blocks until the IMU status flag is set properly to E_IMU_STATUS_CALIBRATING, with a minimum blocking time of 5ms and a timeout of 1 second if it's never 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 Inertial Sensor EAGAIN - The sensor is already calibrating, or time out setting the status flag.

int32_t imu_set_data_rate(uint8_t port, uint32_t rate)
#include <pros/imu.h>

Set the Inertial Sensor's refresh interval in milliseconds.

Parameters
port The V5 Inertial Sensor port number from 1-21
rate The data refresh interval in milliseconds
Returns 1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

The rate may be specified in increments of 5ms, and will be rounded down to the nearest increment. The minimum allowable refresh rate is 5ms. The default rate is 10ms.

As values are copied into the shared memory buffer only at 10ms intervals, setting this value to less than 10ms does not mean that you can poll the sensor's values any faster. However, it will guarantee that the data is as recent as possible.

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 Inertial Sensor EAGAIN - The sensor is still calibrating

Example

double imu_get_rotation(uint8_t port)
#include <pros/imu.h>

Get the total number of degrees the Inertial Sensor has spun about the z-axis.

Parameters
port The V5 Inertial Sensor port number from 1-21
Returns The degree value or PROS_ERR_F if the operation failed, setting errno.

This value is theoretically unbounded. Clockwise rotations are represented with positive degree values, while counterclockwise rotations are represented with negative ones.

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 Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1

void opcontrol() {
  while (true) {
    printf("IMU get rotation: %f degrees\n", imu_get_rotation(IMU_PORT));
    delay(20);
  }
}

double imu_get_heading(uint8_t port)
#include <pros/imu.h>

Get the Inertial Sensor's heading relative to the initial direction of its x-axis.

Parameters
port The V5 Inertial Sensor port number from 1-21
Returns The degree value or PROS_ERR_F if the operation failed, setting errno.

This value is bounded by [0,360). Clockwise rotations are represented with positive degree values, while counterclockwise rotations are represented with negative ones.

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 Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1

void opcontrol() {
  while (true) {
    printf("IMU get heading: %f degrees\n", imu_get_heading(IMU_PORT));
    delay(20);
  }
}

quaternion_s_t imu_get_quaternion(uint8_t port)
#include <pros/imu.h>

Get a quaternion representing the Inertial Sensor's orientation.

Parameters
port The V5 Inertial Sensor port number from 1-21
Returns The quaternion representing the sensor's orientation. If the operation failed, all the quaternion'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 Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1

void opcontrol() {
  while (true) {
    quaternion_s_t qt = imu_get_quaternion(IMU_PORT);
    printf("IMU quaternion: {x: %f, y: %f, z: %f, w: %f}\n", qt.x, qt.y, qt.z, qt.w);
    delay(20);
  }
}

euler_s_t imu_get_euler(uint8_t port)
#include <pros/imu.h>

Get the Euler angles representing the Inertial Sensor's orientation.

Parameters
port The V5 Inertial Sensor port number from 1-21
Returns The Euler angles representing the sensor's orientation. 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 Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1

void opcontrol() {
  while (true) {
    euler_s_t eu = imu_get_euler(IMU_PORT);
    printf("IMU euler angles: {pitch: %f, roll: %f, yaw: %f}\n", eu.pitch, eu.roll, eu.yaw);
    delay(20);
  }
}

imu_gyro_s_t imu_get_gyro_rate(uint8_t port)
#include <pros/imu.h>

Get the Inertial Sensor's raw gyroscope values.

Parameters
port The V5 Inertial Sensor port number from 1-21
Returns The pitch angle, or PROS_ERR_F 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 an Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1

void opcontrol() {
  while (true) {
    printf("IMU pitch: %f\n", imu_get_pitch(IMU_PORT));
    delay(20);
  }
}

imu_accel_s_t imu_get_accel(uint8_t port)
#include <pros/imu.h>

Get the Inertial Sensor's raw acceleroneter values.

Parameters
port The V5 Inertial Sensor port number from 1-21
Returns The roll angle, or PROS_ERR_F 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 an Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1

void opcontrol() {
  while (true) {
    printf("IMU roll: %f\n", imu_get_roll(IMU_PORT));
    delay(20);
  }
}

imu_status_e_t imu_get_status(uint8_t port)
#include <pros/imu.h>

Get the Inertial Sensor's status.

Parameters
port The V5 Inertial Sensor port number from 1-21
Returns The yaw angle, or PROS_ERR_F 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 an Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1

void opcontrol() {
  while (true) {
    printf("IMU yaw: %f\n", imu_get_yaw(IMU_PORT));
    delay(20);
  }
}

double imu_get_pitch(uint8_t port)
#include <pros/imu.h>

Get the Inertial Sensor's pitch angle bounded by (-180,180)

Parameters
port The V5 Inertial Sensor port number from 1-21
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 Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1

void opcontrol() {
  while (true) {
    imu_accel_s_t accel = imu_get_accel(IMU_PORT);
    printf("IMU accel values: {x: %f, y: %f, z: %f}\n", accel.x, accel.y, accel.z);
    delay(20);
  }
}

double imu_get_roll(uint8_t port)
#include <pros/imu.h>

Get the Inertial Sensor's roll angle bounded by (-180,180)

Parameters
port The V5 Inertial Sensor port number from 1-21
Returns The Inertial Sensor's status code, 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 an Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1

void initialize() {
  imu_reset(IMU_PORT);
  int time = millis();
  int iter = 0;
  while (imu_get_status(IMU_PORT) & E_IMU_STATUS_CALIBRATING) {
    printf("IMU calibrating... %d\n", iter);
    iter += 10;
    delay(10);
  }
  // should print about 2000 ms
  printf("IMU is done calibrating (took %d ms)\n", iter - time);
}

double imu_get_yaw(uint8_t port)
#include <pros/imu.h>

Get the Inertial Sensor's yaw angle bounded by (-180,180)

Parameters
port The V5 Inertial Sensor port number from 1-21
Returns The yaw angle, or PROS_ERR_F 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 an Inertial Sensor EAGAIN - The sensor is still calibrating

int32_t imu_tare_heading(uint8_t port)
#include <pros/imu.h>

Resets the current reading of the Inertial Sensor's heading to zero.

Parameters
port The V5 Inertial Sensor port number from 1-21
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 an Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1

void opcontrol() {
  while (true) {
    if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
      imu_tare_heading(IMU_PORT);
    }
  pros::delay(20);
  }
}

int32_t imu_tare_rotation(uint8_t port)
#include <pros/imu.h>

Resets the current reading of the Inertial Sensor's rotation to zero.

Parameters
port The V5 Inertial Sensor port number from 1-21
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 an Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1

void opcontrol() {
  while (true) {
    if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
      imu_tare_rotation(IMU_PORT);
    }
  pros::delay(20);
  }
}

int32_t imu_tare_pitch(uint8_t port)
#include <pros/imu.h>

Resets the current reading of the Inertial Sensor's pitch to zero.

Parameters
port The V5 Inertial Sensor port number from 1-21
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 an Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1void opcontrol() {
  while (true) {
    if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
      imu_tare_pitch(IMU_PORT);
    }
  pros::delay(20);
  }
}

int32_t imu_tare_roll(uint8_t port)
#include <pros/imu.h>

Resets the current reading of the Inertial Sensor's roll to zero.

Parameters
port The V5 Inertial Sensor port number from 1-21
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 an Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1

void opcontrol() {
  while (true) {
    if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
      imu_tare_roll(IMU_PORT);
    }
  pros::delay(20);
  }
}

int32_t imu_tare_yaw(uint8_t port)
#include <pros/imu.h>

Resets the current reading of the Inertial Sensor's yaw to zero.

Parameters
port The V5 Inertial Sensor port number from 1-21
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 an Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1

void opcontrol() {
  while (true) {
    if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
      imu_tare_yaw(IMU_PORT);
    }
  pros::delay(20);
  }
}

int32_t imu_tare_euler(uint8_t port)
#include <pros/imu.h>

Reset all 3 euler values of the Inertial Sensor to 0.

Parameters
port The V5 Inertial Sensor port number from 1-21
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 an Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1

void opcontrol() {
  while (true) {
    if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
      imu_tare_euler(IMU_PORT);
    }
  pros::delay(20);
  }
}

int32_t imu_tare(uint8_t port)
#include <pros/imu.h>

Resets all 5 values of the Inertial Sensor to 0.

Parameters
port The V5 Inertial Sensor port number from 1-21
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 an Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1

void opcontrol() {
  while (true) {
    if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
      imu_tare(IMU_PORT);
    }
  pros::delay(20);
  }
}

int32_t imu_set_euler(uint8_t port, euler_s_t target)
#include <pros/imu.h>

Sets the current reading of the Inertial Sensor's euler values to target euler values.

Parameters
port The V5 Inertial Sensor port number from 1-21
target Target euler values for the euler values to be set to
Returns The raw gyroscope values. If the operation failed, all the structure's members are filled with PROS_ERR_F and errno is set.

Will default to +/- 180 if target exceeds +/- 180.

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 Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1

void opcontrol() {
  while (true) {
    int32_t val = imu_set_euler(IMU_PORT, {45, 60, 90});
    printf("IMU : {gyro vals: %d}\n", val);
    delay(20);
  }
}

Will default to +/- 180 if target exceeds +/- 180.

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 Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1

void opcontrol() {
  while (true) {
    if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
      imu_set_euler(IMU_PORT, {45,45,45});
    }
    pros::delay(20);
  }
}

int32_t imu_set_rotation(uint8_t port, double target)
#include <pros/imu.h>

Sets the current reading of the Inertial Sensor's rotation to target value.

Parameters
port The V5 Inertial Sensor port number from 1-21
target Target value for the rotation value to be set to
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 an Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1

void opcontrol() {
  while (true) {
    if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
      imu_set_rotation(IMU_PORT, 45);
    }
    pros::delay(20);
  }
}

int32_t imu_set_heading(uint8_t port, double target)
#include <pros/imu.h>

Sets the current reading of the Inertial Sensor's heading to target value Target will default to 360 if above 360 and default to 0 if below 0.

Parameters
port The V5 Inertial Sensor port number from 1-21
target Target value for the heading value to be set to
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 an Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1

void opcontrol() {
  while (true) {
    if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
      imu_set_heading(IMU_PORT, 45);
    }
    pros::delay(20);
  }
}

int32_t imu_set_pitch(uint8_t port, double target)
#include <pros/imu.h>

Sets the current reading of the Inertial Sensor's pitch to target value Will default to +/- 180 if target exceeds +/- 180.

Parameters
port The V5 Inertial Sensor port number from 1-21
target Target value for the pitch value to be set to
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 an Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1

void opcontrol() {
  while (true) {
    if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
      imu_set_pitch(IMU_PORT, 45);
    }
    pros::delay(20);
  }
}

int32_t imu_set_roll(uint8_t port, double target)
#include <pros/imu.h>

Sets the current reading of the Inertial Sensor's roll to target value Will default to +/- 180 if target exceeds +/- 180.

Parameters
port The V5 Inertial Sensor port number from 1-21
target Target value for the roll value to be set to
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 an Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1

void opcontrol() {
  while (true) {
    if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
      imu_set_roll(IMU_PORT, 45);
    }
    pros::delay(20);
  }
}

int32_t imu_set_yaw(uint8_t port, double target)
#include <pros/imu.h>

Sets the current reading of the Inertial Sensor's yaw to target value Will default to +/- 180 if target exceeds +/- 180.

Parameters
port The V5 Inertial Sensor port number from 1-21
target Target value for the yaw value to be set to
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 an Inertial Sensor EAGAIN - The sensor is still calibrating

Example

#define IMU_PORT 1void opcontrol() {

while (true) {
  if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
    imu_set_yaw(IMU_PORT, 45);
  }
  pros::delay(20);
  }
}

imu_orientation_e_t imu_get_physical_orientation(uint8_t port)
#include <pros/imu.h>

Returns the physical orientation of the IMU.

Parameters
port The V5 Inertial Sensor port number from 1-21
Returns The orientation of the Inertial Sensor or PROS_ERR if an error occured.

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 Inertial Sensor

Enum documentation

enum imu_status_e
#include <pros/imu.h>

Enumerators
E_IMU_STATUS_READY

E_IMU_STATUS_CALIBRATING

The IMU is calibrating.

E_IMU_STATUS_ERROR

Used to indicate that an error state was reached in the imu_get_status function,\ not that the IMU is necessarily in an error state.

Typedef documentation

typedef struct imu_raw_s imu_gyro_s_t
#include <pros/imu.h>

typedef struct imu_raw_s imu_accel_s_t
#include <pros/imu.h>

Variable documentation

double x
#include <pros/imu.h>

double y
#include <pros/imu.h>

double z
#include <pros/imu.h>

Define documentation