33 #ifndef ROSFLIGHT_FIRMWARE_SENSORS_H 34 #define ROSFLIGHT_FIRMWARE_SENSORS_H 131 float imu_temperature = 0;
132 uint64_t imu_time = 0;
134 float diff_pressure_velocity = 0;
135 float diff_pressure = 0;
136 float diff_pressure_temp = 0;
137 bool diff_pressure_valid =
false;
139 float baro_altitude = 0;
140 float baro_pressure = 0;
141 float baro_temperature = 0;
142 bool baro_valid =
false;
144 float sonar_range = 0;
145 bool sonar_range_valid =
false;
148 bool gnss_new_data =
false;
150 bool gnss_present =
false;
158 bool diff_pressure_present =
false;
160 bool battery_monitor_present =
false;
161 float battery_voltage = 0;
162 float battery_current = 0;
173 void param_change_callback(uint16_t param_id)
override;
176 bool start_imu_calibration(
void);
177 bool start_gyro_calibration(
void);
178 bool start_baro_calibration(
void);
179 bool start_diff_pressure_calibration(
void);
180 bool gyro_calibration_complete(
void);
187 imu_data_sent_ =
true;
202 static constexpr uint32_t BATTERY_MONITOR_UPDATE_PERIOD_MS = 10;
214 void init(
float max_change_rate,
float update_rate,
float center);
215 bool update(
float new_val,
float *val);
226 NUM_LOW_PRIORITY_SENSORS
233 float accel_[3] = {0, 0, 0};
234 float gyro_[3] = {0, 0, 0};
236 bool calibrating_acc_flag_ =
false;
237 bool calibrating_gyro_flag_ =
false;
238 uint8_t next_sensor_to_update_ = BAROMETER;
240 void calibrate_accel(
void);
241 void calibrate_gyro(
void);
242 void calibrate_baro(
void);
243 void calibrate_diff_pressure(
void);
244 void correct_imu(
void);
245 void correct_mag(
void);
246 void correct_baro(
void);
247 void correct_diff_pressure(
void);
248 bool update_imu(
void);
249 void update_battery_monitor(
void);
250 void update_other_sensors(
void);
251 void look_for_disabled_sensors(
void);
252 void update_battery_monitor_multipliers(
void);
253 uint32_t last_time_look_for_disarmed_sensors_ = 0;
254 uint32_t last_imu_update_ms_ = 0;
260 uint16_t gyro_calibration_count_ = 0;
262 uint16_t accel_calibration_count_ = 0;
265 float acc_temp_sum_ = 0.0f;
276 bool baro_calibrated_ =
false;
277 float ground_pressure_ = 0.0f;
278 uint16_t baro_calibration_count_ = 0;
279 uint32_t last_baro_cal_iter_ms_ = 0;
280 float baro_calibration_mean_ = 0.0f;
281 float baro_calibration_var_ = 0.0f;
284 bool diff_pressure_calibrated_ =
false;
285 uint16_t diff_pressure_calibration_count_ = 0;
286 uint32_t last_diff_pressure_cal_iter_ms_ = 0;
287 float diff_pressure_calibration_mean_ = 0.0f;
288 float diff_pressure_calibration_var_ = 0.0f;
295 uint32_t last_battery_monitor_update_ms_ = 0;
297 float battery_voltage_alpha_{0.995};
298 float battery_current_alpha_{0.995};
303 #endif // ROSFLIGHT_FIRMWARE_SENSORS_H
uint64_t rosflight_timestamp
static volatile int16_t gyro[3]
static const float DIFF_SAMPLE_RATE
static const float SONAR_SAMPLE_RATE
static const float DIFF_MAX_CHANGE_RATE
void init(const M_string &remappings)
static const float BARO_MAX_CALIBRATION_VARIANCE
OutlierFilter baro_outlier_filt_
static const float DIFF_PRESSURE_MAX_CALIBRATION_VARIANCE
OutlierFilter diff_outlier_filt_
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
uint64_t prev_imu_read_time_us_
static volatile int16_t accel[3]
static const float BARO_SAMPLE_RATE
static const int SENSOR_CAL_CYCLES
bool should_send_imu_data(void)
static const float BARO_MAX_CHANGE_RATE
turbomath::Vector accel_int_
static volatile float data_[3]
turbomath::Vector gyro_int_
uint64_t rosflight_timestamp
static const float SONAR_MAX_CHANGE_RATE
const Data & data() const
static const int SENSOR_CAL_DELAY_CYCLES
OutlierFilter sonar_outlier_filt_