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 Scrimmage Simulator 17 : */ 18 : 19 : #pragma once 20 : 21 : #include "SIM_config.h" 22 : 23 : #if AP_SIM_SCRIMMAGE_ENABLED 24 : 25 : #include <string> 26 : 27 : #include <AP_HAL/utility/Socket_native.h> 28 : 29 : #include "SIM_Aircraft.h" 30 : 31 : namespace SITL { 32 : 33 : /* 34 : a last_letter simulator 35 : */ 36 : class Scrimmage : public Aircraft { 37 : public: 38 : Scrimmage(const char *frame_str); 39 : 40 : /* update model by one time step */ 41 : void update(const struct sitl_input &input) override; 42 : 43 : /* static object creator */ 44 0 : static Aircraft *create(const char *frame_str) { 45 0 : return NEW_NOTHROW Scrimmage(frame_str); 46 : } 47 : 48 : /* Create and set in/out socket for extenal simulator */ 49 : void set_interface_ports(const char* address, const int port_in, const int port_out) override; 50 : 51 : private: 52 : uint16_t fdm_port_in; 53 : uint16_t fdm_port_out; 54 : const char* fdm_address; 55 : 56 : /* 57 : packet sent to Scrimmage from ArduPilot 58 : */ 59 : static const int MAX_NUM_SERVOS = 16; 60 : struct servo_packet { 61 : uint16_t servos[MAX_NUM_SERVOS]; 62 : }; 63 : 64 : /* 65 : state packet sent from Scrimmage to ArduPilot 66 : */ 67 : struct fdm_packet { 68 : uint64_t timestamp_us; // simulation time in microseconds 69 : double latitude, longitude; 70 : double altitude; 71 : double heading; 72 : double speedN, speedE, speedD; 73 : double xAccel, yAccel, zAccel; 74 : double rollRate, pitchRate, yawRate; 75 : double roll, pitch, yaw; 76 : double airspeed; 77 : }; 78 : 79 : void recv_fdm(const struct sitl_input &input); 80 : void send_servos(const struct sitl_input &input); 81 : 82 : uint64_t prev_timestamp_us; 83 : SocketAPM_native recv_sock; 84 : SocketAPM_native send_sock; 85 : }; 86 : 87 : } // namespace SITL 88 : 89 : #endif // AP_SIM_SCRIMMAGE_ENABLED