26 #include <sys/types.h> 39 const char *colon = strchr(frame_str,
':');
44 heli_frame = (strstr(frame_str,
"-heli") !=
nullptr);
47 printf(
"Waiting for XPlane data on UDP port %u and sending to port %u\n",
62 uint8_t marker[5] {
'D',
'S',
'E',
'L',
'0' };
66 for (uint8_t i=0; i<64 && count<8; i++) {
67 if ((((uint64_t)1)<<i) & sel_mask) {
68 dsel.data[count++] = i;
69 printf(
"i=%u\n", (
unsigned)i);
74 printf(
"Selecting %u data types 0x%llx\n", (
unsigned)count, (
unsigned long long)sel_mask);
78 uint8_t marker[5] {
'U',
'S',
'E',
'L',
'0' };
87 for (uint8_t i=0; i<64 && count<8; i++) {
88 if ((((uint64_t)1)<<i) & usel_mask) {
89 usel.data[count++] = i;
94 printf(
"De-selecting %u data types 0x%llx\n", (
unsigned)count, (
unsigned long long)usel_mask);
104 uint8_t *p = &pkt[5];
105 const uint8_t pkt_len = 36;
106 uint64_t data_mask = 0;
107 const uint64_t one = 1U;
115 uint32_t wait_time_ms = 1;
123 ssize_t len =
socket_in.recv(pkt,
sizeof(pkt), wait_time_ms);
125 if (len < pkt_len+5 || memcmp(pkt,
"DATA", 4) != 0) {
140 while (len >= pkt_len) {
141 const float *data = (
const float *)p;
145 data_mask |= (((uint64_t)1) << code);
149 uint64_t tus = data[3] * 1.0e6f;
153 printf(
"X-Plane time reset %lu\n", (
unsigned long)tdiff);
165 loc.lat = data[1] * 1e7;
166 loc.lng = data[2] * 1e7;
190 float roll, pitch, yaw;
225 rcin[0] = (data[2] + 1)*0.5
f;
226 rcin[1] = (data[1] + 1)*0.5
f;
227 rcin[3] = (data[3] + 1)*0.5
f;
288 if (data_mask != required_mask) {
290 uint64_t usel = data_mask & ~required_mask;
291 uint64_t sel = required_mask & ~data_mask;
307 printf(
"X-Plane home reset dist=%f alt=%.1f/%.1f\n",
359 float aileron = (input.
servos[0]-1500)/500.0
f;
360 float elevator = (input.
servos[1]-1500)/500.0
f;
361 float throttle = (input.
servos[2]-1000)/1000.0;
362 float rudder = (input.
servos[3]-1500)/500.0
f;
364 uint8_t marker[5] {
'D',
'A',
'T',
'A',
'0' };
369 if (input.
servos[0] == 0) {
372 if (input.
servos[1] == 0) {
375 if (input.
servos[2] == 0) {
378 if (input.
servos[3] == 0) {
389 float flap = (input.
servos[flap_chan]-1000)/1000.0;
391 send_dref(
"sim/flightmodel/controls/flaprqst", flap);
392 send_dref(
"sim/aircraft/overflow/acf_flap_arm", flap>0?1:0);
397 d.data[0] = elevator;
405 d.data[0] = throttle;
406 d.data[1] = throttle;
407 d.data[2] = throttle;
408 d.data[3] = throttle;
413 float collective = 10*(input.
servos[2]-1500)/500.0;
416 throttle = (input.
servos[7]-1000)/1000.0;
419 float throttle2 = (input.
servos[5]-1000)/1000.0;
420 float throttle3 = (input.
servos[6]-1000)/1000.0;
423 d.data[0] = collective;
424 d.data[1] = -rudder*15;
431 d.data[0] = throttle;
432 d.data[1] = throttle;
433 d.data[2] = throttle2;
434 d.data[3] = throttle3;
449 uint8_t marker[5] {
'D',
'R',
'E',
'F',
'0' };
454 strcpy(d.name, name);
468 if (
report.last_report_ms == 0) {
469 report.last_report_ms = now;
471 if (now -
report.last_report_ms > 5000) {
472 float dt = (now -
report.last_report_ms) * 1.0e-3
f;
473 printf(
"Data rate: %.1f FPS Frame rate: %.1f FPS\n",
475 report.last_report_ms = now;
int printf(const char *fmt,...)
const AP_HAL::HAL & hal
-*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
void select_data(uint64_t usel_mask, uint64_t sel_mask)
float get_distance(const struct Location &loc1, const struct Location &loc2)
void from_euler(float roll, float pitch, float yaw)
void send_dref(const char *name, float value)
int32_t lat
param 3 - Latitude * 10**7
static bool find_channel(SRV_Channel::Aux_servo_function_t function, uint8_t &chan)
static auto MAX(const A &one, const B &two) -> decltype(one > two ? one :two)
int32_t alt
param 2 - Altitude in centimeters (meters * 100) see LOCATION_ALT_MAX_M
void update(const struct sitl_input &input)
void update_mag_field_bf(void)
void update_position(void)
int32_t lng
param 4 - Longitude * 10**7
static constexpr float radians(float deg)
void extrapolate_sensors(float delta_time)
uint32_t xplane_frame_time
void send_data(const struct sitl_input &input)
const float throttle_magic_scale
const float KNOTS_TO_METERS_PER_SECOND
struct SITL::XPlane::@211 report
const float FEET_TO_METERS
uint32_t last_data_time_ms
XPlane(const char *home_str, const char *frame_str)
static bool set_default_by_name(const char *name, float value)
const float throttle_magic