2016-02-17 21:25:28 -04:00
|
|
|
#pragma once
|
2012-12-14 21:54:26 -04:00
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2012-12-14 21:54:26 -04:00
|
|
|
|
2015-05-04 03:15:12 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
2023-08-17 17:18:36 -03:00
|
|
|
|
|
|
|
#include "SITL_State_common.h"
|
|
|
|
|
2020-09-12 16:04:38 -03:00
|
|
|
#if defined(HAL_BUILD_AP_PERIPH)
|
|
|
|
#include "SITL_Periph_State.h"
|
|
|
|
#else
|
2012-12-14 21:54:26 -04:00
|
|
|
|
2015-05-04 03:15:12 -03:00
|
|
|
class HAL_SITL;
|
2012-12-14 21:54:26 -04:00
|
|
|
|
2023-08-17 17:18:36 -03:00
|
|
|
class HALSITL::SITL_State : public SITL_State_Common {
|
2016-01-10 02:23:32 -04:00
|
|
|
friend class HALSITL::Scheduler;
|
|
|
|
friend class HALSITL::Util;
|
2016-07-21 21:58:02 -03:00
|
|
|
friend class HALSITL::GPIO;
|
2012-12-14 21:54:26 -04:00
|
|
|
public:
|
2023-09-27 20:34:22 -03:00
|
|
|
void init(int argc, char * const argv[]) override;
|
2012-12-14 21:54:26 -04:00
|
|
|
|
2015-03-21 11:27:25 -03:00
|
|
|
void loop_hook(void);
|
2015-05-04 21:59:07 -03:00
|
|
|
uint16_t base_port(void) const {
|
|
|
|
return _base_port;
|
|
|
|
}
|
2012-12-17 22:34:13 -04:00
|
|
|
|
2016-05-16 03:51:09 -03:00
|
|
|
bool use_rtscts(void) const {
|
|
|
|
return _use_rtscts;
|
|
|
|
}
|
|
|
|
|
2015-11-03 16:59:43 -04:00
|
|
|
// paths for UART devices
|
2021-04-26 17:47:21 -03:00
|
|
|
const char *_uart_path[9] {
|
2015-11-03 16:59:43 -04:00
|
|
|
"tcp:0:wait",
|
|
|
|
"GPS1",
|
|
|
|
"tcp:2",
|
|
|
|
"tcp:3",
|
2016-04-19 21:08:35 -03:00
|
|
|
"GPS2",
|
2017-06-23 16:45:26 -03:00
|
|
|
"tcp:5",
|
2018-06-29 04:51:14 -03:00
|
|
|
"tcp:6",
|
2021-04-26 17:47:21 -03:00
|
|
|
"tcp:7",
|
|
|
|
"tcp:8",
|
2015-11-03 16:59:43 -04:00
|
|
|
};
|
2020-08-23 03:24:22 -03:00
|
|
|
std::vector<struct AP_Param::defaults_table_struct> cmdline_param;
|
2019-08-15 03:52:50 -03:00
|
|
|
|
|
|
|
/* parse a home location string */
|
|
|
|
static bool parse_home(const char *home_str,
|
|
|
|
Location &loc,
|
|
|
|
float &yaw_degrees);
|
|
|
|
|
2020-12-30 15:56:35 -04:00
|
|
|
/* lookup a location in locations.txt */
|
|
|
|
static bool lookup_location(const char *home_str,
|
|
|
|
Location &loc,
|
|
|
|
float &yaw_degrees);
|
|
|
|
|
2020-12-28 10:33:56 -04:00
|
|
|
uint8_t get_instance() const { return _instance; }
|
|
|
|
|
2012-12-14 21:54:26 -04:00
|
|
|
private:
|
|
|
|
void _parse_command_line(int argc, char * const argv[]);
|
2015-05-04 18:08:42 -03:00
|
|
|
void _set_param_default(const char *parm);
|
2012-12-14 21:54:26 -04:00
|
|
|
void _usage(void);
|
2021-12-11 05:49:33 -04:00
|
|
|
void _sitl_setup();
|
2012-12-14 21:54:26 -04:00
|
|
|
void _setup_fdm(void);
|
|
|
|
void _setup_timer(void);
|
|
|
|
void _setup_adc(void);
|
|
|
|
|
2016-11-19 02:21:54 -04:00
|
|
|
void set_height_agl(void);
|
2021-12-07 21:49:53 -04:00
|
|
|
void _update_rangefinder();
|
2016-07-13 10:27:56 -03:00
|
|
|
void _set_signal_handlers(void) const;
|
|
|
|
|
2017-05-11 10:38:32 -03:00
|
|
|
void _update_airspeed(float airspeed);
|
2016-09-21 14:15:00 -03:00
|
|
|
void _check_rc_input(void);
|
2018-05-30 07:18:40 -03:00
|
|
|
bool _read_rc_sitl_input();
|
2015-05-02 07:27:33 -03:00
|
|
|
void _fdm_input_local(void);
|
2016-01-01 02:09:07 -04:00
|
|
|
void _output_to_flightgear(void);
|
2018-07-31 09:32:43 -03:00
|
|
|
void _simulator_servos(struct sitl_input &input);
|
2015-05-02 08:41:13 -03:00
|
|
|
void _fdm_input_step(void);
|
2015-05-04 21:59:07 -03:00
|
|
|
|
2015-05-02 08:41:13 -03:00
|
|
|
void wait_clock(uint64_t wait_time_usec);
|
2015-03-21 11:27:25 -03:00
|
|
|
|
2012-12-14 21:54:26 -04:00
|
|
|
// internal state
|
2015-05-10 08:02:20 -03:00
|
|
|
uint8_t _instance;
|
2015-03-21 11:27:25 -03:00
|
|
|
uint16_t _base_port;
|
|
|
|
pid_t _parent_pid;
|
|
|
|
uint32_t _update_count;
|
|
|
|
|
2016-01-10 02:23:32 -04:00
|
|
|
Scheduler *_scheduler;
|
2015-03-21 11:27:25 -03:00
|
|
|
|
2016-01-03 17:22:02 -04:00
|
|
|
SocketAPM _sitl_rc_in{true};
|
2016-09-21 14:15:00 -03:00
|
|
|
uint16_t _rcin_port;
|
2016-11-15 10:44:51 -04:00
|
|
|
uint16_t _fg_view_port;
|
2016-11-17 14:05:04 -04:00
|
|
|
uint16_t _irlock_port;
|
2015-03-21 11:27:25 -03:00
|
|
|
|
|
|
|
bool _synthetic_clock_mode;
|
2015-04-13 03:16:22 -03:00
|
|
|
|
2016-05-16 03:51:09 -03:00
|
|
|
bool _use_rtscts;
|
2016-09-21 14:02:15 -03:00
|
|
|
bool _use_fg_view;
|
2016-05-16 03:51:09 -03:00
|
|
|
|
2018-06-16 22:39:41 -03:00
|
|
|
const char *_fg_address;
|
2015-05-03 19:10:33 -03:00
|
|
|
|
2015-04-13 03:16:22 -03:00
|
|
|
// delay buffer variables
|
|
|
|
static const uint8_t wind_buffer_length = 50;
|
|
|
|
|
|
|
|
// airspeed sensor delay buffer variables
|
|
|
|
struct readings_wind {
|
|
|
|
uint32_t time;
|
|
|
|
float data;
|
|
|
|
};
|
|
|
|
uint8_t store_index_wind;
|
|
|
|
uint32_t last_store_time_wind;
|
|
|
|
VectorN<readings_wind,wind_buffer_length> buffer_wind;
|
|
|
|
uint32_t time_delta_wind;
|
|
|
|
uint32_t delayed_time_wind;
|
2018-04-30 12:26:15 -03:00
|
|
|
uint32_t wind_start_delay_micros;
|
2015-04-13 03:16:22 -03:00
|
|
|
|
2021-10-16 00:10:40 -03:00
|
|
|
// simulated GPS devices
|
|
|
|
SITL::GPS *gps[2]; // constrained by # of parameter sets
|
2021-12-07 21:49:53 -04:00
|
|
|
|
|
|
|
// returns a voltage between 0V to 5V which should appear as the
|
|
|
|
// voltage from the sensor
|
|
|
|
float _sonar_pin_voltage() const;
|
|
|
|
|
2023-08-17 17:18:36 -03:00
|
|
|
// multicast state
|
|
|
|
int mc_out_fd = -1;
|
2023-08-19 03:09:50 -03:00
|
|
|
int servo_in_fd = -1;
|
|
|
|
|
2023-08-17 17:18:36 -03:00
|
|
|
// send out SITL state as UDP multicast
|
|
|
|
void multicast_state_open(void);
|
|
|
|
void multicast_state_send(void);
|
2023-08-19 03:09:50 -03:00
|
|
|
void multicast_servo_update(struct sitl_input &input);
|
|
|
|
|
|
|
|
uint16_t mc_servo[SITL_NUM_CHANNELS];
|
|
|
|
void check_servo_input(void);
|
2012-12-14 21:54:26 -04:00
|
|
|
};
|
|
|
|
|
2020-09-12 16:04:38 -03:00
|
|
|
#endif // defined(HAL_BUILD_AP_PERIPH)
|
2015-05-04 03:15:12 -03:00
|
|
|
#endif // CONFIG_HAL_BOARD == HAL_BOARD_SITL
|