LCOV - code coverage report
Current view: top level - SITL - SIM_JSBSim.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 2 0.0 %
Date: 2026-09-09 11:02:08 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /*
       2             :    This program is free software: you can redistribute it and/or modify
       3             :    it under the terms of the GNU General Public License as published by
       4             :    the Free Software Foundation, either version 3 of the License, or
       5             :    (at your option) any later version.
       6             : 
       7             :    This program is distributed in the hope that it will be useful,
       8             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
       9             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      10             :    GNU General Public License for more details.
      11             : 
      12             :    You should have received a copy of the GNU General Public License
      13             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      14             :  */
      15             : /*
      16             :   simulator connection for JSBSim - https://github.com/JSBSim-Team/jsbsim
      17             : */
      18             : 
      19             : #pragma once
      20             : 
      21             : #include "SIM_config.h"
      22             : 
      23             : #if AP_SIM_JSBSIM_ENABLED
      24             : 
      25             : #include <AP_HAL/utility/Socket_native.h>
      26             : 
      27             : #include "SIM_Aircraft.h"
      28             : 
      29             : namespace SITL {
      30             : 
      31             : /*
      32             :   a Jsbsim simulator
      33             :  */
      34             : class JSBSim : public Aircraft {
      35             : public:
      36             :     JSBSim(const char *frame_str);
      37             : 
      38             :     /* update model by one time step */
      39             :     void update(const struct sitl_input &input) override;
      40             : 
      41             :     /* static object creator */
      42           0 :     static Aircraft *create(const char *frame_str) {
      43           0 :         return NEW_NOTHROW JSBSim(frame_str);
      44             :     }
      45             : 
      46             : private:
      47             :     // tcp input control socket to JSBSIm
      48             :     SocketAPM_native sock_control;
      49             : 
      50             :     // UDP packets from JSBSim in fgFDM format
      51             :     SocketAPM_native sock_fgfdm;
      52             : 
      53             :     bool initialised;
      54             : 
      55             :     uint16_t control_port;
      56             :     uint16_t fdm_port;
      57             :     char *jsbsim_script;
      58             :     char *jsbsim_fgout;
      59             :     int jsbsim_stdout;
      60             : 
      61             :     // default JSBSim model
      62             :     const char *jsbsim_model = "Rascal";
      63             : 
      64             :     bool created_templates;
      65             :     bool started_jsbsim;
      66             :     bool opened_control_socket;
      67             :     bool opened_fdm_socket;
      68             : 
      69             :     enum {
      70             :         FRAME_NORMAL,
      71             :         FRAME_ELEVON,
      72             :         FRAME_VTAIL
      73             :     } frame;
      74             : 
      75             :     bool create_templates(void);
      76             :     bool start_JSBSim(void);
      77             :     bool open_control_socket(void);
      78             :     bool open_fdm_socket(void);
      79             :     void send_servos(const struct sitl_input &input);
      80             :     void recv_fdm(const struct sitl_input &input);
      81             :     void check_stdout(void) const;
      82             :     bool expect(const char *str) const;
      83             : 
      84             :     void drain_control_socket();
      85             : };
      86             : 
      87             : } // namespace SITL
      88             : #endif  // AP_SIM_JSBSIM_ENABLED
      89             : 
      90             : namespace SITL {
      91             : /*
      92             :   FGNetFDM class from JSBSim
      93             :  */
      94             : class FGNetFDM {
      95             : public:
      96             : 
      97             :     enum {
      98             :         FG_MAX_ENGINES = 4,
      99             :         FG_MAX_WHEELS = 3,
     100             :         FG_MAX_TANKS = 4
     101             :     };
     102             : 
     103             :     uint32_t version;           // increment when data values change
     104             :     uint32_t padding;           // padding
     105             : 
     106             :     // Positions
     107             :     double longitude;           // geodetic (radians)
     108             :     double latitude;            // geodetic (radians)
     109             :     double altitude;            // above sea level (meters)
     110             :     float agl;                      // above ground level (meters)
     111             :     float phi;                      // roll (radians)
     112             :     float theta;                    // pitch (radians)
     113             :     float psi;                      // yaw or true heading (radians)
     114             :     float alpha;        // angle of attack (radians)
     115             :     float beta;         // side slip angle (radians)
     116             : 
     117             :     // Velocities
     118             :     float phidot;                    // roll rate (radians/sec)
     119             :     float thetadot;                // pitch rate (radians/sec)
     120             :     float psidot;                    // yaw rate (radians/sec)
     121             :     float vcas;          // calibrated airspeed
     122             :     float climb_rate;            // feet per second
     123             :     float v_north;       // north velocity in local/body frame, fps
     124             :     float v_east;        // east velocity in local/body frame, fps
     125             :     float v_down;        // down/vertical velocity in local/body frame, fps
     126             :     float v_body_u;      // ECEF velocity in body axis
     127             :     float v_body_v;      // ECEF velocity in body axis
     128             :     float v_body_w;      // ECEF velocity in body axis
     129             : 
     130             :     // Accelerations
     131             :     float A_X_pilot;            // X accel in body frame ft/sec^2
     132             :     float A_Y_pilot;            // Y accel in body frame ft/sec^2
     133             :     float A_Z_pilot;            // Z accel in body frame ft/sec^2
     134             : 
     135             :     // Stall
     136             :     float stall_warning;  // 0.0 - 1.0 indicating the amount of stall
     137             :     float slip_deg;                 // slip ball deflection
     138             : 
     139             :     // Pressure
     140             : 
     141             :     // Engine status
     142             :     uint32_t num_engines;               // Number of valid engines
     143             :     uint32_t eng_state[FG_MAX_ENGINES]; // Engine state (off, cranking, running)
     144             :     float rpm[FG_MAX_ENGINES];          // Engine RPM rev/min
     145             :     float fuel_flow[FG_MAX_ENGINES];    // Fuel flow gallons/hr
     146             :     float fuel_px[FG_MAX_ENGINES];      // Fuel pressure psi
     147             :     float egt[FG_MAX_ENGINES];          // Exhuast gas temp deg F
     148             :     float cht[FG_MAX_ENGINES];          // Cylinder head temp deg F
     149             :     float mp_osi[FG_MAX_ENGINES];       // Manifold pressure
     150             :     float tit[FG_MAX_ENGINES];          // Turbine Inlet Temperature
     151             :     float oil_temp[FG_MAX_ENGINES];     // Oil temp deg F
     152             :     float oil_px[FG_MAX_ENGINES];       // Oil pressure psi
     153             : 
     154             :     // Consumables
     155             :     uint32_t num_tanks;                       // Max number of fuel tanks
     156             :     float fuel_quantity[FG_MAX_TANKS];
     157             : 
     158             :     // Gear status
     159             :     uint32_t num_wheels;
     160             :     uint32_t wow[FG_MAX_WHEELS];
     161             :     float gear_pos[FG_MAX_WHEELS];
     162             :     float gear_steer[FG_MAX_WHEELS];
     163             :     float gear_compression[FG_MAX_WHEELS];
     164             : 
     165             :     // Environment
     166             :     uint32_t cur_time;           // current simulation time of JSBSim
     167             :     int32_t warp;                // offset in seconds to unix time
     168             :     float visibility;            // visibility in meters (for env. effects)
     169             : 
     170             :     // Control surface positions (normalized values)
     171             :     float elevator;
     172             :     float elevator_trim_tab;
     173             :     float left_flap;
     174             :     float right_flap;
     175             :     float left_aileron;
     176             :     float right_aileron;
     177             :     float rudder;
     178             :     float nose_wheel;
     179             :     float speedbrake;
     180             :     float spoilers;
     181             : 
     182             :     // nasty hack .... JSBSim sends in little-endian
     183             :     void ByteSwap(void);
     184             : };
     185             : 
     186             : }  // end namespace SITL

Generated by: LCOV version 1.14