LCOV - code coverage report
Current view: top level - SITL - SIM_Webots_Python.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 Webots 2023a
      17             : */
      18             : 
      19             : #pragma once
      20             : 
      21             : #include "SIM_config.h"
      22             : 
      23             : #if AP_SIM_WEBOTSPYTHON_ENABLED
      24             : 
      25             : #include "SIM_Aircraft.h"
      26             : #include <AP_HAL/utility/Socket_native.h>
      27             : 
      28             : namespace SITL {
      29             : 
      30             : /*
      31             :   WebotsPython simulator
      32             :  */
      33             : class WebotsPython : public Aircraft {
      34             : public:
      35             :     WebotsPython(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 WebotsPython(frame_str);
      43             :     }
      44             : 
      45             :     /*  Create and set in/out socket for Webots simulator */
      46             :     void set_interface_ports(const char* address, const int port_in, const int port_out) override;
      47             : 
      48             : private:
      49             :     /// @brief packet to send to Webots
      50             :     /// python struct code 'f'*16
      51             :     struct servo_packet {
      52             :       float motor_speed[16];
      53             :     };
      54             : 
      55             :     /// @brief packet from Webots (the Flight Dynamics Model)
      56             :     /// python struct code 'd'*(1+3+3+3+3+3)
      57             :     struct fdm_packet {
      58             :       double timestamp;  // in seconds
      59             :       double imu_angular_velocity_rpy[3];
      60             :       double imu_linear_acceleration_xyz[3];
      61             :       double imu_orientation_rpy[3];
      62             :       double velocity_xyz[3];
      63             :       double position_xyz[3];
      64             :     };
      65             : 
      66             :     /// @brief receive sensor packet from Webots
      67             :     void recv_fdm(const struct sitl_input &input);
      68             : 
      69             :     /// @brief send servo packet to Webots
      70             :     void send_servos(const struct sitl_input &input);
      71             : 
      72             :     /// @brief drain all pending packets from Webots
      73             :     void drain_sockets();
      74             : 
      75             :     double last_timestamp;
      76             : 
      77             :     SocketAPM_native socket_sitl;
      78             :     const char* _webots_address = "127.0.0.1";
      79             :     int _webots_port = 9002;
      80             :     static const uint64_t WEBOTS_TIMEOUT_US = 5000000;
      81             : };
      82             : 
      83             : }  // namespace SITL
      84             : 
      85             : 
      86             : #endif  // AP_SIM_WEBOTSPYTHON_ENABLED

Generated by: LCOV version 1.14