123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- #pragma once
- #include <AP_Math/AP_Math.h>
- #include "SITL.h"
- #include "SITL_Input.h"
- #include <AP_Terrain/AP_Terrain.h>
- #include "SIM_Sprayer.h"
- #include "SIM_Gripper_Servo.h"
- #include "SIM_Gripper_EPM.h"
- #include "SIM_Parachute.h"
- #include "SIM_Precland.h"
- #include <Filter/Filter.h>
- namespace SITL {
- class Aircraft {
- public:
- Aircraft(const char *frame_str);
-
- virtual void set_start_location(const Location &start_loc, const float start_yaw);
-
- void set_speedup(float speedup);
-
- void set_instance(uint8_t _instance) {
- instance = _instance;
- }
-
- void set_autotest_dir(const char *_autotest_dir) {
- autotest_dir = _autotest_dir;
- }
-
- virtual void set_interface_ports(const char* address, const int port_in, const int port_out) {};
-
- virtual void update(const struct sitl_input &input) = 0;
- void update_model(const struct sitl_input &input);
-
- void fill_fdm(struct sitl_fdm &fdm);
-
- void smooth_sensors(void);
-
- static double rand_normal(double mean, double stddev);
-
- float get_rate_hz(void) const { return rate_hz; }
- const Vector3f &get_gyro(void) const {
- return gyro;
- }
- const Vector3f &get_velocity_ef(void) const {
- return velocity_ef;
- }
- const Vector3f &get_velocity_air_ef(void) const {
- return velocity_air_ef;
- }
- const Matrix3f &get_dcm(void) const {
- return dcm;
- }
- const Vector3f &get_mag_field_bf(void) const {
- return mag_bf;
- }
- float gross_mass() const { return mass + external_payload_mass; }
- virtual void set_config(const char* config) {
- config_ = config;
- }
- const Location &get_location() const { return location; }
- const Vector3f &get_position() const { return position; }
- void get_attitude(Quaternion &attitude) const {
- attitude.from_rotation_matrix(dcm);
- }
- const Location &get_home() const { return home; }
- float get_home_yaw() const { return home_yaw; }
- void set_sprayer(Sprayer *_sprayer) { sprayer = _sprayer; }
- void set_parachute(Parachute *_parachute) { parachute = _parachute; }
- void set_gripper_servo(Gripper_Servo *_gripper) { gripper = _gripper; }
- void set_gripper_epm(Gripper_EPM *_gripper_epm) { gripper_epm = _gripper_epm; }
- void set_precland(SIM_Precland *_precland);
- protected:
- SITL *sitl;
- Location home;
- bool home_is_set;
- Location location;
- float ground_level;
- float home_yaw;
- float frame_height;
- Matrix3f dcm;
- Vector3f gyro;
- Vector3f gyro_prev;
- Vector3f ang_accel;
- Vector3f velocity_ef;
- Vector3f wind_ef;
- Vector3f velocity_air_ef;
- Vector3f velocity_air_bf;
- Vector3f position;
- float mass;
- float external_payload_mass = 0.0f;
- Vector3f accel_body;
- float airspeed;
- float airspeed_pitot;
- float battery_voltage = -1.0f;
- float battery_current = 0.0f;
- float rpm1 = 0;
- float rpm2 = 0;
- uint8_t rcin_chan_count = 0;
- float rcin[8];
- float range = -1.0f;
- struct {
-
- struct vector3f_array points;
- struct float_array ranges;
- } scanner;
-
-
- float turbulence_azimuth = 0.0f;
- float turbulence_horizontal_speed = 0.0f;
- float turbulence_vertical_speed = 0.0f;
- Vector3f mag_bf;
- uint64_t time_now_us;
- const float gyro_noise;
- const float accel_noise;
- float rate_hz;
- float achieved_rate_hz;
- float target_speedup;
- uint64_t frame_time_us;
- float scaled_frame_time_us;
- uint64_t last_wall_time_us;
- uint8_t instance;
- const char *autotest_dir;
- const char *frame;
- bool use_time_sync = true;
- float last_speedup = -1.0f;
- const char *config_ = "";
-
- AP_Int8 *ahrs_orientation;
- enum GroundBehaviour {
- GROUND_BEHAVIOR_NONE = 0,
- GROUND_BEHAVIOR_NO_MOVEMENT,
- GROUND_BEHAVIOR_FWD_ONLY,
- GROUND_BEHAVIOR_TAILSITTER,
- } ground_behavior;
- bool use_smoothing;
- AP_Terrain *terrain;
- float ground_height_difference() const;
- virtual bool on_ground() const;
-
- float hagl() const;
-
- void update_position(void);
-
- void update_mag_field_bf(void);
-
- void time_advance();
-
- void setup_frame_time(float rate, float speedup);
-
- void adjust_frame_time(float rate);
-
- void sync_frame_time(void);
-
- void add_noise(float throttle);
-
- uint64_t get_wall_time_us(void) const;
-
- void update_dynamics(const Vector3f &rot_accel);
-
- void update_wind(const struct sitl_input &input);
-
- float filtered_idx(float v, uint8_t idx);
- float filtered_servo_angle(const struct sitl_input &input, uint8_t idx);
- float filtered_servo_range(const struct sitl_input &input, uint8_t idx);
-
- void extrapolate_sensors(float delta_time);
-
- void update_external_payload(const struct sitl_input &input);
- void add_shove_forces(Vector3f &rot_accel, Vector3f &body_accel);
- void add_twist_forces(Vector3f &rot_accel);
- private:
- uint64_t last_time_us = 0;
- uint32_t frame_counter = 0;
- uint32_t last_ground_contact_ms;
- const uint32_t min_sleep_time;
- struct {
- bool enabled;
- Vector3f accel_body;
- Vector3f gyro;
- Matrix3f rotation_b2e;
- Vector3f position;
- Vector3f velocity_ef;
- uint64_t last_update_us;
- Location location;
- } smoothing;
- LowPassFilterFloat servo_filter[4];
- Sprayer *sprayer;
- Gripper_Servo *gripper;
- Gripper_EPM *gripper_epm;
- Parachute *parachute;
- SIM_Precland *precland;
- };
- }
|