Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
bmi088.hpp
Go to the documentation of this file.
1/*****************************************************************************/
2/********** !!! WARNING: CODE GENERATED BY TAPROOT. DO NOT EDIT !!! **********/
3/*****************************************************************************/
4
5/*
6 * Copyright (c) 2020-2022 Advanced Robotics at the University of Washington <robomstr@uw.edu>
7 *
8 * This file is part of Taproot.
9 *
10 * Taproot is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Taproot is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Taproot. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef TAPROOT_BMI088_HPP_
25#define TAPROOT_BMI088_HPP_
26
32#include "tap/util_macros.hpp"
33
34#include "bmi088_data.hpp"
35
36namespace tap
37{
38class Drivers;
39}
41{
57class Bmi088 final_mockable : public Bmi088Data, public AbstractIMU
58{
59public:
62 mockable ~Bmi088() = default;
63
64 static constexpr Acc::AccRange_t ACC_RANGE = Acc::AccRange::G3;
65 static constexpr Gyro::GyroRange_t GYRO_RANGE = Gyro::GyroRange::DPS2000;
70 static constexpr float GYRO_RANGE_MAX_RAD_PER_S = modm::toRadian(2000.0f);
71
72 static constexpr float BMI088_TEMP_FACTOR = 0.125f;
73 static constexpr float BMI088_TEMP_OFFSET = 23.0f;
74
79 static constexpr float GYRO_RAD_PER_S_PER_GYRO_COUNT = GYRO_RANGE_MAX_RAD_PER_S / 32767.0f;
80
85 static constexpr float ACC_G_PER_ACC_COUNT =
86 modm::pow(2, ACC_RANGE.value + 1) * 1.5f * tap::algorithms::ACCELERATION_GRAVITY / 32768.0f;
87
91 mockable void initialize(float sampleFrequency, float mahonyKp, float mahonyKi) override;
92
97 mockable void periodicIMUUpdate() override;
98
104 mockable bool read();
105
106 inline const char *getName() const final_mockable { return "bmi088"; }
107
108 inline void setAccOversampling(Acc::AccBandwidth oversampling)
109 {
110 accOversampling = oversampling;
111 }
112 inline void setAccOutputRate(Acc::AccOutputRate outputRate) { accOutputRate = outputRate; }
113
114 inline void setGyroOutputRate(Gyro::GyroBandwidth outputRate) { gyroOutputRate = outputRate; }
115
116 inline void setTargetTemperature(float temperatureC)
117 {
118 imuHeater.setDesiredTemperature(temperatureC);
119 }
120
121private:
123
124 inline float getAccelerationSensitivity() const override { return ACC_G_PER_ACC_COUNT; }
125
126 static constexpr uint16_t RAW_TEMPERATURE_TO_APPLY_OFFSET = 1023;
128 static constexpr int16_t RAW_TEMPERATURE_OFFSET = -2048;
129
130 imu_heater::ImuHeater imuHeater;
131
132 Acc::AccBandwidth accOversampling = Acc::AccBandwidth::NORMAL;
133 Acc::AccOutputRate accOutputRate = Acc::AccOutputRate::Hz800;
134
135 void initializeAcc();
136
137 Gyro::GyroBandwidth gyroOutputRate = Gyro::GyroBandwidth::ODR1000_BANDWIDTH116;
138 void initializeGyro();
139
140 void setAndCheckAccRegister(Acc::Register reg, Acc::Registers_t value);
141
142 void setAndCheckGyroRegister(Gyro::Register reg, Gyro::Registers_t value);
143
151 static inline float parseTemp(uint8_t tempMsb, uint8_t tempLsb)
152 {
153 uint16_t temp =
154 (static_cast<uint16_t>(tempMsb) * 8) + (static_cast<uint16_t>(tempLsb) / 32);
155
156 int16_t shiftedTemp = static_cast<int16_t>(temp);
157
158 if (temp > RAW_TEMPERATURE_TO_APPLY_OFFSET)
159 {
160 shiftedTemp += RAW_TEMPERATURE_OFFSET;
161 }
162
163 return static_cast<float>(shiftedTemp) * BMI088_TEMP_FACTOR + BMI088_TEMP_OFFSET;
164 }
165};
166
167} // namespace tap::communication::sensors::imu::bmi088
168
169#endif // TAPROOT_BMI088_HPP_
Definition drivers.hpp:70
Definition abstract_imu.hpp:45
void setAccOversampling(Acc::AccBandwidth oversampling)
Definition bmi088.hpp:108
void setGyroOutputRate(Gyro::GyroBandwidth outputRate)
Definition bmi088.hpp:114
void setTargetTemperature(float temperatureC)
Definition bmi088.hpp:116
Bmi088(Drivers *drivers)
Definition bmi088.hpp:60
void setAccOutputRate(Acc::AccOutputRate outputRate)
Definition bmi088.hpp:112
Definition can.hpp:32
Definition ballistics.cpp:29
tap::Drivers Drivers
Definition drivers.hpp:11
fang::Drivers & drivers
Definition robot_singleton.cpp:45
#define mockable
Wrap class functions that are not already virtual in this function if you wish to mock them.
Definition util_macros.hpp:38
#define DISALLOW_COPY_AND_ASSIGN(Typename)
Definition util_macros.hpp:27