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 ardupilot version of Gazebo 17 : */ 18 : 19 : #pragma once 20 : 21 : #include "SIM_config.h" 22 : 23 : #if AP_SIM_GAZEBO_ENABLED 24 : 25 : #include "SIM_Aircraft.h" 26 : #include <AP_HAL/utility/Socket_native.h> 27 : 28 : namespace SITL { 29 : 30 : /* 31 : Gazebo simulator 32 : */ 33 : class Gazebo : public Aircraft { 34 : public: 35 : Gazebo(const char *frame_str); 36 : 37 : /* update model by one time step */ 38 : void update(const struct sitl_input &input) override; 39 : 40 : /* static object creator */ 41 0 : static Aircraft *create(const char *frame_str) { 42 0 : return NEW_NOTHROW Gazebo(frame_str); 43 : } 44 : 45 : /* Create and set in/out socket for Gazebo simulator */ 46 : void set_interface_ports(const char* address, const int port_in, const int port_out) override; 47 : 48 : private: 49 : /* 50 : packet sent to Gazebo 51 : */ 52 : struct servo_packet { 53 : // size matches sitl_input upstream 54 : float motor_speed[16]; 55 : }; 56 : 57 : /* 58 : reply packet sent from Gazebo to ArduPilot 59 : */ 60 : struct fdm_packet { 61 : double timestamp; // in seconds 62 : double imu_angular_velocity_rpy[3]; 63 : double imu_linear_acceleration_xyz[3]; 64 : double imu_orientation_quat[4]; 65 : double velocity_xyz[3]; 66 : double position_xyz[3]; 67 : }; 68 : 69 : void recv_fdm(const struct sitl_input &input); 70 : void send_servos(const struct sitl_input &input); 71 : void drain_sockets(); 72 : 73 : double last_timestamp; 74 : 75 : SocketAPM_native socket_sitl; 76 : const char *_gazebo_address = "127.0.0.1"; 77 : int _gazebo_port = 9002; 78 : static const uint64_t GAZEBO_TIMEOUT_US = 5000000; 79 : }; 80 : 81 : } // namespace SITL 82 : 83 : 84 : #endif // AP_SIM_GAZEBO_ENABLED