Skip to content

Commit

Permalink
autotest: add test for compass_learn=3 when using gps-for-yaw
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker committed Apr 11, 2024
1 parent 563d31b commit c578a18
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 66 deletions.
30 changes: 30 additions & 0 deletions Tools/autotest/arducopter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9331,6 +9331,34 @@ def GPSForYaw(self):
if ex is not None:
raise ex

def GPSForYawCompassLearn(self):
'''Moving baseline GPS yaw - with compass learning'''
self.context_push()
self.load_default_params_file("copter-gps-for-yaw.parm")
self.set_parameter("EK3_SRC1_YAW", 3) # GPS with compass fallback
self.reboot_sitl()

self.wait_gps_fix_type_gte(6, message_type="GPS2_RAW", verbose=True)

self.wait_ready_to_arm()

self.takeoff(10, mode='GUIDED')
tstart = self.get_sim_time()
compass_learn_set = False
while True:
delta_t = self.get_sim_time_cached() - tstart
if delta_t > 30:
break
if not compass_learn_set and delta_t > 10:
self.set_parameter("COMPASS_LEARN", 3)
compass_learn_set = True

self.check_attitudes_match()
self.delay_sim_time(1)

self.context_pop()
self.reboot_sitl()

def AP_Avoidance(self):
'''ADSB-based avoidance'''
self.set_parameters({
Expand Down Expand Up @@ -10831,6 +10859,7 @@ def tests2b(self): # this block currently around 9.5mins here
self.MAV_CMD_NAV_TAKEOFF_command_int,
self.Ch6TuningWPSpeed,
self.PILOT_THR_BHV,
self.GPSForYawCompassLearn,
])
return ret

Expand Down Expand Up @@ -10860,6 +10889,7 @@ def disabled_tests(self):
"GroundEffectCompensation_takeOffExpected": "Flapping",
"GroundEffectCompensation_touchDownExpected": "Flapping",
"FlyMissionTwice": "See https://github.com/ArduPilot/ardupilot/pull/18561",
"GPSForYawCompassLearn": "Vehicle currently crashed in spectacular fashion",
}


Expand Down
67 changes: 1 addition & 66 deletions Tools/autotest/arduplane.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import time

from pymavlink import quaternion
from pymavlink import mavextra
from pymavlink import mavutil

from pymavlink.rotmat import Vector3
Expand Down Expand Up @@ -2005,70 +2004,6 @@ def run_subtest(self, desc, func):
self.start_subtest(desc)
func()

def check_attitudes_match(self, a, b):
'''make sure ahrs2 and simstate and ATTTIUDE_QUATERNION all match'''

# these are ordered to bookend the list with timestamps (which
# both attitude messages have):
get_names = ['ATTITUDE', 'SIMSTATE', 'AHRS2', 'ATTITUDE_QUATERNION']
msgs = self.get_messages_frame(get_names)

for get_name in get_names:
self.progress("%s: %s" % (get_name, msgs[get_name]))

simstate = msgs['SIMSTATE']
attitude = msgs['ATTITUDE']
ahrs2 = msgs['AHRS2']
attitude_quaternion = msgs['ATTITUDE_QUATERNION']

# check ATTITUDE
want = math.degrees(simstate.roll)
got = math.degrees(attitude.roll)
if abs(mavextra.angle_diff(want, got)) > 20:
raise NotAchievedException("ATTITUDE.Roll looks bad (want=%f got=%f)" %
(want, got))
want = math.degrees(simstate.pitch)
got = math.degrees(attitude.pitch)
if abs(mavextra.angle_diff(want, got)) > 20:
raise NotAchievedException("ATTITUDE.Pitch looks bad (want=%f got=%f)" %
(want, got))

# check AHRS2
want = math.degrees(simstate.roll)
got = math.degrees(ahrs2.roll)
if abs(mavextra.angle_diff(want, got)) > 20:
raise NotAchievedException("AHRS2.Roll looks bad (want=%f got=%f)" %
(want, got))

want = math.degrees(simstate.pitch)
got = math.degrees(ahrs2.pitch)
if abs(mavextra.angle_diff(want, got)) > 20:
raise NotAchievedException("AHRS2.Pitch looks bad (want=%f got=%f)" %
(want, got))

# check ATTITUDE_QUATERNION
q = quaternion.Quaternion([
attitude_quaternion.q1,
attitude_quaternion.q2,
attitude_quaternion.q3,
attitude_quaternion.q4
])
euler = q.euler
self.progress("attquat:%s q:%s euler:%s" % (
str(attitude_quaternion), q, euler))

want = math.degrees(simstate.roll)
got = math.degrees(euler[0])
if mavextra.angle_diff(want, got) > 20:
raise NotAchievedException("quat roll differs from attitude roll; want=%f got=%f" %
(want, got))

want = math.degrees(simstate.pitch)
got = math.degrees(euler[1])
if mavextra.angle_diff(want, got) > 20:
raise NotAchievedException("quat pitch differs from attitude pitch; want=%f got=%f" %
(want, got))

def fly_ahrs2_test(self):
'''check secondary estimator is looking OK'''

Expand All @@ -2089,7 +2024,7 @@ def fly_ahrs2_test(self):
if self.get_distance_int(gpi, ahrs2) > 10:
raise NotAchievedException("Secondary location looks bad")

self.check_attitudes_match(1, 2)
self.check_attitudes_match()

def MainFlight(self):
'''Lots of things in one flight'''
Expand Down
64 changes: 64 additions & 0 deletions Tools/autotest/vehicle_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -13675,6 +13675,70 @@ def assert_gps_satellite_count(self, messagename, count):
raise NotAchievedException("Expected %u sats, got %u" %
(count, m.satellites_visible))

def check_attitudes_match(self):
'''make sure ahrs2 and simstate and ATTTIUDE_QUATERNION all match'''

# these are ordered to bookend the list with timestamps (which
# both attitude messages have):
get_names = ['ATTITUDE', 'SIMSTATE', 'AHRS2', 'ATTITUDE_QUATERNION']
msgs = self.get_messages_frame(get_names)

for get_name in get_names:
self.progress("%s: %s" % (get_name, msgs[get_name]))

simstate = msgs['SIMSTATE']
attitude = msgs['ATTITUDE']
ahrs2 = msgs['AHRS2']
attitude_quaternion = msgs['ATTITUDE_QUATERNION']

# check ATTITUDE
want = math.degrees(simstate.roll)
got = math.degrees(attitude.roll)
if abs(mavextra.angle_diff(want, got)) > 20:
raise NotAchievedException("ATTITUDE.Roll looks bad (want=%f got=%f)" %
(want, got))
want = math.degrees(simstate.pitch)
got = math.degrees(attitude.pitch)
if abs(mavextra.angle_diff(want, got)) > 20:
raise NotAchievedException("ATTITUDE.Pitch looks bad (want=%f got=%f)" %
(want, got))

# check AHRS2
want = math.degrees(simstate.roll)
got = math.degrees(ahrs2.roll)
if abs(mavextra.angle_diff(want, got)) > 20:
raise NotAchievedException("AHRS2.Roll looks bad (want=%f got=%f)" %
(want, got))

want = math.degrees(simstate.pitch)
got = math.degrees(ahrs2.pitch)
if abs(mavextra.angle_diff(want, got)) > 20:
raise NotAchievedException("AHRS2.Pitch looks bad (want=%f got=%f)" %
(want, got))

# check ATTITUDE_QUATERNION
q = quaternion.Quaternion([
attitude_quaternion.q1,
attitude_quaternion.q2,
attitude_quaternion.q3,
attitude_quaternion.q4
])
euler = q.euler
self.progress("attquat:%s q:%s euler:%s" % (
str(attitude_quaternion), q, euler))

want = math.degrees(simstate.roll)
got = math.degrees(euler[0])
if mavextra.angle_diff(want, got) > 20:
raise NotAchievedException("quat roll differs from attitude roll; want=%f got=%f" %
(want, got))

want = math.degrees(simstate.pitch)
got = math.degrees(euler[1])
if mavextra.angle_diff(want, got) > 20:
raise NotAchievedException("quat pitch differs from attitude pitch; want=%f got=%f" %
(want, got))

def MultipleGPS(self):
'''check ArduPilot behaviour across multiple GPS units'''
self.assert_message_rate_hz('GPS2_RAW', 0)
Expand Down

0 comments on commit c578a18

Please sign in to comment.