26 #if defined(__CYGWIN__) || defined(__CYGWIN64__) 55 autotest_dir(nullptr),
57 #if defined(__CYGWIN__) || defined(__CYGWIN64__)
67 ::printf(
"Failed to parse home string (%s). Should be LAT,LON,ALT,HDG e.g. 37.4003371,-122.0800351,0,353\n", home_str);
69 ::printf(
"Home: %f %f alt=%fm hdg=%f\n",
97 char *saveptr =
nullptr;
98 char *s = strdup(home_str);
101 ::printf(
"No home string supplied\n");
104 char *lat_s = strtok_r(s,
",", &saveptr);
107 ::printf(
"Failed to parse latitude\n");
110 char *lon_s = strtok_r(
nullptr,
",", &saveptr);
113 ::printf(
"Failed to parse longitude\n");
116 char *alt_s = strtok_r(
nullptr,
",", &saveptr);
119 ::printf(
"Failed to parse altitude\n");
122 char *yaw_s = strtok_r(
nullptr,
",", &saveptr);
129 memset(&loc, 0,
sizeof(loc));
130 loc.
lat =
static_cast<int32_t
>(strtof(lat_s,
nullptr) * 1.0e7f);
131 loc.
lng =
static_cast<int32_t
>(strtof(lon_s,
nullptr) * 1.0e7f);
132 loc.
alt =
static_cast<int32_t
>(strtof(alt_s,
nullptr) * 1.0e2f);
134 if (loc.
lat == 0 && loc.
lng == 0) {
137 loc.
lat = -35.363261*1e7;
138 loc.
lng = 149.165230*1e7;
142 yaw_degrees = strtof(yaw_s,
nullptr);
191 DataFlash_Class::instance()->
Log_Write(
"SITL",
"TimeUS,VN,VE,VD,AN,AE,AD,PN,PE,PD",
"Qfffffffff",
194 accel_ef.
x, accel_ef.
y, accel_ef.
z,
211 Vector3f mag_ef(1e3f * intensity, 0.0
f, 0.0
f);
222 anomaly_scaler = anomaly_scaler * anomaly_scaler * anomaly_scaler;
290 ::printf(
"achieved_rate_hz=%.3f rate=%.2f rate_hz=%.3f sft=%.1f\n",
292 static_cast<double>(rate),
323 static double n2 = 0.0;
324 static int n2_cached = 0;
329 x = 2.0 * rand()/RAND_MAX - 1;
330 y = 2.0 * rand()/RAND_MAX - 1;
332 }
while (
is_zero(r) || r > 1.0);
333 const double d = sqrt(-2.0 * log(r)/r);
334 const double n1 = x * d;
336 const double result = n1 * stddev + mean;
341 return n2 * stddev + mean;
433 #if defined(__CYGWIN__) || defined(__CYGWIN64__) 435 static uint64_t last_ret_us;
437 tPrev = timeGetTime();
440 DWORD now = timeGetTime();
441 last_ret_us += (uint64_t)((now - tPrev)*1000UL);
446 gettimeofday(&tp,
nullptr);
447 return static_cast<uint64_t
>(tp.tv_sec * 1.0e6 + tp.tv_usec);
467 gyro += rot_accel * delta_time;
587 const float iir_coef = 0.98f;
594 static_cast<float>(turbulence_horizontal_speed * iir_coef+wind_turb *
rand_normal(0, 1) * (1 - iir_coef));
620 printf(
"Smoothing reset at %.3f\n", now * 1.0e-6
f);
623 const float delta_time = (now -
smoothing.last_update_us) * 1.0e-6
f;
624 if (delta_time < 0 || delta_time > 0.1) {
629 const float time_constant = 0.1f;
644 error_q = desired_q / current_q;
652 smoothing.rotation_b2e.to_euler(&R, &P, &Y);
657 DataFlash_Class::instance()->
Log_Write(
"SMOO",
"TimeUS,AEx,AEy,AEz,DPx,DPy,DPz,R,P,Y,R2,P2,Y2",
663 delta_pos.
x, delta_pos.
y, delta_pos.
z,
674 smoothing.velocity_ef += accel_e * delta_time;
706 const float v = (input.
servos[idx] - 1500)/500.0
f;
716 const float v = (input.
servos[idx] - 1000)/1000.0
f;
void to_euler(float *roll, float *pitch, float *yaw) const
AP_Vector3f mag_anomaly_ned
int printf(const char *fmt,...)
static AP_Param * find_object(const char *name)
Aircraft(const char *home_str, const char *frame_str)
void sync_frame_time(void)
struct SITL::Aircraft::@200 smoothing
void update_wind(const struct sitl_input &input)
LowPassFilterFloat servo_filter[4]
Vector3< float > Vector3f
float filtered_idx(float v, uint8_t idx)
void to_axis_angle(Vector3f &v)
float turbulence_horizontal_speed
void add_noise(float throttle)
void set_speedup(float speedup)
void setup_frame_time(float rate, float speedup)
float filtered_servo_range(const struct sitl_input &input, uint8_t idx)
const uint32_t min_sleep_time
static AP_Param * find(const char *name, enum ap_var_type *ptype)
void from_euler(float roll, float pitch, float yaw)
float turbulence_vertical_speed
void location_offset(struct Location &loc, float ofs_north, float ofs_east)
void from_rotation_matrix(const Matrix3f &m)
int32_t lat
param 3 - Latitude * 10**7
uint64_t get_wall_time_us(void) const
void set_cutoff_frequency(float cutoff_freq)
float ground_height_difference() const
virtual bool on_ground() const
A system for managing and storing variables that are of general interest to the system.
static double rand_normal(double mean, double stddev)
Matrix3< T > transposed(void) const
AP_Int8 * ahrs_orientation
uint32_t last_ground_contact_ms
int32_t alt
param 2 - Altitude in centimeters (meters * 100) see LOCATION_ALT_MAX_M
void Log_Write(const char *name, const char *labels, const char *fmt,...)
bool is_zero(const T fVal1)
static DataFlash_Class * instance(void)
void from_rotation(enum Rotation rotation)
static bool parse_home(const char *home_str, Location &loc, float &yaw_degrees)
void adjust_frame_time(float rate)
void update_mag_field_bf(void)
float constrain_float(const float amt, const float low, const float high)
void smooth_sensors(void)
void update_position(void)
int32_t lng
param 4 - Longitude * 10**7
static bool get_mag_field_ef(float latitude_deg, float longitude_deg, float &intensity_gauss, float &declination_deg, float &inclination_deg)
static constexpr float radians(float deg)
void extrapolate_sensors(float delta_time)
void update_dynamics(const Vector3f &rot_accel)
float scaled_frame_time_us
uint64_t last_wall_time_us
void rotate(const Vector3< T > &g)
void fill_fdm(struct sitl_fdm &fdm)
enum SITL::Aircraft::@199 ground_behavior
float filtered_servo_angle(const struct sitl_input &input, uint8_t idx)
T apply(T sample, float dt)