Skip to content

Commit 8a25c29

Browse files
committed
autotest: add a WaitAndMaintainAttitude method
.... so we can have minimum_duration which wait_attitude does not
1 parent b996deb commit 8a25c29

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

Tools/autotest/arducopter.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from vehicle_test_suite import Test
3131
from vehicle_test_suite import MAV_POS_TARGET_TYPE_MASK
3232
from vehicle_test_suite import WaitAndMaintainArmed
33+
from vehicle_test_suite import WaitAndMaintainAttitude
3334
from vehicle_test_suite import WaitModeTimeout
3435

3536
from pymavlink.rotmat import Vector3, Matrix3
@@ -15122,6 +15123,36 @@ def verify_yaw(mav, m):
1512215123
self.arm_vehicle()
1512315124
self.wait_disarmed()
1512415125

15126+
def WaitAndMaintainAttitude_RCFlight(self):
15127+
'''just test WaitAndMaintainAttitude works'''
15128+
WaitAndMaintainAttitude(self, 0, 0, epsilon=1).run()
15129+
self.takeoff(20, mode='LOITER')
15130+
15131+
WaitAndMaintainAttitude(self, 0, 0, epsilon=1).run()
15132+
15133+
self.start_subtest("Full forward stick")
15134+
self.set_rc(2, 1000)
15135+
WaitAndMaintainAttitude(self, 0, -30, epsilon=1, minimum_duration=10, timeout=60).run()
15136+
15137+
self.start_subtest("Full left stick")
15138+
self.set_rc(2, 1500)
15139+
self.set_rc(1, 1000)
15140+
WaitAndMaintainAttitude(self, -30, 0, epsilon=1).run()
15141+
15142+
self.start_subtest("Circular angle")
15143+
self.set_rc(2, 1000)
15144+
self.set_rc(1, 1000)
15145+
# this is some sort of circular-angle shenanigans / frame
15146+
# translation weirdness:
15147+
WaitAndMaintainAttitude(self, -20, -23, epsilon=1, timeout=120).run()
15148+
15149+
self.start_subtest("Center the sticks")
15150+
self.set_rc(2, 1500)
15151+
self.set_rc(1, 1500)
15152+
WaitAndMaintainAttitude(self, 0, 0, epsilon=1).run()
15153+
15154+
self.do_RTL()
15155+
1512515156
def LuaParamSet(self):
1512615157
'''test param-set.lua applet'''
1512715158
self.set_parameters({
@@ -15705,6 +15736,7 @@ def tests2b(self): # this block currently around 9.5mins here
1570515736
self.IMUConsistency,
1570615737
self.AHRSTrimLand,
1570715738
self.IBus,
15739+
self.WaitAndMaintainAttitude_RCFlight,
1570815740
self.GuidedYawRate,
1570915741
self.RudderDisarmMidair,
1571015742
self.NoArmWithoutMissionItems,

Tools/autotest/vehicle_test_suite.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,66 @@ def get_current_value(self):
728728
return m_value
729729

730730

731+
class WaitAndMaintainAttitude(WaitAndMaintain):
732+
def __init__(self, test_suite, desroll=None, despitch=None, **kwargs):
733+
super().__init__(test_suite, **kwargs)
734+
self.desroll = desroll
735+
self.despitch = despitch
736+
737+
if self.desroll is None and self.despitch is None:
738+
raise ValueError("despitch or desroll must be supplied")
739+
740+
def announce_start_text(self):
741+
conditions = []
742+
if self.desroll is not None:
743+
conditions.append(f"roll={self.desroll}")
744+
if self.despitch is not None:
745+
conditions.append(f"pitch={self.despitch}")
746+
747+
return f"Waiting for {' and '.join(conditions)}"
748+
749+
def get_target_value(self):
750+
return (self.desroll, self.despitch)
751+
752+
def get_current_value(self):
753+
m = self.test_suite.assert_receive_message('ATTITUDE', timeout=10)
754+
self.last_ATTITUDE = m
755+
return (math.degrees(m.roll), math.degrees(m.pitch))
756+
757+
def validate_value(self, value):
758+
(candidate_roll, candidate_pitch) = value
759+
760+
if self.desroll is not None:
761+
roll_error = abs(self.desroll - candidate_roll)
762+
if roll_error > self.epsilon:
763+
return False
764+
765+
if self.despitch is not None:
766+
pitch_error = abs(self.despitch - candidate_pitch)
767+
if pitch_error > self.epsilon:
768+
return False
769+
770+
return True
771+
772+
def success_text(self):
773+
return "Attained attitude"
774+
775+
def timeoutexception(self):
776+
return AutoTestTimeoutException("Failed to attain attitude")
777+
778+
def progress_text(self, current_value):
779+
(achieved_roll, achieved_pitch) = current_value
780+
axis_progress = []
781+
782+
if self.desroll is not None:
783+
axis_progress.append(f"r={achieved_roll:.03} des-r={self.desroll}")
784+
785+
if self.despitch is not None:
786+
axis_progress.append(f"p={achieved_pitch:.3} des-p={self.despitch}")
787+
788+
return " ".join(axis_progress)
789+
790+
731791
class MSP_Generic(Telem):
732792
def __init__(self, destination_address):
733793
super(MSP_Generic, self).__init__(destination_address)

0 commit comments

Comments
 (0)