SIM_SilentWings.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. #pragma once
  14. #include <AP_HAL/utility/Socket.h>
  15. #include "SIM_Aircraft.h"
  16. namespace SITL {
  17. /*
  18. A wrapper for a simulated Silent Wings aircraft.
  19. */
  20. class SilentWings : public Aircraft {
  21. public:
  22. SilentWings(const char *frame_str);
  23. /* Updates the aircraft model by one time step */
  24. void update(const struct sitl_input &input) override;
  25. /* Static object creator */
  26. static Aircraft *create(const char *frame_str) {
  27. return new SilentWings(frame_str);
  28. }
  29. private:
  30. /* Reply packet sent from SilentWings to ArduPlane */
  31. struct PACKED fdm_packet {
  32. unsigned int timestamp; // Millisec Timestamp
  33. double position_latitude; // Degrees Position latitude,
  34. double position_longitude; // Degrees longitude,
  35. float altitude_msl; // m Altitude w.r.t. the sea level
  36. float altitude_ground; // m Altitude w.r.t. the ground level
  37. float altitude_ground_45; // m Ground 45 degrees ahead (NOT IMPLEMENTED YET)
  38. float altitude_ground_forward; // m Ground straight ahead (NOT IMPLEMENTED YET)
  39. float roll; // Degrees
  40. float pitch; // Degrees
  41. float yaw; // Degrees
  42. float d_roll; // Deg/sec Roll speed
  43. float d_pitch; // Deg/sec Pitch speed
  44. float d_yaw; // Deg/sec Yaw speed
  45. float vx; // m/s Velocity vector in body-axis
  46. float vy;
  47. float vz;
  48. float vx_wind; // m/s Velocity vector in body-axis, relative to the wind
  49. float vy_wind;
  50. float vz_wind;
  51. float v_eas; // m/s Equivalent (indicated) air speed.
  52. float ax; // m/s^2 Acceleration vector in body axis
  53. float ay;
  54. float az;
  55. float angle_of_attack; // Degrees Angle of attack
  56. float angle_sideslip; // Degrees Sideslip angle
  57. float vario; // m/s Total energy-compensated variometer
  58. float heading; // Degrees Compass heading
  59. float rate_of_turn; // Deg/sec Rate of turn
  60. float airpressure; // Pa Local air pressure at aircraft altitude)
  61. float density; // Air density at aircraft altitude
  62. float temperature; // Degrees Celcius Air temperature at aircraft altitude
  63. } pkt;
  64. struct {
  65. uint32_t last_report_ms;
  66. uint32_t data_count;
  67. uint32_t frame_count;
  68. } report;
  69. bool recv_fdm(void);
  70. void process_packet();
  71. bool interim_update();
  72. /* Create and set in/out socket for Silent Wings simulator */
  73. void set_interface_ports(const char* address, const int port_in, const int port_out) override;
  74. /* Sends control inputs to the Silent Wings. */
  75. void send_servos(const struct sitl_input &input);
  76. /* Timestamp of the latest data packet received from Silent Wings. */
  77. uint32_t last_data_time_ms;
  78. /* Timestamp of the first data packet received from Silent Wings. */
  79. uint32_t first_pkt_timestamp_ms;
  80. /* Indicates whether first_pkt_timestamp_ms has been initialized (i.e., any packets have been received from Silent Wings. */
  81. bool inited_first_pkt_timestamp;
  82. /* ArduPlane's internal time when the first packet from Silent Wings is received. */
  83. uint64_t time_base_us;
  84. SocketAPM sock;
  85. const char *_sw_address = "127.0.0.1";
  86. int _port_in = 6060;
  87. int _sw_port = 6070;
  88. bool home_initialized;
  89. };
  90. } // namespace SITL