Class final_mockable
Defined in File mpu6500.hpp
Nested Relationships
Nested Types
Inheritance Relationships
Base Types
public modm::pt::Protothread
public tap::communication::sensors::imu::ImuInterface
(Class ImuInterface)
Class Documentation
-
class final_mockable : public modm::pt::Protothread, public tap::communication::sensors::imu::ImuInterface
A class specifically designed for interfacing with the RoboMaster type A board Mpu6500.
To use this class, call Remote::init() to properly initialize and calibrate the MPU6500. Next, call Remote::read() to read acceleration, gyro, and temperature values from the imu. Use the getter methods to access imu information.
Note
if you are shaking the imu while it is initializing, the offsets will likely be calibrated poorly and unexpectedly bad results may occur.
Public Types
-
using ProcessRawMpu6500DataFn = void (*)(const uint8_t (&)[ACC_GYRO_TEMPERATURE_BUFF_RX_SIZE], modm::Vector3f &accel, modm::Vector3f &gyro)
Public Functions
-
Mpu6500(Drivers *drivers)
-
~Mpu6500() = default
-
void init(float sampleFrequency, float mahonyKp, float mahonyKi)
Initialize the imu and the SPI line. Uses SPI1, which is internal to the type A board.
Note
this function can block for approximately 12 seconds.
-
void periodicIMUUpdate()
Calculates the IMU’s pitch, roll, and yaw angles usign the Mahony AHRS algorithm. Also runs a controller to keep the temperature constant. Call at 500 hz for best performance.
-
bool read()
Read data from the imu. This is a protothread that reads the SPI bus using nonblocking I/O.
- Returns:
true
if the function is not done,false
otherwise
-
inline bool run()
-
inline ImuState getImuState() const
Returns the state of the IMU. Can be not connected, connected but not calibrated, calibrating or calibrated. When not connected, IMU data is undefiend. When not calibrated, IMU data is valid but the computed yaw angle data will drift. When calibrating, the IMU data is invalid. When calibrated, the IMU data is valid and assuming proper calibration the IMU data should not drift.
To be safe, whenever you call functions that return IMU (acceleration, gyroscope, temperature, and angle) data, call this function to ensure the data you are about to receive is not undefined.
-
inline virtual const char *getName() const
-
inline float validateReading(float reading)
If the imu is not initialized, logs an error and returns 0. Otherwise, returns the value passed in.
- inline virtual float getAx () final _mockable
Returns the acceleration reading in the x direction, in \(\frac{\mbox{m}}{\mbox{second}^2}\).
- inline virtual float getAy () final _mockable
Returns the acceleration reading in the y direction, in \(\frac{\mbox{m}}{\mbox{second}^2}\).
- inline virtual float getAz () final _mockable
Returns the acceleration reading in the z direction, in \(\frac{\mbox{m}}{\mbox{second}^2}\).
- inline virtual float getGx () final _mockable
Returns the gyroscope reading in the x direction, in \(\frac{\mbox{degrees}}{\mbox{second}}\).
- inline virtual float getGy () final _mockable
Returns the gyroscope reading in the y direction, in \(\frac{\mbox{degrees}}{\mbox{second}}\).
- inline virtual float getGz () final _mockable
Returns the gyroscope reading in the z direction, in \(\frac{\mbox{degrees}}{\mbox{second}}\).
- inline virtual float getTemp () final _mockable
Returns the temperature of the imu in degrees C.
See also
page 33 of this datasheet: https://3cfeqx1hf82y3xcoull08ihx-wpengine.netdna-ssl.com/wp-content/uploads/2015/02/MPU-6500-Register-Map2.pdf for what the magic numbers are used.
- inline virtual float getYaw () final _mockable
Returns yaw angle. in degrees.
- inline virtual float getPitch () final _mockable
Returns pitch angle in degrees.
- inline virtual float getRoll () final _mockable
Returns roll angle in degrees.
-
inline uint32_t getPrevIMUDataReceivedTime() const
-
float getTiltAngle()
Returns the angle difference between the normal vector of the plane that the type A board lies on and of the angle directly upward.
-
void requestCalibration()
Uninitializes the mpu6500 and enters calibration mode.
-
inline void attachProcessRawMpu6500DataFn(ProcessRawMpu6500DataFn fn)
-
inline void setCalibrationSamples(float samples)
-
inline void setTargetTemperature(float temperatureC)
Public Static Attributes
-
static uint8_t ACC_GYRO_TEMPERATURE_BUFF_RX_SIZE = 14
The number of bytes read to read acceleration, gyro, and temperature.
-
static float LSB_D_PER_S_TO_D_PER_S = 16.384f
Use for converting from gyro values we receive to more conventional degrees / second.
-
struct RawData
Storage for the raw data we receive from the mpu6500, as well as offsets that are used each time we receive data.
-
using ProcessRawMpu6500DataFn = void (*)(const uint8_t (&)[ACC_GYRO_TEMPERATURE_BUFF_RX_SIZE], modm::Vector3f &accel, modm::Vector3f &gyro)