2015-11-16 00:09:37 -04:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include "AP_InertialSensor_SITL.h"
|
|
|
|
#include <SITL/SITL.h>
|
2017-04-30 21:51:15 -03:00
|
|
|
#include <stdio.h>
|
2015-11-16 00:09:37 -04:00
|
|
|
|
2021-10-29 22:15:49 -03:00
|
|
|
#if AP_SIM_INS_ENABLED
|
2015-11-16 00:09:37 -04:00
|
|
|
|
|
|
|
const extern AP_HAL::HAL& hal;
|
|
|
|
|
2020-01-03 15:52:33 -04:00
|
|
|
AP_InertialSensor_SITL::AP_InertialSensor_SITL(AP_InertialSensor &imu, const uint16_t sample_rates[]) :
|
|
|
|
AP_InertialSensor_Backend(imu),
|
|
|
|
gyro_sample_hz(sample_rates[0]),
|
|
|
|
accel_sample_hz(sample_rates[1])
|
2015-11-16 00:09:37 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
detect the sensor
|
|
|
|
*/
|
2020-01-03 15:52:33 -04:00
|
|
|
AP_InertialSensor_Backend *AP_InertialSensor_SITL::detect(AP_InertialSensor &_imu, const uint16_t sample_rates[])
|
2015-11-16 00:09:37 -04:00
|
|
|
{
|
2020-01-03 15:52:33 -04:00
|
|
|
AP_InertialSensor_SITL *sensor = new AP_InertialSensor_SITL(_imu, sample_rates);
|
2016-10-30 02:24:21 -03:00
|
|
|
if (sensor == nullptr) {
|
|
|
|
return nullptr;
|
2015-11-16 00:09:37 -04:00
|
|
|
}
|
|
|
|
if (!sensor->init_sensor()) {
|
|
|
|
delete sensor;
|
2016-10-30 02:24:21 -03:00
|
|
|
return nullptr;
|
2015-11-16 00:09:37 -04:00
|
|
|
}
|
|
|
|
return sensor;
|
|
|
|
}
|
|
|
|
|
2018-06-15 16:05:56 -03:00
|
|
|
bool AP_InertialSensor_SITL::init_sensor(void)
|
2015-11-16 00:09:37 -04:00
|
|
|
{
|
2018-06-15 16:05:56 -03:00
|
|
|
sitl = AP::sitl();
|
2015-11-16 00:09:37 -04:00
|
|
|
if (sitl == nullptr) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-12-24 17:19:34 -04:00
|
|
|
// calculate a noisy noise component
|
|
|
|
static float calculate_noise(float noise, float noise_variation) {
|
|
|
|
return noise * (1.0f + noise_variation * rand_float());
|
|
|
|
}
|
|
|
|
|
2021-01-08 06:50:24 -04:00
|
|
|
float AP_InertialSensor_SITL::get_temperature(void)
|
|
|
|
{
|
2022-01-28 07:25:37 -04:00
|
|
|
#if HAL_INS_TEMPERATURE_CAL_ENABLE
|
2021-01-08 06:50:24 -04:00
|
|
|
if (!is_zero(sitl->imu_temp_fixed)) {
|
|
|
|
// user wants fixed temperature
|
|
|
|
return sitl->imu_temp_fixed;
|
|
|
|
}
|
2021-01-10 17:08:00 -04:00
|
|
|
uint32_t now = AP_HAL::millis();
|
|
|
|
if (temp_start_ms == 0) {
|
|
|
|
temp_start_ms = now;
|
|
|
|
}
|
2021-01-08 06:50:24 -04:00
|
|
|
// follow a curve with given start, end and time constant
|
2021-01-10 17:08:00 -04:00
|
|
|
const float tsec = (AP_HAL::millis() - temp_start_ms) * 0.001f;
|
2021-01-08 06:50:24 -04:00
|
|
|
const float T0 = sitl->imu_temp_start;
|
|
|
|
const float T1 = sitl->imu_temp_end;
|
|
|
|
const float tconst = sitl->imu_temp_tconst;
|
|
|
|
return T1 - (T1 - T0) * expf(-tsec / tconst);
|
2022-01-28 07:25:37 -04:00
|
|
|
#else
|
|
|
|
return 20.0f;
|
|
|
|
#endif
|
2021-01-08 06:50:24 -04:00
|
|
|
}
|
|
|
|
|
2017-04-30 21:51:15 -03:00
|
|
|
/*
|
|
|
|
generate an accelerometer sample
|
|
|
|
*/
|
2020-01-03 15:52:33 -04:00
|
|
|
void AP_InertialSensor_SITL::generate_accel()
|
2015-11-16 00:09:37 -04:00
|
|
|
{
|
2019-12-24 17:19:34 -04:00
|
|
|
Vector3f accel_accum;
|
2020-01-03 15:52:33 -04:00
|
|
|
uint8_t nsamples = enable_fast_sampling(accel_instance) ? 4 : 1;
|
2021-01-08 06:50:24 -04:00
|
|
|
|
2019-12-24 17:19:34 -04:00
|
|
|
for (uint8_t j = 0; j < nsamples; j++) {
|
2015-11-16 00:09:37 -04:00
|
|
|
|
2021-01-24 01:55:08 -04:00
|
|
|
Vector3f accel = Vector3f(sitl->state.xAccel,
|
|
|
|
sitl->state.yAccel,
|
|
|
|
sitl->state.zAccel);
|
|
|
|
|
|
|
|
const Vector3f &accel_trim = sitl->accel_trim.get();
|
|
|
|
if (!accel_trim.is_zero()) {
|
|
|
|
Matrix3f trim_rotation;
|
|
|
|
trim_rotation.from_euler(accel_trim.x, accel_trim.y, 0);
|
|
|
|
accel = trim_rotation.transposed() * accel;
|
|
|
|
}
|
2021-01-19 22:35:24 -04:00
|
|
|
|
|
|
|
// add scaling
|
|
|
|
Vector3f accel_scale = sitl->accel_scale[accel_instance].get();
|
|
|
|
// note that we divide so the SIM_ACC values match the
|
|
|
|
// INS_ACCSCAL values
|
|
|
|
if (!is_zero(accel_scale.x)) {
|
2021-01-24 01:55:08 -04:00
|
|
|
accel.x /= accel_scale.x;
|
2021-01-19 22:35:24 -04:00
|
|
|
}
|
|
|
|
if (!is_zero(accel_scale.y)) {
|
2021-01-24 01:55:08 -04:00
|
|
|
accel.y /= accel_scale.y;
|
2021-01-19 22:35:24 -04:00
|
|
|
}
|
|
|
|
if (!is_zero(accel_scale.z)) {
|
2021-01-24 01:55:08 -04:00
|
|
|
accel.z /= accel_scale.z;
|
2021-01-19 22:35:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// apply bias
|
2021-01-19 20:54:46 -04:00
|
|
|
const Vector3f &accel_bias = sitl->accel_bias[accel_instance].get();
|
2021-01-24 01:55:08 -04:00
|
|
|
accel += accel_bias;
|
2019-12-24 17:19:34 -04:00
|
|
|
|
|
|
|
// minimum noise levels are 2 bits, but averaged over many
|
|
|
|
// samples, giving around 0.01 m/s/s
|
|
|
|
float accel_noise = 0.01f;
|
2020-01-03 15:52:33 -04:00
|
|
|
float noise_variation = 0.05f;
|
2019-12-24 17:19:34 -04:00
|
|
|
// this smears the individual motor peaks somewhat emulating physical motors
|
2020-01-03 15:52:33 -04:00
|
|
|
float freq_variation = 0.12f;
|
2021-01-24 01:55:08 -04:00
|
|
|
|
2020-02-22 11:20:42 -04:00
|
|
|
// add in sensor noise
|
2021-01-24 18:07:16 -04:00
|
|
|
accel += Vector3f{rand_float(), rand_float(), rand_float()} * accel_noise;
|
2019-12-24 17:19:34 -04:00
|
|
|
|
|
|
|
bool motors_on = sitl->throttle > sitl->ins_noise_throttle_min;
|
2020-02-22 11:20:42 -04:00
|
|
|
|
2019-12-24 17:19:34 -04:00
|
|
|
// on a real 180mm copter gyro noise varies between 0.8-4 m/s/s for throttle 0.2-0.8
|
|
|
|
// giving a accel noise variation of 5.33 m/s/s over the full throttle range
|
|
|
|
if (motors_on) {
|
|
|
|
// add extra noise when the motors are on
|
2021-01-19 20:54:46 -04:00
|
|
|
accel_noise = sitl->accel_noise[accel_instance];
|
2019-12-24 17:19:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// VIB_FREQ is a static vibration applied to each axis
|
|
|
|
const Vector3f &vibe_freq = sitl->vibe_freq;
|
2020-02-22 11:20:42 -04:00
|
|
|
|
2019-12-24 17:19:34 -04:00
|
|
|
if (!vibe_freq.is_zero() && motors_on) {
|
2021-01-24 01:55:08 -04:00
|
|
|
accel.x += sinf(accel_time * 2 * M_PI * vibe_freq.x) * calculate_noise(accel_noise, noise_variation);
|
|
|
|
accel.y += sinf(accel_time * 2 * M_PI * vibe_freq.y) * calculate_noise(accel_noise, noise_variation);
|
|
|
|
accel.z += sinf(accel_time * 2 * M_PI * vibe_freq.z) * calculate_noise(accel_noise, noise_variation);
|
2020-01-03 15:52:33 -04:00
|
|
|
accel_time += 1.0f / (accel_sample_hz * nsamples);
|
2019-12-24 17:19:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// VIB_MOT_MAX is a rpm-scaled vibration applied to each axis
|
|
|
|
if (!is_zero(sitl->vibe_motor) && motors_on) {
|
2019-09-27 16:56:45 -03:00
|
|
|
for (uint8_t i = 0; i < sitl->state.num_motors; i++) {
|
2022-07-03 04:40:29 -03:00
|
|
|
uint32_t harmonics = uint32_t(sitl->vibe_motor_harmonics);
|
|
|
|
const float base_freq = calculate_noise(sitl->state.rpm[sitl->state.vtol_motor_start+i] / 60.0f, freq_variation);
|
|
|
|
while (harmonics != 0) {
|
|
|
|
const uint8_t bit = __builtin_ffs(harmonics);
|
|
|
|
harmonics &= ~(1U<<(bit-1U));
|
|
|
|
const float phase = accel_motor_phase[i] * float(bit);
|
|
|
|
accel.x += sinf(phase) * calculate_noise(accel_noise * sitl->vibe_motor_scale, noise_variation);
|
|
|
|
accel.y += sinf(phase) * calculate_noise(accel_noise * sitl->vibe_motor_scale, noise_variation);
|
|
|
|
accel.z += sinf(phase) * calculate_noise(accel_noise * sitl->vibe_motor_scale, noise_variation);
|
2019-09-27 16:56:45 -03:00
|
|
|
}
|
2022-07-03 04:40:29 -03:00
|
|
|
const float phase_incr = base_freq * 2 * M_PI / (accel_sample_hz * nsamples);
|
|
|
|
accel_motor_phase[i] = wrap_PI(accel_motor_phase[i] + phase_incr);
|
2019-09-27 16:56:45 -03:00
|
|
|
}
|
|
|
|
}
|
2019-12-24 17:19:34 -04:00
|
|
|
|
|
|
|
// correct for the acceleration due to the IMU position offset and angular acceleration
|
|
|
|
// correct for the centripetal acceleration
|
|
|
|
// only apply corrections to first accelerometer
|
|
|
|
Vector3f pos_offset = sitl->imu_pos_offset;
|
|
|
|
if (!pos_offset.is_zero()) {
|
|
|
|
// calculate sensed acceleration due to lever arm effect
|
|
|
|
// Note: the % operator has been overloaded to provide a cross product
|
|
|
|
Vector3f angular_accel = Vector3f(radians(sitl->state.angAccel.x), radians(sitl->state.angAccel.y), radians(sitl->state.angAccel.z));
|
|
|
|
Vector3f lever_arm_accel = angular_accel % pos_offset;
|
|
|
|
|
|
|
|
// calculate sensed acceleration due to centripetal acceleration
|
|
|
|
Vector3f angular_rate = Vector3f(radians(sitl->state.rollRate), radians(sitl->state.pitchRate), radians(sitl->state.yawRate));
|
|
|
|
Vector3f centripetal_accel = angular_rate % (angular_rate % pos_offset);
|
|
|
|
|
|
|
|
// apply corrections
|
2021-01-24 18:07:16 -04:00
|
|
|
accel += lever_arm_accel + centripetal_accel;
|
2019-09-27 16:56:45 -03:00
|
|
|
}
|
2016-10-18 17:41:26 -03:00
|
|
|
|
2021-01-19 20:54:46 -04:00
|
|
|
if (fabsf(sitl->accel_fail[accel_instance]) > 1.0e-6f) {
|
2021-01-24 01:55:08 -04:00
|
|
|
accel.x = accel.y = accel.z = sitl->accel_fail[accel_instance];
|
2019-12-24 17:19:34 -04:00
|
|
|
}
|
2015-11-16 00:09:37 -04:00
|
|
|
|
2022-01-28 07:25:37 -04:00
|
|
|
#if HAL_INS_TEMPERATURE_CAL_ENABLE
|
|
|
|
const float T = get_temperature();
|
2021-01-08 06:50:24 -04:00
|
|
|
sitl->imu_tcal[gyro_instance].sitl_apply_accel(T, accel);
|
2022-01-28 07:25:37 -04:00
|
|
|
#endif
|
2021-01-08 06:50:24 -04:00
|
|
|
|
2020-01-03 15:52:33 -04:00
|
|
|
_notify_new_accel_sensor_rate_sample(accel_instance, accel);
|
2019-01-07 16:15:02 -04:00
|
|
|
|
2019-12-24 17:19:34 -04:00
|
|
|
accel_accum += accel;
|
2019-01-07 16:15:02 -04:00
|
|
|
}
|
2019-10-08 00:32:45 -03:00
|
|
|
|
2019-12-24 17:19:34 -04:00
|
|
|
accel_accum /= nsamples;
|
2020-01-03 15:52:33 -04:00
|
|
|
_rotate_and_correct_accel(accel_instance, accel_accum);
|
2020-06-01 07:55:08 -03:00
|
|
|
_notify_new_accel_raw_sample(accel_instance, accel_accum, AP_HAL::micros64());
|
2019-12-24 17:19:34 -04:00
|
|
|
|
2021-01-08 06:50:24 -04:00
|
|
|
_publish_temperature(accel_instance, get_temperature());
|
2017-04-30 21:51:15 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
generate a gyro sample
|
|
|
|
*/
|
2020-01-03 15:52:33 -04:00
|
|
|
void AP_InertialSensor_SITL::generate_gyro()
|
2017-04-30 21:51:15 -03:00
|
|
|
{
|
2019-12-24 17:19:34 -04:00
|
|
|
Vector3f gyro_accum;
|
2020-01-03 15:52:33 -04:00
|
|
|
uint8_t nsamples = enable_fast_sampling(gyro_instance) ? 8 : 1;
|
|
|
|
|
2019-12-24 17:19:34 -04:00
|
|
|
for (uint8_t j = 0; j < nsamples; j++) {
|
|
|
|
float p = radians(sitl->state.rollRate) + gyro_drift();
|
|
|
|
float q = radians(sitl->state.pitchRate) + gyro_drift();
|
|
|
|
float r = radians(sitl->state.yawRate) + gyro_drift();
|
2015-11-16 00:09:37 -04:00
|
|
|
|
2019-12-24 17:19:34 -04:00
|
|
|
// minimum gyro noise is less than 1 bit
|
|
|
|
float gyro_noise = ToRad(0.04f);
|
|
|
|
float noise_variation = 0.05f;
|
|
|
|
// this smears the individual motor peaks somewhat emulating physical motors
|
|
|
|
float freq_variation = 0.12f;
|
2020-02-22 11:20:42 -04:00
|
|
|
// add in sensor noise
|
2019-01-07 05:32:40 -04:00
|
|
|
p += gyro_noise * rand_float();
|
|
|
|
q += gyro_noise * rand_float();
|
|
|
|
r += gyro_noise * rand_float();
|
2019-12-24 17:19:34 -04:00
|
|
|
|
|
|
|
bool motors_on = sitl->throttle > sitl->ins_noise_throttle_min;
|
|
|
|
// on a real 180mm copter gyro noise varies between 0.2-0.4 rad/s for throttle 0.2-0.8
|
|
|
|
// giving a gyro noise variation of 0.33 rad/s or 20deg/s over the full throttle range
|
|
|
|
if (motors_on) {
|
|
|
|
// add extra noise when the motors are on
|
2021-01-19 20:54:46 -04:00
|
|
|
gyro_noise = ToRad(sitl->gyro_noise[gyro_instance]) * sitl->throttle;
|
2019-12-24 17:19:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// VIB_FREQ is a static vibration applied to each axis
|
|
|
|
const Vector3f &vibe_freq = sitl->vibe_freq;
|
2020-02-22 11:20:42 -04:00
|
|
|
|
|
|
|
if (vibe_freq.is_zero() && is_zero(sitl->vibe_motor)) {
|
|
|
|
// no rpm noise, so add in background noise if any
|
|
|
|
p += gyro_noise * rand_float();
|
|
|
|
q += gyro_noise * rand_float();
|
|
|
|
r += gyro_noise * rand_float();
|
|
|
|
}
|
|
|
|
|
2019-12-24 17:19:34 -04:00
|
|
|
if (!vibe_freq.is_zero() && motors_on) {
|
2020-01-03 15:52:33 -04:00
|
|
|
p += sinf(gyro_time * 2 * M_PI * vibe_freq.x) * calculate_noise(gyro_noise, noise_variation);
|
|
|
|
q += sinf(gyro_time * 2 * M_PI * vibe_freq.y) * calculate_noise(gyro_noise, noise_variation);
|
|
|
|
r += sinf(gyro_time * 2 * M_PI * vibe_freq.z) * calculate_noise(gyro_noise, noise_variation);
|
|
|
|
gyro_time += 1.0f / (gyro_sample_hz * nsamples);
|
2019-12-24 17:19:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// VIB_MOT_MAX is a rpm-scaled vibration applied to each axis
|
|
|
|
if (!is_zero(sitl->vibe_motor) && motors_on) {
|
2019-09-27 16:56:45 -03:00
|
|
|
for (uint8_t i = 0; i < sitl->state.num_motors; i++) {
|
2022-07-03 04:40:29 -03:00
|
|
|
uint32_t harmonics = uint32_t(sitl->vibe_motor_harmonics);
|
|
|
|
const float base_freq = calculate_noise(sitl->state.rpm[sitl->state.vtol_motor_start+i] / 60.0f, freq_variation);
|
|
|
|
while (harmonics != 0) {
|
|
|
|
const uint8_t bit = __builtin_ffs(harmonics);
|
|
|
|
harmonics &= ~(1U<<(bit-1U));
|
|
|
|
const float phase = gyro_motor_phase[i] * float(bit);
|
|
|
|
p += sinf(phase) * calculate_noise(gyro_noise * sitl->vibe_motor_scale, noise_variation);
|
|
|
|
q += sinf(phase) * calculate_noise(gyro_noise * sitl->vibe_motor_scale, noise_variation);
|
|
|
|
r += sinf(phase) * calculate_noise(gyro_noise * sitl->vibe_motor_scale, noise_variation);
|
2019-09-27 16:56:45 -03:00
|
|
|
}
|
2022-07-03 04:40:29 -03:00
|
|
|
const float phase_incr = base_freq * 2 * M_PI / (gyro_sample_hz * nsamples);
|
|
|
|
gyro_motor_phase[i] = wrap_PI(gyro_motor_phase[i] + phase_incr);
|
2019-09-27 16:56:45 -03:00
|
|
|
}
|
|
|
|
}
|
2015-11-16 00:09:37 -04:00
|
|
|
|
2019-12-24 17:19:34 -04:00
|
|
|
Vector3f gyro = Vector3f(p, q, r);
|
2015-11-16 00:09:37 -04:00
|
|
|
|
2022-01-28 07:25:37 -04:00
|
|
|
#if HAL_INS_TEMPERATURE_CAL_ENABLE
|
2021-01-08 06:50:24 -04:00
|
|
|
sitl->imu_tcal[gyro_instance].sitl_apply_gyro(get_temperature(), gyro);
|
2022-01-28 07:25:37 -04:00
|
|
|
#endif
|
2021-01-08 06:50:24 -04:00
|
|
|
|
2019-12-24 17:19:34 -04:00
|
|
|
// add in gyro scaling
|
2021-01-19 20:54:46 -04:00
|
|
|
Vector3f scale = sitl->gyro_scale[gyro_instance];
|
2019-12-24 17:19:34 -04:00
|
|
|
gyro.x *= (1 + scale.x * 0.01f);
|
|
|
|
gyro.y *= (1 + scale.y * 0.01f);
|
|
|
|
gyro.z *= (1 + scale.z * 0.01f);
|
2016-01-19 00:29:08 -04:00
|
|
|
|
2019-12-24 17:19:34 -04:00
|
|
|
gyro_accum += gyro;
|
2020-01-03 15:52:33 -04:00
|
|
|
_notify_new_gyro_sensor_rate_sample(gyro_instance, gyro);
|
2019-01-07 16:15:02 -04:00
|
|
|
}
|
2019-12-24 17:19:34 -04:00
|
|
|
gyro_accum /= nsamples;
|
2020-01-03 15:52:33 -04:00
|
|
|
_rotate_and_correct_gyro(gyro_instance, gyro_accum);
|
2020-06-01 07:55:08 -03:00
|
|
|
_notify_new_gyro_raw_sample(gyro_instance, gyro_accum, AP_HAL::micros64());
|
2017-04-30 21:51:15 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void AP_InertialSensor_SITL::timer_update(void)
|
|
|
|
{
|
|
|
|
uint64_t now = AP_HAL::micros64();
|
2017-12-04 01:30:28 -04:00
|
|
|
#if 0
|
|
|
|
// insert a 1s pause in IMU data. This triggers a pause in EK2
|
|
|
|
// processing that leads to some interesting issues
|
|
|
|
if (now > 5e6 && now < 6e6) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2021-02-04 22:28:53 -04:00
|
|
|
if (sitl == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
2020-01-03 15:52:33 -04:00
|
|
|
if (now >= next_accel_sample) {
|
|
|
|
if (((1U << accel_instance) & sitl->accel_fail_mask) == 0) {
|
|
|
|
generate_accel();
|
|
|
|
if (next_accel_sample == 0) {
|
|
|
|
next_accel_sample = now + 1000000UL / accel_sample_hz;
|
|
|
|
} else {
|
|
|
|
while (now >= next_accel_sample) {
|
|
|
|
next_accel_sample += 1000000UL / accel_sample_hz;
|
2019-04-17 23:41:10 -03:00
|
|
|
}
|
2017-04-30 21:51:15 -03:00
|
|
|
}
|
|
|
|
}
|
2020-01-03 15:52:33 -04:00
|
|
|
}
|
|
|
|
if (now >= next_gyro_sample) {
|
|
|
|
if (((1U << gyro_instance) & sitl->gyro_fail_mask) == 0) {
|
|
|
|
generate_gyro();
|
|
|
|
if (next_gyro_sample == 0) {
|
|
|
|
next_gyro_sample = now + 1000000UL / gyro_sample_hz;
|
|
|
|
} else {
|
|
|
|
while (now >= next_gyro_sample) {
|
|
|
|
next_gyro_sample += 1000000UL / gyro_sample_hz;
|
2019-04-17 23:41:10 -03:00
|
|
|
}
|
2017-04-30 21:51:15 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-16 00:09:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
float AP_InertialSensor_SITL::gyro_drift(void)
|
|
|
|
{
|
2018-08-14 23:35:52 -03:00
|
|
|
if (is_zero(sitl->drift_speed) ||
|
|
|
|
is_zero(sitl->drift_time)) {
|
2015-11-16 00:09:37 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
double period = sitl->drift_time * 2;
|
2015-11-19 23:11:52 -04:00
|
|
|
double minutes = fmod(AP_HAL::micros64() / 60.0e6, period);
|
2015-11-16 00:09:37 -04:00
|
|
|
if (minutes < period/2) {
|
|
|
|
return minutes * ToRad(sitl->drift_speed);
|
|
|
|
}
|
|
|
|
return (period - minutes) * ToRad(sitl->drift_speed);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool AP_InertialSensor_SITL::update(void)
|
|
|
|
{
|
2020-01-03 15:52:33 -04:00
|
|
|
update_accel(accel_instance);
|
|
|
|
update_gyro(gyro_instance);
|
2015-11-16 00:09:37 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-03 15:52:33 -04:00
|
|
|
uint8_t AP_InertialSensor_SITL::bus_id = 0;
|
|
|
|
|
|
|
|
void AP_InertialSensor_SITL::start()
|
|
|
|
{
|
2021-03-17 22:36:41 -03:00
|
|
|
if (!_imu.register_gyro(gyro_instance, gyro_sample_hz,
|
|
|
|
AP_HAL::Device::make_bus_id(AP_HAL::Device::BUS_TYPE_SITL, bus_id, 1, DEVTYPE_SITL)) ||
|
|
|
|
!_imu.register_accel(accel_instance, accel_sample_hz,
|
|
|
|
AP_HAL::Device::make_bus_id(AP_HAL::Device::BUS_TYPE_SITL, bus_id, 2, DEVTYPE_SITL))) {
|
|
|
|
return;
|
|
|
|
}
|
2020-01-03 15:52:33 -04:00
|
|
|
bus_id++;
|
|
|
|
hal.scheduler->register_timer_process(FUNCTOR_BIND_MEMBER(&AP_InertialSensor_SITL::timer_update, void));
|
|
|
|
}
|
|
|
|
|
2021-10-29 22:15:49 -03:00
|
|
|
#endif // AP_SIM_INS_ENABLED
|