mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-26 01:33:56 -04:00
AP_HAL_SITL: read all available SITL RC input packets
MAVProxy runs on its own clock. While our clock is stopped for whatever reason MAVProxy will continue to send RC input. This patch always gives us the most recent RC input from MAVProxy. Also add sanity check on packet received
This commit is contained in:
parent
4d0ae8c371
commit
80e8f9cdd8
@ -229,13 +229,26 @@ int SITL_State::sim_fd(const char *name, const char *arg)
|
||||
*/
|
||||
void SITL_State::_check_rc_input(void)
|
||||
{
|
||||
ssize_t size;
|
||||
uint32_t count = 0;
|
||||
while (_read_rc_sitl_input()) {
|
||||
count++;
|
||||
}
|
||||
|
||||
if (count > 100) {
|
||||
::fprintf(stderr, "Read %u rc inputs\n", count);
|
||||
}
|
||||
}
|
||||
|
||||
bool SITL_State::_read_rc_sitl_input()
|
||||
{
|
||||
struct pwm_packet {
|
||||
uint16_t pwm[16];
|
||||
} pwm_pkt;
|
||||
|
||||
size = _sitl_rc_in.recv(&pwm_pkt, sizeof(pwm_pkt), 0);
|
||||
const ssize_t size = _sitl_rc_in.recv(&pwm_pkt, sizeof(pwm_pkt), 0);
|
||||
switch (size) {
|
||||
case -1:
|
||||
return false;
|
||||
case 8*2:
|
||||
case 16*2: {
|
||||
// a packet giving the receiver PWM inputs
|
||||
@ -259,9 +272,12 @@ void SITL_State::_check_rc_input(void)
|
||||
pwm_input[i] = pwm;
|
||||
}
|
||||
}
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
fprintf(stderr, "Malformed SITL RC input (%li)", size);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -133,6 +133,7 @@ private:
|
||||
void _update_airspeed(float airspeed);
|
||||
void _update_gps_instance(SITL::SITL::GPSType gps_type, const struct gps_data *d, uint8_t instance);
|
||||
void _check_rc_input(void);
|
||||
bool _read_rc_sitl_input();
|
||||
void _fdm_input_local(void);
|
||||
void _output_to_flightgear(void);
|
||||
void _simulator_servos(struct sitl_input &input);
|
||||
|
Loading…
Reference in New Issue
Block a user