Browse Source

autotest: Python correctness fixes

Tools: common: correct copy shadowing in set_rc_from_map

Tools: common: comment out unused code

Tools: common: remove iteritem usage for py3

Tools: common: remove duplicate key in FRSkySPort id description for GPS

Tools: rover: correct type shadowing

Tools: rover: make expected_distance_epsilon float

Tools: rover: comment out unused code

Tools: rover: correct variable shadowing on my_message_hook

Tools: copter: correct variable shadowing

Tools: common: use Bool for port.setblocking

Tools: common: fix variable shadowing
zr-v5.1
Pierre Kancir 5 years ago committed by Peter Barker
parent
commit
e1d8148cc0
  1. 32
      Tools/autotest/apmrover2.py
  2. 4
      Tools/autotest/arducopter.py
  3. 55
      Tools/autotest/common.py

32
Tools/autotest/apmrover2.py

@ -1128,11 +1128,11 @@ Brakes have negligible effect (with=%0.2fm without=%0.2fm delta=%0.2fm) @@ -1128,11 +1128,11 @@ Brakes have negligible effect (with=%0.2fm without=%0.2fm delta=%0.2fm)
check_atts = ['mission_type', 'command', 'x', 'y', 'z', 'seq', 'param1']
return self.check_mission_items_same(check_atts, want, got, skip_first_item=True)
def check_mission_item_upload_download(self, items, type, mission_type):
def check_mission_item_upload_download(self, items, itype, mission_type):
self.progress("check %s _upload/download: upload %u items" %
(type, len(items),))
(itype, len(items),))
self.upload_using_mission_protocol(mission_type, items)
self.progress("check %s upload/download: download items" % type)
self.progress("check %s upload/download: download items" % itype)
downloaded_items = self.download_using_mission_protocol(mission_type)
self.progress("Downloaded items: (%s)" % str(downloaded_items))
if len(items) != len(downloaded_items):
@ -3504,7 +3504,7 @@ Brakes have negligible effect (with=%0.2fm without=%0.2fm delta=%0.2fm) @@ -3504,7 +3504,7 @@ Brakes have negligible effect (with=%0.2fm without=%0.2fm delta=%0.2fm)
def drive_somewhere_stop_at_boundary(self,
loc,
expected_stopping_point,
expected_distance_epsilon=1,
expected_distance_epsilon=1.0,
target_system=1,
target_component=1,
timeout=120):
@ -4323,9 +4323,9 @@ Brakes have negligible effect (with=%0.2fm without=%0.2fm delta=%0.2fm) @@ -4323,9 +4323,9 @@ Brakes have negligible effect (with=%0.2fm without=%0.2fm delta=%0.2fm)
target_component=target_component)
return
# twosquares is currently disabled because of the requirement to have an inclusion fence (which it doesn't have ATM)
self.test_poly_fence_object_avoidance_guided_two_squares(
target_system=target_system,
target_component=target_component)
# self.test_poly_fence_object_avoidance_guided_two_squares(
# target_system=target_system,
# target_component=target_component)
def test_poly_fence_object_avoidance_auto(self, target_system=1, target_component=1):
self.load_fence("rover-path-planning-fence.txt")
@ -4714,10 +4714,10 @@ Brakes have negligible effect (with=%0.2fm without=%0.2fm delta=%0.2fm) @@ -4714,10 +4714,10 @@ Brakes have negligible effect (with=%0.2fm without=%0.2fm delta=%0.2fm)
ex = None
example_script = "simple_loop.lua"
messages = []
def my_message_hook(mav, m):
if m.get_type() != 'STATUSTEXT':
def my_message_hook(mav, message):
if message.get_type() != 'STATUSTEXT':
return
messages.append(m)
messages.append(message)
self.install_message_hook(my_message_hook)
try:
self.set_parameter("SCR_ENABLE", 1)
@ -4748,10 +4748,10 @@ Brakes have negligible effect (with=%0.2fm without=%0.2fm delta=%0.2fm) @@ -4748,10 +4748,10 @@ Brakes have negligible effect (with=%0.2fm without=%0.2fm delta=%0.2fm)
ex = None
example_script = "scripting_test.lua"
messages = []
def my_message_hook(mav, m):
if m.get_type() != 'STATUSTEXT':
def my_message_hook(mav, message):
if message.get_type() != 'STATUSTEXT':
return
messages.append(m)
messages.append(message)
self.install_message_hook(my_message_hook)
try:
self.set_parameter("SCR_ENABLE", 1)
@ -4783,10 +4783,10 @@ Brakes have negligible effect (with=%0.2fm without=%0.2fm delta=%0.2fm) @@ -4783,10 +4783,10 @@ Brakes have negligible effect (with=%0.2fm without=%0.2fm delta=%0.2fm)
ex = None
example_script = "hello_world.lua"
messages = []
def my_message_hook(mav, m):
if m.get_type() != 'STATUSTEXT':
def my_message_hook(mav, message):
if message.get_type() != 'STATUSTEXT':
return
messages.append(m)
messages.append(message)
self.install_message_hook(my_message_hook)
try:
self.set_parameter("SCR_ENABLE", 1)

4
Tools/autotest/arducopter.py

@ -4126,9 +4126,9 @@ class AutoTestCopter(AutoTest): @@ -4126,9 +4126,9 @@ class AutoTestCopter(AutoTest):
if ex is not None:
raise ex
def global_position_int_for_location(self, loc, time, heading=0):
def global_position_int_for_location(self, loc, time_boot, heading=0):
return self.mav.mav.global_position_int_encode(
int(time * 1000), # time_boot_ms
int(time_boot * 1000), # time_boot_ms
int(loc.lat * 1e7),
int(loc.lng * 1e7),
int(loc.alt * 1000), # alt in mm

55
Tools/autotest/common.py

@ -185,7 +185,7 @@ class Telem(object): @@ -185,7 +185,7 @@ class Telem(object):
pass
self.port = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.port.connect(self.destination_address)
self.port.setblocking(0)
self.port.setblocking(False)
self.port.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1)
self.connected = True
self.progress("Connected")
@ -495,8 +495,7 @@ class FRSkySPort(FRSky): @@ -495,8 +495,7 @@ class FRSkySPort(FRSky):
self.id_descriptions = {
0x5000: "status text (dynamic)",
0x5006: "Attitude and range (dynamic)",
0x800: "GPS lat (600 with 1 sensor)",
0x800: "GPS lon (600 with 1 sensor)",
0x800: "GPS lat or lon (600 with 1 sensor)",
0x5005: "Vel and Yaw",
0x5001: "AP status",
0x5002: "GPS Status",
@ -513,7 +512,7 @@ class FRSkySPort(FRSky): @@ -513,7 +512,7 @@ class FRSkySPort(FRSky):
0x21: "BARO_ALT_AP",
0x30: "VARIO",
0x39: "VFAS",
0x800: "GPS",
# 0x800: "GPS", ## comments as duplicated dictrionary key
}
self.sensors_to_poll = [
@ -1530,22 +1529,22 @@ class AutoTest(ABC): @@ -1530,22 +1529,22 @@ class AutoTest(ABC):
}
def set_rc_from_map(self, _map, timeout=2000):
copy = _map.copy()
map_copy = _map.copy()
tstart = self.get_sim_time()
while len(copy.keys()):
while len(map_copy.keys()):
if self.get_sim_time_cached() - tstart > timeout:
raise SetRCTimeout("Failed to set RC channels")
for chan in copy:
value = copy[chan]
for chan in map_copy:
value = map_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:
for chan in map_copy:
chan_pwm = getattr(m, "chan" + str(chan) + "_raw")
if chan_pwm != copy[chan]:
new[chan] = copy[chan]
copy = new
if chan_pwm != map_copy[chan]:
new[chan] = map_copy[chan]
map_copy = new
def set_rc_default(self):
"""Setup all simulated RC control to 1500."""
@ -2097,13 +2096,13 @@ class AutoTest(ABC): @@ -2097,13 +2096,13 @@ class AutoTest(ABC):
mavutil.location(loc1_lat*1e-7, loc1_lon*1e-7),
mavutil.location(loc2_lat*1e-7, loc2_lon*1e-7))
dlat = loc2_lat - loc1_lat
dlong = loc2_lon - loc1_lon
dlat /= 10000000.0
dlong /= 10000000.0
return math.sqrt((dlat*dlat) + (dlong*dlong)) * 1.113195e5
# dlat = loc2_lat - loc1_lat
# dlong = loc2_lon - loc1_lon
#
# dlat /= 10000000.0
# dlong /= 10000000.0
#
# return math.sqrt((dlat*dlat) + (dlong*dlong)) * 1.113195e5
@staticmethod
def get_bearing(loc1, loc2):
@ -2791,8 +2790,8 @@ class AutoTest(ABC): @@ -2791,8 +2790,8 @@ class AutoTest(ABC):
for desc in self.test_timings.keys():
if len(desc) > longest:
longest = len(desc)
for desc, test_time in sorted(self.test_timings.iteritems(),
key=self.show_test_timings_key_sorter):
for desc, test_time in sorted(self.test_timings.items(),
key=self.show_test_timings_key_sorter):
fmt = "%" + str(longest) + "s: %.2fs"
self.progress(fmt % (desc, test_time))
@ -4605,16 +4604,16 @@ switch value''' @@ -4605,16 +4604,16 @@ switch value'''
# This, at least makes sure we're getting some of each
# message. These are ordered according to the wfq scheduler
wants = {
0x5000: lambda x : True,
0x5006: lambda x : True,
0x800: lambda x : True,
0x5000: lambda xx : True,
0x5006: lambda xx : True,
0x800: lambda xx : True,
0x5005: self.tfp_validate_vel_and_yaw,
0x5001: lambda x : True,
0x5002: lambda x : True,
0x5004: lambda x : True,
0x5001: lambda xx : True,
0x5002: lambda xx : True,
0x5004: lambda xx : True,
# 0x5008: lambda x : True, # no second battery, so this doesn't arrive
0x5003: self.tfp_validate_battery1,
0x5007: lambda x : True,
0x5007: lambda xx : True,
}
tstart = self.get_sim_time_cached()
while len(wants):

Loading…
Cancel
Save