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 : gimbal simulator class 17 : 18 : ./Tools/autotest/sim_vehicle.py -D -G -v ArduCopter --mavlink-gimbal 19 : param set MNT1_TYPE 2 20 : param set RC6_OPTION 213 # MOUNT1_PITCH 21 : rc 6 1818 # for neutral pitch input 22 : */ 23 : 24 : #pragma once 25 : 26 : #include "SIM_config.h" 27 : 28 : #if AP_SIM_SOLOGIMBAL_ENABLED 29 : 30 : #include "SIM_Gimbal.h" 31 : 32 : #include <AP_Math/AP_Math.h> 33 : #include <GCS_MAVLink/GCS_MAVLink.h> 34 : #include <AP_HAL/utility/Socket_native.h> 35 : 36 : namespace SITL { 37 : 38 : class SoloGimbal { 39 : public: 40 : 41 : // endpoint for the vehicle's SERIAL1 MAVLink connection 42 1 : explicit SoloGimbal(uint16_t _target_port) : target_path(nullptr), target_port(_target_port) {} 43 0 : explicit SoloGimbal(const char *_target_path) : target_path(_target_path), target_port(0) {} 44 : void update(const Aircraft &aicraft); 45 : 46 : private: 47 : 48 : const char *target_address = "127.0.0.1"; 49 : const char *const target_path; 50 : const uint16_t target_port; 51 : 52 : // physic simulation of gimbal: 53 : Gimbal gimbal; 54 : 55 : // reporting variables. gimbal pushes these to vehicle code over 56 : // MAVLink at approx 100Hz 57 : 58 : // reporting period in ms 59 : const float reporting_period_ms = 10; 60 : 61 : uint32_t last_report_us; 62 : uint32_t last_heartbeat_ms; 63 : bool seen_heartbeat; 64 : bool seen_gimbal_control; 65 : uint8_t vehicle_system_id; 66 : uint8_t vehicle_component_id; 67 : 68 : SocketAPM_native mav_socket{false}; 69 : struct { 70 : // socket to telem2 on aircraft 71 : bool connected; 72 : mavlink_message_t rxmsg; 73 : mavlink_status_t status; 74 : uint8_t seq; 75 : } mavlink; 76 : 77 : uint32_t param_send_last_ms; 78 : uint8_t param_send_idx; 79 : 80 : // component ID we send from: 81 : const uint8_t gimbal_component_id = 154; // MAV_COMP_ID_GIMBAL 82 : 83 : void send_report(void); 84 : void param_send(const struct gimbal_param *p); 85 : struct gimbal_param *param_find(const char *name); 86 : }; 87 : 88 : } // namespace SITL 89 : 90 : #endif // AP_SIM_SOLOGIMBAL_ENABLED