From e9552ec4e1172e636cf4cc2f2b58ea5de9f22b60 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Sat, 1 Jun 2019 20:53:05 +1000 Subject: [PATCH] Tools: autotest: more efficient set_rc_from_map --- Tools/autotest/common.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Tools/autotest/common.py b/Tools/autotest/common.py index ed20868de7..31f31e5e88 100644 --- a/Tools/autotest/common.py +++ b/Tools/autotest/common.py @@ -740,11 +740,23 @@ class AutoTest(ABC): 16: 1500, } - def set_rc_from_map(self, _map): - for chan in _map: - value = _map[chan] - self.set_rc(chan, value) -# self.mavproxy.send('rc %u value\n' % (chan, value)) + def set_rc_from_map(self, _map, timeout=2000): + copy = _map.copy() + tstart = self.get_sim_time() + while len(copy.keys()): + if self.get_sim_time_cached() - tstart > timeout: + raise SetRCTimeout("Failed to set RC channels") + for chan in copy: + value = copy[chan] + self.send_set_rc(chan, value) + m = self.mav.recv_match(type='RC_CHANNELS', blocking=True) + self.progress("m: %s" % m) + new = dict() + for chan in copy: + chan_pwm = getattr(m, "chan" + str(chan) + "_raw") + if chan_pwm != copy[chan]: + new[chan] = copy[chan] + copy = new def set_rc_default(self): """Setup all simulated RC control to 1500."""