123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- #pragma once
- #include <AP_Math/AP_Math.h>
- #include <GCS_MAVLink/GCS_MAVLink.h>
- #include <AP_Common/Location.h>
- #include "SIM_Sprayer.h"
- #include "SIM_Gripper_Servo.h"
- #include "SIM_Gripper_EPM.h"
- #include "SIM_Parachute.h"
- #include "SIM_Precland.h"
- namespace SITL {
- struct vector3f_array {
- uint16_t length;
- Vector3f *data;
- };
- struct float_array {
- uint16_t length;
- float *data;
- };
-
- struct sitl_fdm {
-
- uint64_t timestamp_us;
- Location home;
- double latitude, longitude;
- double altitude;
- double heading;
- double speedN, speedE, speedD;
- double xAccel, yAccel, zAccel;
- double rollRate, pitchRate, yawRate;
- double rollDeg, pitchDeg, yawDeg;
- Quaternion quaternion;
- double airspeed;
- double battery_voltage;
- double battery_current;
- double rpm1;
- double rpm2;
- uint8_t rcin_chan_count;
- float rcin[8];
- double range;
- Vector3f bodyMagField;
- Vector3f angAccel;
- struct {
-
- struct vector3f_array points;
- struct float_array ranges;
- } scanner;
- };
- #define SITL_NUM_CHANNELS 16
- class SITL {
- public:
- SITL() {
-
- mag_ofs.set(Vector3f(5, 13, -18));
- AP_Param::setup_object_defaults(this, var_info);
- AP_Param::setup_object_defaults(this, var_info2);
- if (_singleton != nullptr) {
- AP_HAL::panic("Too many SITL instances");
- }
- _singleton = this;
- }
-
- SITL(const SITL &other) = delete;
- SITL &operator=(const SITL&) = delete;
- static SITL *_singleton;
- static SITL *get_singleton() { return _singleton; }
- enum SITL_RCFail {
- SITL_RCFail_None = 0,
- SITL_RCFail_NoPulses = 1,
- SITL_RCFail_Throttle950 = 2,
- };
- enum GPSType {
- GPS_TYPE_NONE = 0,
- GPS_TYPE_UBLOX = 1,
- GPS_TYPE_MTK = 2,
- GPS_TYPE_MTK16 = 3,
- GPS_TYPE_MTK19 = 4,
- GPS_TYPE_NMEA = 5,
- GPS_TYPE_SBP = 6,
- GPS_TYPE_FILE = 7,
- GPS_TYPE_NOVA = 8,
- GPS_TYPE_SBP2 = 9,
- };
- struct sitl_fdm state;
-
- uint16_t update_rate_hz;
-
- bool motors_on;
-
- float height_agl;
-
- static const struct AP_Param::GroupInfo var_info[];
- static const struct AP_Param::GroupInfo var_info2[];
-
- AP_Float baro_noise;
- AP_Float baro_drift;
- AP_Float baro_glitch;
- AP_Float gyro_noise;
- AP_Vector3f gyro_scale;
- AP_Float accel_noise;
- AP_Float accel2_noise;
- AP_Vector3f accel_bias;
- AP_Vector3f accel2_bias;
- AP_Float arspd_noise;
- AP_Float arspd_fail;
- AP_Float arspd2_fail;
- AP_Float arspd_fail_pressure;
- AP_Float arspd_fail_pitot_pressure;
- AP_Float arspd2_fail_pressure;
- AP_Float arspd2_fail_pitot_pressure;
- AP_Float gps_noise;
- AP_Int16 gps_lock_time;
- AP_Int16 gps_alt_offset;
- AP_Int8 vicon_observation_history_length;
- AP_Float mag_noise;
- AP_Float mag_error;
- AP_Vector3f mag_mot;
- AP_Vector3f mag_ofs;
- AP_Vector3f mag_diag;
- AP_Vector3f mag_offdiag;
- AP_Int8 mag_orient;
- AP_Float servo_speed;
- AP_Float sonar_glitch;
- AP_Float sonar_noise;
- AP_Float sonar_scale;
- AP_Float drift_speed;
- AP_Float drift_time;
- AP_Float engine_mul;
- AP_Int8 engine_fail;
- AP_Int8 gps_disable;
- AP_Int8 gps2_enable;
- AP_Int8 gps_delay;
- AP_Int8 gps_type;
- AP_Int8 gps2_type;
- AP_Float gps_byteloss;
- AP_Int8 gps_numsats;
- AP_Vector3f gps_glitch;
- AP_Vector3f gps2_glitch;
- AP_Int8 gps_hertz;
- AP_Float batt_voltage;
- AP_Float accel_fail;
- AP_Int8 rc_fail;
- AP_Int8 rc_chancount;
- AP_Int8 baro_disable;
- AP_Int8 float_exception;
- AP_Int8 flow_enable;
- AP_Int16 flow_rate;
- AP_Int8 flow_delay;
- AP_Int8 terrain_enable;
- AP_Int16 pin_mask;
- AP_Float speedup;
- AP_Int8 odom_enable;
- AP_Int8 telem_baudlimit_enable;
- AP_Float flow_noise;
- AP_Int8 baro_count;
- AP_Int8 gps_hdg_enabled;
- AP_Int32 loop_delay;
-
- enum WindType {
- WIND_TYPE_SQRT = 0,
- WIND_TYPE_NO_LIMIT = 1,
- WIND_TYPE_COEF = 2,
- };
-
- float wind_speed_active;
- float wind_direction_active;
- float wind_dir_z_active;
- AP_Float wind_speed;
- AP_Float wind_direction;
- AP_Float wind_turbulance;
- AP_Float gps_drift_alt;
- AP_Float wind_dir_z;
- AP_Int8 wind_type;
- AP_Float wind_type_alt;
- AP_Float wind_type_coef;
- AP_Int16 baro_delay;
- AP_Int16 mag_delay;
- AP_Int16 wind_delay;
-
- AP_Int16 adsb_plane_count;
- AP_Float adsb_radius_m;
- AP_Float adsb_altitude_m;
- AP_Int8 adsb_tx;
-
- AP_Vector3f mag_anomaly_ned;
- AP_Float mag_anomaly_hgt;
-
- AP_Vector3f imu_pos_offset;
- AP_Vector3f gps_pos_offset;
- AP_Vector3f rngfnd_pos_offset;
- AP_Vector3f optflow_pos_offset;
-
- AP_Float temp_start;
- AP_Float temp_flight;
- AP_Float temp_tconst;
- AP_Float temp_baro_factor;
-
-
- AP_Int8 arspd_signflip;
-
- AP_Int8 wow_pin;
-
- AP_Vector3f vibe_freq;
-
- AP_Int8 gyro_fail_mask;
- AP_Int8 accel_fail_mask;
- struct {
- AP_Float x;
- AP_Float y;
- AP_Float z;
- AP_Int32 t;
- uint32_t start_ms;
- } shove;
- struct {
- AP_Float x;
- AP_Float y;
- AP_Float z;
- AP_Int32 t;
- uint32_t start_ms;
- } twist;
- AP_Int8 gnd_behav;
- struct {
- AP_Int8 enable;
- AP_Float length;
- AP_Float amp;
- AP_Float direction;
- AP_Float speed;
- } wave;
- struct {
- AP_Float direction;
- AP_Float speed;
- } tide;
-
- struct {
- AP_Float lat;
- AP_Float lng;
- AP_Float alt;
- AP_Float hdg;
- } opos;
- uint16_t irlock_port;
- void simstate_send(mavlink_channel_t chan);
- void Log_Write_SIMSTATE();
-
- static void convert_body_frame(double rollDeg, double pitchDeg,
- double rollRate, double pitchRate, double yawRate,
- double *p, double *q, double *r);
-
- static Vector3f convert_earth_frame(const Matrix3f &dcm, const Vector3f &gyro);
- Sprayer sprayer_sim;
- Gripper_Servo gripper_sim;
- Gripper_EPM gripper_epm_sim;
- Parachute parachute_sim;
- SIM_Precland precland_sim;
- };
- }
- namespace AP {
- SITL::SITL *sitl();
- };
|