WPILibC++ 2024.1.1-beta-4
frc::ADIS16470_IMU Class Reference

Use DMA SPI to read rate and acceleration data from the ADIS16470 IMU and return the robot's heading relative to a starting position and instant measurements. More...

#include <frc/ADIS16470_IMU.h>

Inheritance diagram for frc::ADIS16470_IMU:
wpi::Sendable wpi::SendableHelper< ADIS16470_IMU >

Public Types

enum class  CalibrationTime {
  _32ms = 0 , _64ms = 1 , _128ms = 2 , _256ms = 3 ,
  _512ms = 4 , _1s = 5 , _2s = 6 , _4s = 7 ,
  _8s = 8 , _16s = 9 , _32s = 10 , _64s = 11
}
 
enum  IMUAxis { kX , kY , kZ }
 

Public Member Functions

 ADIS16470_IMU ()
 Default constructor. More...
 
 ADIS16470_IMU (IMUAxis yaw_axis, SPI::Port port, CalibrationTime cal_time)
 Customizable constructor. More...
 
 ~ADIS16470_IMU () override
 Destructor. More...
 
 ADIS16470_IMU (ADIS16470_IMU &&)=default
 
ADIS16470_IMUoperator= (ADIS16470_IMU &&)=default
 
int ConfigDecRate (uint16_t reg)
 
void Calibrate ()
 Switches the active SPI port to standard SPI mode, writes the command to activate the new null configuration, and re-enables auto SPI. More...
 
int ConfigCalTime (CalibrationTime new_cal_time)
 Switches the active SPI port to standard SPI mode, writes a new value to the NULL_CNFG register in the IMU, and re-enables auto SPI. More...
 
void Reset ()
 Resets (zeros) the xgyro, ygyro, and zgyro angle integrations. More...
 
units::degree_t GetAngle () const
 Returns the yaw axis angle in degrees (CCW positive). More...
 
units::degrees_per_second_t GetRate () const
 Returns the yaw axis angular rate in degrees per second (CCW positive). More...
 
units::meters_per_second_squared_t GetAccelX () const
 Returns the acceleration in the X axis. More...
 
units::meters_per_second_squared_t GetAccelY () const
 Returns the acceleration in the Y axis. More...
 
units::meters_per_second_squared_t GetAccelZ () const
 Returns the acceleration in the Z axis. More...
 
units::degree_t GetXComplementaryAngle () const
 
units::degree_t GetYComplementaryAngle () const
 
units::degree_t GetXFilteredAccelAngle () const
 
units::degree_t GetYFilteredAccelAngle () const
 
IMUAxis GetYawAxis () const
 
int SetYawAxis (IMUAxis yaw_axis)
 
bool IsConnected () const
 
int GetPort () const
 Get the SPI port number. More...
 
void InitSendable (wpi::SendableBuilder &builder) override
 Initializes this Sendable object. More...
 
- Public Member Functions inherited from wpi::Sendable
virtual ~Sendable ()=default
 
virtual void InitSendable (SendableBuilder &builder)=0
 Initializes this Sendable object. More...
 
- Public Member Functions inherited from wpi::SendableHelper< ADIS16470_IMU >
 SendableHelper (const SendableHelper &rhs)=default
 
 SendableHelper (SendableHelper &&rhs)
 
SendableHelperoperator= (const SendableHelper &rhs)=default
 
SendableHelperoperator= (SendableHelper &&rhs)
 

Public Attributes

IMUAxis m_yaw_axis
 

Additional Inherited Members

- Protected Member Functions inherited from wpi::SendableHelper< ADIS16470_IMU >
 SendableHelper ()=default
 
 ~SendableHelper ()
 

Detailed Description

Use DMA SPI to read rate and acceleration data from the ADIS16470 IMU and return the robot's heading relative to a starting position and instant measurements.

The ADIS16470 gyro angle outputs track the robot's heading based on the starting position. As the robot rotates the new heading is computed by integrating the rate of rotation returned by the IMU. When the class is instantiated, a short calibration routine is performed where the IMU samples the gyros while at rest to determine the initial offset. This is subtracted from each sample to determine the heading.

This class is for the ADIS16470 IMU connected via the primary SPI port available on the RoboRIO.

Member Enumeration Documentation

◆ CalibrationTime

Enumerator
_32ms 
_64ms 
_128ms 
_256ms 
_512ms 
_1s 
_2s 
_4s 
_8s 
_16s 
_32s 
_64s 

◆ IMUAxis

Enumerator
kX 
kY 
kZ 

Constructor & Destructor Documentation

◆ ADIS16470_IMU() [1/3]

frc::ADIS16470_IMU::ADIS16470_IMU ( )

Default constructor.

Uses CS0 on the 10-pin SPI port, the yaw axis is set to the IMU Z axis, and calibration time is defaulted to 4 seconds.

◆ ADIS16470_IMU() [2/3]

frc::ADIS16470_IMU::ADIS16470_IMU ( IMUAxis  yaw_axis,
SPI::Port  port,
CalibrationTime  cal_time 
)
explicit

Customizable constructor.

Allows the SPI port and CS to be customized, the yaw axis used for GetAngle() is adjustable, and initial calibration time can be modified.

Parameters
yaw_axisSelects the "default" axis to use for GetAngle() and GetRate()
portThe SPI port and CS where the IMU is connected.
cal_timeThe calibration time that should be used on start-up.

◆ ~ADIS16470_IMU()

frc::ADIS16470_IMU::~ADIS16470_IMU ( )
override

Destructor.

Kills the acquisition loop and closes the SPI peripheral.

◆ ADIS16470_IMU() [3/3]

frc::ADIS16470_IMU::ADIS16470_IMU ( ADIS16470_IMU &&  )
default

Member Function Documentation

◆ Calibrate()

void frc::ADIS16470_IMU::Calibrate ( )

Switches the active SPI port to standard SPI mode, writes the command to activate the new null configuration, and re-enables auto SPI.

◆ ConfigCalTime()

int frc::ADIS16470_IMU::ConfigCalTime ( CalibrationTime  new_cal_time)

Switches the active SPI port to standard SPI mode, writes a new value to the NULL_CNFG register in the IMU, and re-enables auto SPI.

◆ ConfigDecRate()

int frc::ADIS16470_IMU::ConfigDecRate ( uint16_t  reg)

◆ GetAccelX()

units::meters_per_second_squared_t frc::ADIS16470_IMU::GetAccelX ( ) const

Returns the acceleration in the X axis.

◆ GetAccelY()

units::meters_per_second_squared_t frc::ADIS16470_IMU::GetAccelY ( ) const

Returns the acceleration in the Y axis.

◆ GetAccelZ()

units::meters_per_second_squared_t frc::ADIS16470_IMU::GetAccelZ ( ) const

Returns the acceleration in the Z axis.

◆ GetAngle()

units::degree_t frc::ADIS16470_IMU::GetAngle ( ) const

Returns the yaw axis angle in degrees (CCW positive).

◆ GetPort()

int frc::ADIS16470_IMU::GetPort ( ) const

Get the SPI port number.

Returns
The SPI port number.

◆ GetRate()

units::degrees_per_second_t frc::ADIS16470_IMU::GetRate ( ) const

Returns the yaw axis angular rate in degrees per second (CCW positive).

◆ GetXComplementaryAngle()

units::degree_t frc::ADIS16470_IMU::GetXComplementaryAngle ( ) const

◆ GetXFilteredAccelAngle()

units::degree_t frc::ADIS16470_IMU::GetXFilteredAccelAngle ( ) const

◆ GetYawAxis()

IMUAxis frc::ADIS16470_IMU::GetYawAxis ( ) const

◆ GetYComplementaryAngle()

units::degree_t frc::ADIS16470_IMU::GetYComplementaryAngle ( ) const

◆ GetYFilteredAccelAngle()

units::degree_t frc::ADIS16470_IMU::GetYFilteredAccelAngle ( ) const

◆ InitSendable()

void frc::ADIS16470_IMU::InitSendable ( wpi::SendableBuilder builder)
overridevirtual

Initializes this Sendable object.

Parameters
buildersendable builder

Implements wpi::Sendable.

◆ IsConnected()

bool frc::ADIS16470_IMU::IsConnected ( ) const

◆ operator=()

ADIS16470_IMU & frc::ADIS16470_IMU::operator= ( ADIS16470_IMU &&  )
default

◆ Reset()

void frc::ADIS16470_IMU::Reset ( )

Resets (zeros) the xgyro, ygyro, and zgyro angle integrations.

Resets the gyro accumulations to a heading of zero. This can be used if the "zero" orientation of the sensor needs to be changed in runtime.

◆ SetYawAxis()

int frc::ADIS16470_IMU::SetYawAxis ( IMUAxis  yaw_axis)

Member Data Documentation

◆ m_yaw_axis

IMUAxis frc::ADIS16470_IMU::m_yaw_axis

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