LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
Loading...
Searching...
No Matches
okapi::IMU Class Reference

#include <IMU.hpp>

Inheritance diagram for okapi::IMU:
okapi::ContinuousRotarySensor okapi::RotarySensor okapi::ControllerInput< double >

Public Member Functions

 IMU (std::uint8_t iport, IMUAxes iaxis=IMUAxes::z)
 An inertial sensor on the given port.
 
double get () const override
 Get the current rotation about the configured axis.
 
double getRemapped (double iupperBound=1800, double ilowerBound=-1800) const
 Get the current sensor value remapped into the target range ([-1800, 1800] by default).
 
double getAcceleration () const
 Get the current acceleration along the configured axis.
 
std::int32_t reset () override
 Reset the rotation value to zero.
 
std::int32_t reset (double inewAngle)
 Resets rotation value to desired value For example, reset(0) will reset the sensor to zero.
 
std::int32_t calibrate ()
 Calibrate the IMU.
 
double controllerGet () override
 Get the sensor value for use in a control loop.
 
bool isCalibrating () const
 
- Public Member Functions inherited from okapi::RotarySensor
virtual ~RotarySensor ()
 

Protected Member Functions

double readAngle () const
 Get the current rotation about the configured axis.
 

Protected Attributes

std::uint8_t port
 
IMUAxes axis
 
double offset = 0
 

Detailed Description

Definition at line 19 of file IMU.hpp.

Constructor & Destructor Documentation

◆ IMU()

okapi::IMU::IMU ( std::uint8_t  iport,
IMUAxes  iaxis = IMUAxes::z 
)

An inertial sensor on the given port.

The IMU returns an angle about the selected axis in degrees.

auto imuZ = IMU(1);
auto imuX = IMU(1, IMUAxes::x);
@ x
Roll Axis.
Parameters
iportThe port number in the range [1, 21].
iaxisThe axis of the inertial sensor to measure, default IMUAxes::z.

Member Function Documentation

◆ calibrate()

std::int32_t okapi::IMU::calibrate ( )

Calibrate the IMU.

Resets the rotation value to zero. Calibration is expected to take two seconds, but is bounded to five seconds.

Returns
1 or PROS_ERR.

◆ controllerGet()

double okapi::IMU::controllerGet ( )
overridevirtual

Get the sensor value for use in a control loop.

This method might be automatically called in another thread by the controller.

Returns
The current sensor value or PROS_ERR.

Implements okapi::ControllerInput< double >.

◆ get()

double okapi::IMU::get ( ) const
overridevirtual

Get the current rotation about the configured axis.

Returns
The current sensor value or PROS_ERR.

Implements okapi::RotarySensor.

◆ getAcceleration()

double okapi::IMU::getAcceleration ( ) const

Get the current acceleration along the configured axis.

Returns
The current sensor value or PROS_ERR.

◆ getRemapped()

double okapi::IMU::getRemapped ( double  iupperBound = 1800,
double  ilowerBound = -1800 
) const

Get the current sensor value remapped into the target range ([-1800, 1800] by default).

Parameters
iupperBoundThe upper bound of the range.
ilowerBoundThe lower bound of the range.
Returns
The remapped sensor value.

◆ isCalibrating()

bool okapi::IMU::isCalibrating ( ) const
Returns
Whether the IMU is calibrating.

◆ readAngle()

double okapi::IMU::readAngle ( ) const
protected

Get the current rotation about the configured axis.

The internal offset is not accounted for or modified. This just reads from the sensor.

Returns
The current sensor value or PROS_ERR.

◆ reset() [1/2]

std::int32_t okapi::IMU::reset ( )
overridevirtual

Reset the rotation value to zero.

Returns
1 or PROS_ERR.

Implements okapi::ContinuousRotarySensor.

◆ reset() [2/2]

std::int32_t okapi::IMU::reset ( double  inewAngle)

Resets rotation value to desired value For example, reset(0) will reset the sensor to zero.

But reset(90) will reset the sensor to 90 degrees.

Parameters
inewAngledesired reset value
Returns
1 or PROS_ERR.

Member Data Documentation

◆ axis

IMUAxes okapi::IMU::axis
protected

Definition at line 98 of file IMU.hpp.

◆ offset

double okapi::IMU::offset = 0
protected

Definition at line 99 of file IMU.hpp.

◆ port

std::uint8_t okapi::IMU::port
protected

Definition at line 97 of file IMU.hpp.


The documentation for this class was generated from the following file: