SIM_Gazebo.h 2.1 KB

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