2017-02-21 13:32:26 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
# Fly ArduPlane in SITL
|
2016-11-08 07:06:05 -04:00
|
|
|
from __future__ import print_function
|
2016-07-31 07:22:06 -03:00
|
|
|
import math
|
|
|
|
import os
|
|
|
|
|
2018-05-31 07:27:41 -03:00
|
|
|
from pymavlink import quaternion
|
2013-06-18 03:27:21 -03:00
|
|
|
from pymavlink import mavutil
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
from common import AutoTest
|
2018-11-09 08:32:02 -04:00
|
|
|
from common import AutoTestTimeoutException
|
2018-04-27 15:21:53 -03:00
|
|
|
from common import NotAchievedException
|
2018-08-03 07:50:15 -03:00
|
|
|
from common import PreconditionFailedException
|
2018-03-14 08:08:53 -03:00
|
|
|
|
2011-11-12 07:13:17 -04:00
|
|
|
# get location of scripts
|
2016-07-31 07:22:06 -03:00
|
|
|
testdir = os.path.dirname(os.path.realpath(__file__))
|
2019-02-15 20:46:33 -04:00
|
|
|
SITL_START_LOCATION = mavutil.location(-35.362938, 149.165085, 585, 354)
|
2016-07-31 07:22:06 -03:00
|
|
|
WIND = "0,180,0.2" # speed,direction,variance
|
2011-11-12 07:13:17 -04:00
|
|
|
|
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
class AutoTestPlane(AutoTest):
|
2018-10-10 10:06:01 -03:00
|
|
|
@staticmethod
|
|
|
|
def get_not_armable_mode_list():
|
|
|
|
return []
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_not_disarmed_settable_modes_list():
|
|
|
|
return ["FOLLOW"]
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_no_position_not_settable_modes_list():
|
|
|
|
return []
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_position_armable_modes_list():
|
|
|
|
return ["GUIDED", "AUTO"]
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_normal_armable_modes_list():
|
|
|
|
return ["MANUAL", "STABILIZE", "ACRO"]
|
2019-03-09 00:20:36 -04:00
|
|
|
|
|
|
|
def log_name(self):
|
|
|
|
return "ArduPlane"
|
|
|
|
|
|
|
|
def test_filepath(self):
|
|
|
|
return os.path.realpath(__file__)
|
2018-03-15 08:54:34 -03:00
|
|
|
|
2019-02-15 20:46:33 -04:00
|
|
|
def sitl_start_location(self):
|
|
|
|
return SITL_START_LOCATION
|
|
|
|
|
2019-03-09 00:20:36 -04:00
|
|
|
def defaults_filepath(self):
|
|
|
|
return os.path.join(testdir, 'default_params/plane-jsbsim.parm')
|
|
|
|
|
|
|
|
def default_frame(self):
|
|
|
|
return "plane-elevrev"
|
|
|
|
|
|
|
|
def apply_defaultfile_parameters(self):
|
|
|
|
# plane passes in a defaults_file in place of applying
|
|
|
|
# parameters afterwards.
|
|
|
|
pass
|
2018-03-05 11:14:34 -04:00
|
|
|
|
2018-10-10 10:07:21 -03:00
|
|
|
def is_plane(self):
|
|
|
|
return True
|
|
|
|
|
2019-03-26 09:17:11 -03:00
|
|
|
def get_stick_arming_channel(self):
|
2018-10-10 10:07:21 -03:00
|
|
|
return int(self.get_parameter("RCMAP_YAW"))
|
|
|
|
|
|
|
|
def get_disarm_delay(self):
|
|
|
|
return int(self.get_parameter("LAND_DISARMDELAY"))
|
|
|
|
|
|
|
|
def set_autodisarm_delay(self, delay):
|
|
|
|
self.set_parameter("LAND_DISARMDELAY", delay)
|
|
|
|
|
2018-10-10 10:06:01 -03:00
|
|
|
def arming_test_mission(self):
|
|
|
|
return os.path.join(testdir, "ArduPlane-Missions", "test_arming.txt")
|
|
|
|
|
2019-04-25 21:57:19 -03:00
|
|
|
def takeoff(self, alt=150, alt_max=None, relative=True):
|
|
|
|
"""Takeoff to altitude."""
|
|
|
|
|
|
|
|
if alt_max is None:
|
|
|
|
alt_max = alt + 30
|
2018-03-05 11:14:34 -04:00
|
|
|
|
2019-09-24 23:25:55 -03:00
|
|
|
self.change_mode("FBWA")
|
2018-03-05 11:14:34 -04:00
|
|
|
|
2018-08-13 08:07:34 -03:00
|
|
|
self.wait_ready_to_arm()
|
|
|
|
self.arm_vehicle()
|
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
# some rudder to counteract the prop torque
|
|
|
|
self.set_rc(4, 1700)
|
|
|
|
|
|
|
|
# some up elevator to keep the tail down
|
|
|
|
self.set_rc(2, 1200)
|
|
|
|
|
|
|
|
# get it moving a bit first
|
|
|
|
self.set_rc(3, 1300)
|
2019-02-21 23:51:05 -04:00
|
|
|
self.wait_groundspeed(6, 100)
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
# a bit faster again, straighten rudder
|
|
|
|
self.set_rc(3, 1600)
|
|
|
|
self.set_rc(4, 1500)
|
2019-02-21 23:51:05 -04:00
|
|
|
self.wait_groundspeed(12, 100)
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
# hit the gas harder now, and give it some more elevator
|
|
|
|
self.set_rc(2, 1100)
|
|
|
|
self.set_rc(3, 2000)
|
|
|
|
|
|
|
|
# gain a bit of altitude
|
2019-04-25 21:57:19 -03:00
|
|
|
self.wait_altitude(alt, alt_max, timeout=30, relative=relative)
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
# level off
|
|
|
|
self.set_rc(2, 1500)
|
2013-07-16 00:23:48 -03:00
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("TAKEOFF COMPLETE")
|
2013-07-16 00:23:48 -03:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
def fly_left_circuit(self):
|
|
|
|
"""Fly a left circuit, 200m on a side."""
|
|
|
|
self.mavproxy.send('switch 4\n')
|
|
|
|
self.wait_mode('FBWA')
|
|
|
|
self.set_rc(3, 2000)
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_level_flight()
|
2018-03-14 08:08:53 -03:00
|
|
|
|
|
|
|
self.progress("Flying left circuit")
|
2018-03-05 11:14:34 -04:00
|
|
|
# do 4 turns
|
|
|
|
for i in range(0, 4):
|
|
|
|
# hard left
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting turn %u" % i)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(1, 1000)
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_heading(270 - (90*i), accuracy=10)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(1, 1500)
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting leg %u" % i)
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_distance(100, accuracy=20)
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Circuit complete")
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
def fly_RTL(self):
|
|
|
|
"""Fly to home."""
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Flying home in RTL")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.mavproxy.send('switch 2\n')
|
|
|
|
self.wait_mode('RTL')
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_location(self.homeloc,
|
2018-05-09 00:32:23 -03:00
|
|
|
accuracy=120,
|
|
|
|
target_altitude=self.homeloc.alt+100,
|
|
|
|
height_accuracy=20,
|
|
|
|
timeout=180)
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("RTL Complete")
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
def fly_LOITER(self, num_circles=4):
|
|
|
|
"""Loiter where we are."""
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Testing LOITER for %u turns" % num_circles)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.mavproxy.send('loiter\n')
|
|
|
|
self.wait_mode('LOITER')
|
|
|
|
|
|
|
|
m = self.mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
initial_alt = m.alt
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Initial altitude %u\n" % initial_alt)
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
while num_circles > 0:
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_heading(0, accuracy=10, timeout=60)
|
|
|
|
self.wait_heading(180, accuracy=10, timeout=60)
|
2018-03-05 11:14:34 -04:00
|
|
|
num_circles -= 1
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Loiter %u circles left" % num_circles)
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
m = self.mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
final_alt = m.alt
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Final altitude %u initial %u\n" %
|
|
|
|
(final_alt, initial_alt))
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
self.mavproxy.send('mode FBWA\n')
|
|
|
|
self.wait_mode('FBWA')
|
|
|
|
|
|
|
|
if abs(final_alt - initial_alt) > 20:
|
2018-10-17 23:55:16 -03:00
|
|
|
raise NotAchievedException("Failed to maintain altitude")
|
2013-07-16 00:23:48 -03:00
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Completed Loiter OK")
|
2013-07-16 00:23:48 -03:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
def fly_CIRCLE(self, num_circles=1):
|
|
|
|
"""Circle where we are."""
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Testing CIRCLE for %u turns" % num_circles)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.mavproxy.send('mode CIRCLE\n')
|
|
|
|
self.wait_mode('CIRCLE')
|
2013-07-16 00:23:48 -03:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
m = self.mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
initial_alt = m.alt
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Initial altitude %u\n" % initial_alt)
|
2013-07-16 00:23:48 -03:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
while num_circles > 0:
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_heading(0, accuracy=10, timeout=60)
|
|
|
|
self.wait_heading(180, accuracy=10, timeout=60)
|
2018-03-05 11:14:34 -04:00
|
|
|
num_circles -= 1
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("CIRCLE %u circles left" % num_circles)
|
2011-11-12 07:13:17 -04:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
m = self.mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
final_alt = m.alt
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Final altitude %u initial %u\n" %
|
|
|
|
(final_alt, initial_alt))
|
2011-11-12 07:13:17 -04:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
self.mavproxy.send('mode FBWA\n')
|
|
|
|
self.wait_mode('FBWA')
|
2011-11-12 07:13:17 -04:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
if abs(final_alt - initial_alt) > 20:
|
2018-10-17 23:55:16 -03:00
|
|
|
raise NotAchievedException("Failed to maintain altitude")
|
2011-11-13 21:59:59 -04:00
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Completed CIRCLE OK")
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
def wait_level_flight(self, accuracy=5, timeout=30):
|
|
|
|
"""Wait for level flight."""
|
|
|
|
tstart = self.get_sim_time()
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Waiting for level flight")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(1, 1500)
|
|
|
|
self.set_rc(2, 1500)
|
|
|
|
self.set_rc(4, 1500)
|
2019-03-07 18:34:09 -04:00
|
|
|
while self.get_sim_time_cached() < tstart + timeout:
|
2018-03-05 11:14:34 -04:00
|
|
|
m = self.mav.recv_match(type='ATTITUDE', blocking=True)
|
|
|
|
roll = math.degrees(m.roll)
|
|
|
|
pitch = math.degrees(m.pitch)
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Roll=%.1f Pitch=%.1f" % (roll, pitch))
|
2018-03-05 11:14:34 -04:00
|
|
|
if math.fabs(roll) <= accuracy and math.fabs(pitch) <= accuracy:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Attained level flight")
|
2018-04-27 15:21:53 -03:00
|
|
|
return
|
2018-10-17 23:55:16 -03:00
|
|
|
raise NotAchievedException("Failed to attain level flight")
|
2011-11-13 21:59:59 -04:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
def change_altitude(self, altitude, accuracy=30):
|
|
|
|
"""Get to a given altitude."""
|
|
|
|
self.mavproxy.send('mode FBWA\n')
|
|
|
|
self.wait_mode('FBWA')
|
|
|
|
alt_error = self.mav.messages['VFR_HUD'].alt - altitude
|
|
|
|
if alt_error > 0:
|
|
|
|
self.set_rc(2, 2000)
|
|
|
|
else:
|
|
|
|
self.set_rc(2, 1000)
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_altitude(altitude-accuracy/2, altitude+accuracy/2)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(2, 1500)
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Reached target altitude at %u" %
|
|
|
|
self.mav.messages['VFR_HUD'].alt)
|
2018-03-05 11:14:34 -04:00
|
|
|
return self.wait_level_flight()
|
|
|
|
|
|
|
|
def axial_left_roll(self, count=1):
|
|
|
|
"""Fly a left axial roll."""
|
|
|
|
# full throttle!
|
|
|
|
self.set_rc(3, 2000)
|
2018-04-27 15:21:53 -03:00
|
|
|
self.change_altitude(self.homeloc.alt+300)
|
2013-07-16 00:23:48 -03:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
# fly the roll in manual
|
|
|
|
self.mavproxy.send('switch 6\n')
|
|
|
|
self.wait_mode('MANUAL')
|
|
|
|
|
|
|
|
while count > 0:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting roll")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(1, 1000)
|
2018-04-27 15:21:53 -03:00
|
|
|
try:
|
|
|
|
self.wait_roll(-150, accuracy=90)
|
|
|
|
self.wait_roll(150, accuracy=90)
|
|
|
|
self.wait_roll(0, accuracy=90)
|
|
|
|
except Exception as e:
|
2018-05-09 00:32:23 -03:00
|
|
|
self.set_rc(1, 1500)
|
2018-04-27 15:21:53 -03:00
|
|
|
raise e
|
2018-03-05 11:14:34 -04:00
|
|
|
count -= 1
|
|
|
|
|
|
|
|
# back to FBWA
|
|
|
|
self.set_rc(1, 1500)
|
|
|
|
self.mavproxy.send('switch 4\n')
|
|
|
|
self.wait_mode('FBWA')
|
|
|
|
self.set_rc(3, 1700)
|
|
|
|
return self.wait_level_flight()
|
|
|
|
|
|
|
|
def inside_loop(self, count=1):
|
|
|
|
"""Fly a inside loop."""
|
|
|
|
# full throttle!
|
|
|
|
self.set_rc(3, 2000)
|
2018-04-27 15:21:53 -03:00
|
|
|
self.change_altitude(self.homeloc.alt+300)
|
2018-03-05 11:14:34 -04:00
|
|
|
# fly the loop in manual
|
|
|
|
self.mavproxy.send('switch 6\n')
|
|
|
|
self.wait_mode('MANUAL')
|
|
|
|
|
|
|
|
while count > 0:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting loop")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(2, 1000)
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_pitch(-60, accuracy=20)
|
|
|
|
self.wait_pitch(0, accuracy=20)
|
2018-03-05 11:14:34 -04:00
|
|
|
count -= 1
|
|
|
|
|
|
|
|
# back to FBWA
|
|
|
|
self.set_rc(2, 1500)
|
|
|
|
self.mavproxy.send('switch 4\n')
|
|
|
|
self.wait_mode('FBWA')
|
|
|
|
self.set_rc(3, 1700)
|
|
|
|
return self.wait_level_flight()
|
|
|
|
|
2019-03-10 04:44:38 -03:00
|
|
|
def set_attitude_target(self, tolerance=10):
|
2018-05-31 07:27:41 -03:00
|
|
|
"""Test setting of attitude target in guided mode."""
|
2019-03-10 04:44:38 -03:00
|
|
|
self.change_mode("GUIDED")
|
|
|
|
# self.set_parameter("STALL_PREVENTION", 0)
|
2018-05-31 07:27:41 -03:00
|
|
|
|
|
|
|
state_roll_over = "roll-over"
|
|
|
|
state_stabilize_roll = "stabilize-roll"
|
|
|
|
state_hold = "hold"
|
|
|
|
state_roll_back = "roll-back"
|
|
|
|
state_done = "done"
|
|
|
|
|
|
|
|
tstart = self.get_sim_time()
|
|
|
|
|
|
|
|
try:
|
|
|
|
state = state_roll_over
|
|
|
|
while state != state_done:
|
|
|
|
|
|
|
|
m = self.mav.recv_match(type='ATTITUDE',
|
|
|
|
blocking=True,
|
|
|
|
timeout=0.1)
|
2019-03-10 04:44:38 -03:00
|
|
|
now = self.get_sim_time_cached()
|
|
|
|
if now - tstart > 20:
|
|
|
|
raise AutoTestTimeoutException("Manuevers not completed")
|
2018-05-31 07:27:41 -03:00
|
|
|
if m is None:
|
|
|
|
continue
|
|
|
|
|
|
|
|
r = math.degrees(m.roll)
|
|
|
|
if state == state_roll_over:
|
2019-03-10 04:44:38 -03:00
|
|
|
target_roll_degrees = 60
|
|
|
|
if abs(r - target_roll_degrees) < tolerance:
|
2018-05-31 07:27:41 -03:00
|
|
|
state = state_stabilize_roll
|
2019-03-10 04:44:38 -03:00
|
|
|
stabilize_start = now
|
2018-05-31 07:27:41 -03:00
|
|
|
elif state == state_stabilize_roll:
|
|
|
|
# just give it a little time to sort it self out
|
2019-03-10 04:44:38 -03:00
|
|
|
if now - stabilize_start > 2:
|
2018-05-31 07:27:41 -03:00
|
|
|
state = state_hold
|
2019-03-10 04:44:38 -03:00
|
|
|
hold_start = now
|
2018-05-31 07:27:41 -03:00
|
|
|
elif state == state_hold:
|
2019-03-10 04:44:38 -03:00
|
|
|
target_roll_degrees = 60
|
|
|
|
if now - hold_start > tolerance:
|
2018-05-31 07:27:41 -03:00
|
|
|
state = state_roll_back
|
2019-03-10 04:44:38 -03:00
|
|
|
if abs(r - target_roll_degrees) > tolerance:
|
2018-10-17 23:55:16 -03:00
|
|
|
raise NotAchievedException("Failed to hold attitude")
|
2018-05-31 07:27:41 -03:00
|
|
|
elif state == state_roll_back:
|
|
|
|
target_roll_degrees = 0
|
2019-03-10 04:44:38 -03:00
|
|
|
if abs(r - target_roll_degrees) < tolerance:
|
2018-05-31 07:27:41 -03:00
|
|
|
state = state_done
|
|
|
|
else:
|
2018-10-17 23:55:16 -03:00
|
|
|
raise ValueError("Unknown state %s" % str(state))
|
2018-05-31 07:27:41 -03:00
|
|
|
|
2019-03-10 04:44:38 -03:00
|
|
|
m_nav = self.mav.messages['NAV_CONTROLLER_OUTPUT']
|
|
|
|
self.progress("%s Roll: %f desired=%f set=%f" %
|
|
|
|
(state, r, m_nav.nav_roll, target_roll_degrees))
|
2018-05-31 07:27:41 -03:00
|
|
|
|
|
|
|
time_boot_millis = 0 # FIXME
|
|
|
|
target_system = 1 # FIXME
|
|
|
|
target_component = 1 # FIXME
|
|
|
|
type_mask = 0b10000001 ^ 0xFF # FIXME
|
|
|
|
# attitude in radians:
|
|
|
|
q = quaternion.Quaternion([math.radians(target_roll_degrees),
|
2018-11-22 23:51:58 -04:00
|
|
|
0,
|
2018-05-31 07:27:41 -03:00
|
|
|
0])
|
|
|
|
roll_rate_radians = 0.5
|
|
|
|
pitch_rate_radians = 0
|
|
|
|
yaw_rate_radians = 0
|
|
|
|
thrust = 1.0
|
|
|
|
self.mav.mav.set_attitude_target_send(time_boot_millis,
|
|
|
|
target_system,
|
|
|
|
target_component,
|
|
|
|
type_mask,
|
|
|
|
q,
|
|
|
|
roll_rate_radians,
|
|
|
|
pitch_rate_radians,
|
|
|
|
yaw_rate_radians,
|
|
|
|
thrust)
|
|
|
|
except Exception as e:
|
|
|
|
self.mavproxy.send('mode FBWA\n')
|
|
|
|
self.wait_mode('FBWA')
|
|
|
|
self.set_rc(3, 1700)
|
|
|
|
raise e
|
|
|
|
|
|
|
|
# back to FBWA
|
|
|
|
self.mavproxy.send('mode FBWA\n')
|
|
|
|
self.wait_mode('FBWA')
|
|
|
|
self.set_rc(3, 1700)
|
|
|
|
self.wait_level_flight()
|
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
def test_stabilize(self, count=1):
|
|
|
|
"""Fly stabilize mode."""
|
|
|
|
# full throttle!
|
|
|
|
self.set_rc(3, 2000)
|
|
|
|
self.set_rc(2, 1300)
|
2018-04-27 15:21:53 -03:00
|
|
|
self.change_altitude(self.homeloc.alt+300)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(2, 1500)
|
|
|
|
|
|
|
|
self.mavproxy.send("mode STABILIZE\n")
|
|
|
|
self.wait_mode('STABILIZE')
|
|
|
|
|
|
|
|
while count > 0:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting roll")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(1, 2000)
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_roll(-150, accuracy=90)
|
|
|
|
self.wait_roll(150, accuracy=90)
|
|
|
|
self.wait_roll(0, accuracy=90)
|
2018-03-05 11:14:34 -04:00
|
|
|
count -= 1
|
|
|
|
|
|
|
|
self.set_rc(1, 1500)
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_roll(0, accuracy=5)
|
2013-07-16 00:23:48 -03:00
|
|
|
|
2018-03-05 11:14:34 -04:00
|
|
|
# back to FBWA
|
|
|
|
self.mavproxy.send('mode FBWA\n')
|
|
|
|
self.wait_mode('FBWA')
|
|
|
|
self.set_rc(3, 1700)
|
|
|
|
return self.wait_level_flight()
|
|
|
|
|
|
|
|
def test_acro(self, count=1):
|
|
|
|
"""Fly ACRO mode."""
|
|
|
|
# full throttle!
|
|
|
|
self.set_rc(3, 2000)
|
|
|
|
self.set_rc(2, 1300)
|
2018-04-27 15:21:53 -03:00
|
|
|
self.change_altitude(self.homeloc.alt+300)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(2, 1500)
|
|
|
|
|
|
|
|
self.mavproxy.send("mode ACRO\n")
|
|
|
|
self.wait_mode('ACRO')
|
|
|
|
|
|
|
|
while count > 0:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting roll")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(1, 1000)
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_roll(-150, accuracy=90)
|
|
|
|
self.wait_roll(150, accuracy=90)
|
|
|
|
self.wait_roll(0, accuracy=90)
|
2018-03-05 11:14:34 -04:00
|
|
|
count -= 1
|
|
|
|
self.set_rc(1, 1500)
|
|
|
|
|
|
|
|
# back to FBWA
|
|
|
|
self.mavproxy.send('mode FBWA\n')
|
|
|
|
self.wait_mode('FBWA')
|
|
|
|
|
|
|
|
self.wait_level_flight()
|
|
|
|
|
|
|
|
self.mavproxy.send("mode ACRO\n")
|
|
|
|
self.wait_mode('ACRO')
|
|
|
|
|
|
|
|
count = 2
|
|
|
|
while count > 0:
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting loop")
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(2, 1000)
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_pitch(-60, accuracy=20)
|
|
|
|
self.wait_pitch(0, accuracy=20)
|
2018-03-05 11:14:34 -04:00
|
|
|
count -= 1
|
|
|
|
|
|
|
|
self.set_rc(2, 1500)
|
|
|
|
|
|
|
|
# back to FBWA
|
|
|
|
self.mavproxy.send('mode FBWA\n')
|
|
|
|
self.wait_mode('FBWA')
|
|
|
|
self.set_rc(3, 1700)
|
|
|
|
return self.wait_level_flight()
|
|
|
|
|
2018-07-31 06:47:49 -03:00
|
|
|
def test_FBWB(self, mode='FBWB'):
|
2018-03-05 11:14:34 -04:00
|
|
|
"""Fly FBWB or CRUISE mode."""
|
|
|
|
self.mavproxy.send("mode %s\n" % mode)
|
|
|
|
self.wait_mode(mode)
|
|
|
|
self.set_rc(3, 1700)
|
|
|
|
self.set_rc(2, 1500)
|
|
|
|
|
|
|
|
# lock in the altitude by asking for an altitude change then releasing
|
|
|
|
self.set_rc(2, 1000)
|
|
|
|
self.wait_distance(50, accuracy=20)
|
|
|
|
self.set_rc(2, 1500)
|
|
|
|
self.wait_distance(50, accuracy=20)
|
|
|
|
|
|
|
|
m = self.mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
initial_alt = m.alt
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Initial altitude %u\n" % initial_alt)
|
2018-03-05 11:14:34 -04:00
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Flying right circuit")
|
2018-03-05 11:14:34 -04:00
|
|
|
# do 4 turns
|
|
|
|
for i in range(0, 4):
|
|
|
|
# hard left
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting turn %u" % i)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(1, 1800)
|
2018-04-27 15:21:53 -03:00
|
|
|
try:
|
|
|
|
self.wait_heading(0 + (90*i), accuracy=20, timeout=60)
|
|
|
|
except Exception as e:
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(1, 1500)
|
2018-04-27 15:21:53 -03:00
|
|
|
raise e
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(1, 1500)
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting leg %u" % i)
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_distance(100, accuracy=20)
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Circuit complete")
|
2018-03-05 11:14:34 -04:00
|
|
|
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Flying rudder left circuit")
|
2018-03-05 11:14:34 -04:00
|
|
|
# do 4 turns
|
|
|
|
for i in range(0, 4):
|
|
|
|
# hard left
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting turn %u" % i)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(4, 1900)
|
2018-04-27 15:21:53 -03:00
|
|
|
try:
|
|
|
|
self.wait_heading(360 - (90*i), accuracy=20, timeout=60)
|
|
|
|
except Exception as e:
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(4, 1500)
|
2018-04-27 15:21:53 -03:00
|
|
|
raise e
|
2018-03-05 11:14:34 -04:00
|
|
|
self.set_rc(4, 1500)
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Starting leg %u" % i)
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_distance(100, accuracy=20)
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Circuit complete")
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
m = self.mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
final_alt = m.alt
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Final altitude %u initial %u\n" %
|
|
|
|
(final_alt, initial_alt))
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
# back to FBWA
|
|
|
|
self.mavproxy.send('mode FBWA\n')
|
|
|
|
self.wait_mode('FBWA')
|
|
|
|
|
|
|
|
if abs(final_alt - initial_alt) > 20:
|
2018-10-17 23:55:16 -03:00
|
|
|
raise NotAchievedException("Failed to maintain altitude")
|
2018-03-05 11:14:34 -04:00
|
|
|
|
|
|
|
return self.wait_level_flight()
|
|
|
|
|
2018-08-13 08:07:34 -03:00
|
|
|
def fly_mission(self, filename):
|
|
|
|
"""Fly a mission from a file."""
|
|
|
|
self.progress("Flying mission %s" % filename)
|
2018-11-09 08:32:02 -04:00
|
|
|
self.load_mission(filename)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.mavproxy.send('switch 1\n') # auto mode
|
|
|
|
self.wait_mode('AUTO')
|
2018-04-27 15:21:53 -03:00
|
|
|
self.wait_waypoint(1, 7, max_dist=60)
|
|
|
|
self.wait_groundspeed(0, 0.5, timeout=60)
|
2018-03-05 11:14:34 -04:00
|
|
|
self.mavproxy.expect("Auto disarmed")
|
2018-03-14 08:08:53 -03:00
|
|
|
self.progress("Mission OK")
|
2018-03-05 11:14:34 -04:00
|
|
|
|
2019-08-05 08:09:07 -03:00
|
|
|
def fly_do_reposition(self):
|
|
|
|
self.progress("Takeoff")
|
|
|
|
self.takeoff(alt=50)
|
|
|
|
self.set_rc(3, 1500)
|
|
|
|
self.progress("Entering guided and flying somewhere constant")
|
|
|
|
self.change_mode("GUIDED")
|
|
|
|
loc = self.mav.location()
|
|
|
|
self.location_offset_ne(loc, 500, 500)
|
|
|
|
|
|
|
|
new_alt = 100
|
|
|
|
self.run_cmd_int(
|
|
|
|
mavutil.mavlink.MAV_CMD_DO_REPOSITION,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2019-08-28 09:38:45 -03:00
|
|
|
int(loc.lat*1e7),
|
|
|
|
int(loc.lng*1e7),
|
2019-08-05 08:09:07 -03:00
|
|
|
new_alt, # alt
|
|
|
|
frame=mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT_INT,
|
|
|
|
)
|
|
|
|
self.wait_altitude(new_alt-10, new_alt, timeout=30, relative=True)
|
|
|
|
|
|
|
|
self.fly_home_land_and_disarm()
|
|
|
|
|
2019-10-17 17:33:07 -03:00
|
|
|
def fly_deepstall(self):
|
2019-10-17 18:24:25 -03:00
|
|
|
# self.fly_deepstall_absolute()
|
|
|
|
self.fly_deepstall_relative()
|
|
|
|
|
|
|
|
def fly_deepstall_absolute(self):
|
|
|
|
self.start_subtest("DeepStall Relative Absolute")
|
2019-10-17 17:33:07 -03:00
|
|
|
self.set_parameter("LAND_TYPE", 1)
|
|
|
|
deepstall_elevator_pwm = 1661
|
|
|
|
self.set_parameter("LAND_DS_ELEV_PWM", deepstall_elevator_pwm)
|
|
|
|
self.load_mission("plane-deepstall-mission.txt")
|
|
|
|
self.change_mode("AUTO")
|
|
|
|
self.wait_ready_to_arm()
|
|
|
|
self.arm_vehicle()
|
|
|
|
self.progress("Waiting for deepstall messages")
|
|
|
|
|
|
|
|
self.wait_text("Deepstall: Entry: ", timeout=240)
|
|
|
|
|
|
|
|
# assume elevator is on channel 2:
|
|
|
|
self.wait_servo_channel_value(2, deepstall_elevator_pwm)
|
|
|
|
|
|
|
|
self.disarm_wait(timeout=120)
|
2019-10-17 18:24:25 -03:00
|
|
|
|
|
|
|
self.progress("Flying home")
|
|
|
|
self.takeoff(10)
|
|
|
|
self.set_parameter("LAND_TYPE", 0)
|
|
|
|
self.fly_home_land_and_disarm()
|
|
|
|
|
|
|
|
def fly_deepstall_relative(self):
|
|
|
|
self.start_subtest("DeepStall Relative")
|
|
|
|
self.set_parameter("LAND_TYPE", 1)
|
|
|
|
deepstall_elevator_pwm = 1661
|
|
|
|
self.set_parameter("LAND_DS_ELEV_PWM", deepstall_elevator_pwm)
|
|
|
|
self.load_mission("plane-deepstall-relative-mission.txt")
|
|
|
|
self.change_mode("AUTO")
|
|
|
|
self.wait_ready_to_arm()
|
|
|
|
self.arm_vehicle()
|
|
|
|
self.progress("Waiting for deepstall messages")
|
|
|
|
|
|
|
|
self.wait_text("Deepstall: Entry: ", timeout=240)
|
|
|
|
|
|
|
|
# assume elevator is on channel 2:
|
|
|
|
self.wait_servo_channel_value(2, deepstall_elevator_pwm)
|
|
|
|
|
|
|
|
self.disarm_wait(timeout=120)
|
2019-10-17 17:33:07 -03:00
|
|
|
|
|
|
|
self.progress("Flying home")
|
|
|
|
self.takeoff(10)
|
|
|
|
self.set_parameter("LAND_TYPE", 0)
|
|
|
|
self.fly_home_land_and_disarm()
|
|
|
|
|
2019-05-20 09:47:01 -03:00
|
|
|
def fly_do_change_speed(self):
|
|
|
|
# the following lines ensure we revert these parameter values
|
|
|
|
# - DO_CHANGE_AIRSPEED is a permanent vehicle change!
|
|
|
|
self.set_parameter("TRIM_ARSPD_CM", self.get_parameter("TRIM_ARSPD_CM"))
|
|
|
|
self.set_parameter("MIN_GNDSPD_CM", self.get_parameter("MIN_GNDSPD_CM"))
|
|
|
|
|
|
|
|
self.progress("Takeoff")
|
|
|
|
self.takeoff(alt=100)
|
|
|
|
self.set_rc(3, 1500)
|
|
|
|
# ensure we know what the airspeed is:
|
|
|
|
self.progress("Entering guided and flying somewhere constant")
|
|
|
|
self.change_mode("GUIDED")
|
|
|
|
self.run_cmd_int(
|
|
|
|
mavutil.mavlink.MAV_CMD_DO_REPOSITION,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
12345, # lat*1e7
|
|
|
|
12345, # lon*1e7
|
|
|
|
100 # alt
|
|
|
|
)
|
|
|
|
self.delay_sim_time(10)
|
|
|
|
self.progress("Ensuring initial speed is known and relatively constant")
|
|
|
|
initial_speed = 21.5;
|
|
|
|
timeout = 10
|
|
|
|
tstart = self.get_sim_time()
|
|
|
|
while True:
|
|
|
|
if self.get_sim_time_cached() - tstart > timeout:
|
|
|
|
break
|
|
|
|
m = self.mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
self.progress("GroundSpeed: %f want=%f" %
|
|
|
|
(m.groundspeed, initial_speed))
|
|
|
|
if abs(initial_speed - m.groundspeed) > 1:
|
|
|
|
raise NotAchievedException("Initial speed not as expected (want=%f got=%f" % (initial_speed, m.groundspeed))
|
|
|
|
|
|
|
|
self.progress("Setting groundspeed")
|
|
|
|
new_target_groundspeed = initial_speed + 5
|
|
|
|
self.run_cmd(
|
|
|
|
mavutil.mavlink.MAV_CMD_DO_CHANGE_SPEED,
|
|
|
|
1, # groundspeed
|
|
|
|
new_target_groundspeed,
|
|
|
|
-1, # throttle / no change
|
|
|
|
0, # absolute values
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0)
|
|
|
|
self.wait_groundspeed(new_target_groundspeed-0.5, new_target_groundspeed+0.5, timeout=40)
|
|
|
|
self.progress("Adding some wind, ensuring groundspeed holds")
|
|
|
|
self.set_parameter("SIM_WIND_SPD", 5)
|
|
|
|
self.delay_sim_time(5)
|
|
|
|
self.wait_groundspeed(new_target_groundspeed-0.5, new_target_groundspeed+0.5, timeout=40)
|
|
|
|
self.set_parameter("SIM_WIND_SPD", 0)
|
|
|
|
|
|
|
|
self.progress("Setting airspeed")
|
|
|
|
new_target_airspeed = initial_speed + 5
|
|
|
|
self.run_cmd(
|
|
|
|
mavutil.mavlink.MAV_CMD_DO_CHANGE_SPEED,
|
|
|
|
0, # airspeed
|
|
|
|
new_target_airspeed,
|
|
|
|
-1, # throttle / no change
|
|
|
|
0, # absolute values
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0)
|
|
|
|
self.wait_groundspeed(new_target_airspeed-0.5, new_target_airspeed+0.5)
|
|
|
|
self.progress("Adding some wind, hoping groundspeed increases/decreases")
|
|
|
|
self.set_parameter("SIM_WIND_SPD", 5)
|
|
|
|
self.set_parameter("SIM_WIND_DIR", 270)
|
|
|
|
self.delay_sim_time(5)
|
|
|
|
timeout = 10
|
|
|
|
tstart = self.get_sim_time()
|
|
|
|
while True:
|
|
|
|
if self.get_sim_time_cached() - tstart > timeout:
|
|
|
|
raise NotAchievedException("Did not achieve groundspeed delta")
|
|
|
|
m = self.mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
delta = abs(m.airspeed - m.groundspeed)
|
|
|
|
want_delta = 4
|
|
|
|
self.progress("groundspeed and airspeed should be different (have=%f want=%f)" % (delta, want_delta))
|
|
|
|
if delta > want_delta:
|
|
|
|
break
|
2019-08-05 08:09:07 -03:00
|
|
|
self.fly_home_land_and_disarm()
|
|
|
|
|
|
|
|
def fly_home_land_and_disarm(self):
|
2019-05-20 09:47:01 -03:00
|
|
|
filename = os.path.join(testdir, "flaps.txt")
|
|
|
|
self.progress("Using %s to fly home" % filename)
|
|
|
|
self.load_mission(filename)
|
|
|
|
self.change_mode("AUTO")
|
|
|
|
self.mavproxy.send('wp set 7\n')
|
|
|
|
self.mav.motors_disarmed_wait()
|
|
|
|
|
2018-08-13 08:07:34 -03:00
|
|
|
def fly_flaps(self):
|
|
|
|
"""Test flaps functionality."""
|
|
|
|
filename = os.path.join(testdir, "flaps.txt")
|
|
|
|
self.context_push()
|
|
|
|
ex = None
|
|
|
|
try:
|
|
|
|
flaps_ch = 5
|
|
|
|
servo_ch = 5
|
|
|
|
self.set_parameter("SERVO%u_FUNCTION" % servo_ch, 3) # flapsauto
|
|
|
|
self.set_parameter("FLAP_IN_CHANNEL", flaps_ch)
|
|
|
|
self.set_parameter("LAND_FLAP_PERCNT", 50)
|
|
|
|
self.set_parameter("LOG_DISARMED", 1)
|
|
|
|
flaps_ch_min = 1000
|
|
|
|
flaps_ch_trim = 1500
|
|
|
|
flaps_ch_max = 2000
|
|
|
|
self.set_parameter("RC%u_MIN" % flaps_ch, flaps_ch_min)
|
|
|
|
self.set_parameter("RC%u_MAX" % flaps_ch, flaps_ch_max)
|
|
|
|
self.set_parameter("RC%u_TRIM" % flaps_ch, flaps_ch_trim)
|
|
|
|
|
|
|
|
servo_ch_min = 1200
|
|
|
|
servo_ch_trim = 1300
|
|
|
|
servo_ch_max = 1800
|
|
|
|
self.set_parameter("SERVO%u_MIN" % servo_ch, servo_ch_min)
|
|
|
|
self.set_parameter("SERVO%u_MAX" % servo_ch, servo_ch_max)
|
|
|
|
self.set_parameter("SERVO%u_TRIM" % servo_ch, servo_ch_trim)
|
|
|
|
|
2018-11-28 18:48:31 -04:00
|
|
|
self.progress("check flaps are not deployed")
|
2018-08-13 08:07:34 -03:00
|
|
|
self.set_rc(flaps_ch, flaps_ch_min)
|
|
|
|
self.wait_servo_channel_value(servo_ch, servo_ch_min)
|
2018-11-28 18:48:31 -04:00
|
|
|
self.progress("deploy the flaps")
|
2018-08-13 08:07:34 -03:00
|
|
|
self.set_rc(flaps_ch, flaps_ch_max)
|
|
|
|
tstart = self.get_sim_time()
|
|
|
|
self.wait_servo_channel_value(servo_ch, servo_ch_max)
|
|
|
|
tstop = self.get_sim_time_cached()
|
|
|
|
delta_time = tstop - tstart
|
|
|
|
delta_time_min = 0.5
|
|
|
|
delta_time_max = 1.5
|
|
|
|
if delta_time < delta_time_min or delta_time > delta_time_max:
|
2018-10-17 23:55:16 -03:00
|
|
|
raise NotAchievedException((
|
|
|
|
"Flaps Slew not working (%f seconds)" % (delta_time,)))
|
2018-11-28 18:48:31 -04:00
|
|
|
self.progress("undeploy flaps")
|
2018-08-13 08:07:34 -03:00
|
|
|
self.set_rc(flaps_ch, flaps_ch_min)
|
|
|
|
self.wait_servo_channel_value(servo_ch, servo_ch_min)
|
|
|
|
|
|
|
|
self.progress("Flying mission %s" % filename)
|
2018-11-09 08:32:02 -04:00
|
|
|
self.load_mission(filename)
|
2018-08-13 08:07:34 -03:00
|
|
|
self.mavproxy.send('wp set 1\n')
|
|
|
|
self.mavproxy.send('switch 1\n') # auto mode
|
|
|
|
self.wait_mode('AUTO')
|
|
|
|
self.wait_ready_to_arm()
|
|
|
|
self.arm_vehicle()
|
2018-09-07 20:48:45 -03:00
|
|
|
last_mission_current_msg = 0
|
|
|
|
last_seq = None
|
2018-08-13 08:07:34 -03:00
|
|
|
while self.armed():
|
|
|
|
m = self.mav.recv_match(type='MISSION_CURRENT', blocking=True)
|
2018-09-07 20:48:45 -03:00
|
|
|
time_delta = (self.get_sim_time_cached() -
|
|
|
|
last_mission_current_msg)
|
2018-11-22 23:51:58 -04:00
|
|
|
if (time_delta > 1 or m.seq != last_seq):
|
2018-09-07 20:48:45 -03:00
|
|
|
dist = None
|
|
|
|
x = self.mav.messages.get("NAV_CONTROLLER_OUTPUT", None)
|
|
|
|
if x is not None:
|
|
|
|
dist = x.wp_dist
|
|
|
|
self.progress("MISSION_CURRENT.seq=%u (dist=%s)" %
|
2018-11-22 23:51:58 -04:00
|
|
|
(m.seq, str(dist)))
|
2018-09-07 20:48:45 -03:00
|
|
|
last_mission_current_msg = self.get_sim_time_cached()
|
|
|
|
last_seq = m.seq
|
2018-08-13 08:07:34 -03:00
|
|
|
# flaps should undeploy at the end
|
|
|
|
self.wait_servo_channel_value(servo_ch, servo_ch_min, timeout=30)
|
|
|
|
|
|
|
|
# do a short flight in FBWA, watching for flaps
|
|
|
|
# self.mavproxy.send('switch 4\n')
|
|
|
|
# self.wait_mode('FBWA')
|
2019-11-08 02:22:30 -04:00
|
|
|
# self.delay_sim_time(10)
|
2018-08-13 08:07:34 -03:00
|
|
|
# self.mavproxy.send('switch 6\n')
|
|
|
|
# self.wait_mode('MANUAL')
|
2019-11-08 02:22:30 -04:00
|
|
|
# self.delay_sim_time(10)
|
2018-08-13 08:07:34 -03:00
|
|
|
|
|
|
|
self.progress("Flaps OK")
|
|
|
|
except Exception as e:
|
|
|
|
ex = e
|
|
|
|
self.context_pop()
|
|
|
|
if ex:
|
2018-09-07 08:15:02 -03:00
|
|
|
if self.armed():
|
|
|
|
self.disarm_vehicle()
|
2018-08-13 08:07:34 -03:00
|
|
|
raise ex
|
|
|
|
|
2018-08-03 07:16:10 -03:00
|
|
|
def test_rc_relay(self):
|
|
|
|
'''test toggling channel 12 toggles relay'''
|
2018-12-16 18:54:05 -04:00
|
|
|
self.set_parameter("RC12_OPTION", 28) # Relay On/Off
|
|
|
|
self.set_rc(12, 1000)
|
|
|
|
self.reboot_sitl() # needed for RC12_OPTION to take effect
|
|
|
|
|
2018-08-03 07:16:10 -03:00
|
|
|
off = self.get_parameter("SIM_PIN_MASK")
|
|
|
|
if off:
|
2018-10-17 23:55:16 -03:00
|
|
|
raise PreconditionFailedException("SIM_MASK_PIN off")
|
2018-12-16 18:54:05 -04:00
|
|
|
|
|
|
|
# allow time for the RC library to register initial value:
|
|
|
|
self.delay_sim_time(1)
|
|
|
|
|
2018-08-03 07:16:10 -03:00
|
|
|
self.set_rc(12, 2000)
|
2018-12-13 18:17:02 -04:00
|
|
|
self.wait_heartbeat()
|
|
|
|
self.wait_heartbeat()
|
2018-12-16 18:54:05 -04:00
|
|
|
|
2018-08-03 07:16:10 -03:00
|
|
|
on = self.get_parameter("SIM_PIN_MASK")
|
|
|
|
if not on:
|
2018-10-17 23:55:16 -03:00
|
|
|
raise NotAchievedException("SIM_PIN_MASK doesn't reflect ON")
|
2018-08-03 07:16:10 -03:00
|
|
|
self.set_rc(12, 1000)
|
2018-12-13 18:17:02 -04:00
|
|
|
self.wait_heartbeat()
|
|
|
|
self.wait_heartbeat()
|
2018-08-03 07:16:10 -03:00
|
|
|
off = self.get_parameter("SIM_PIN_MASK")
|
|
|
|
if off:
|
2018-10-17 23:55:16 -03:00
|
|
|
raise NotAchievedException("SIM_PIN_MASK doesn't reflect OFF")
|
2018-08-03 07:16:10 -03:00
|
|
|
|
2018-08-03 07:50:15 -03:00
|
|
|
def test_rc_option_camera_trigger(self):
|
|
|
|
'''test toggling channel 12 takes picture'''
|
2018-12-16 18:54:05 -04:00
|
|
|
self.set_parameter("RC12_OPTION", 9) # CameraTrigger
|
|
|
|
self.reboot_sitl() # needed for RC12_OPTION to take effect
|
|
|
|
|
2018-08-03 07:50:15 -03:00
|
|
|
x = self.mav.messages.get("CAMERA_FEEDBACK", None)
|
|
|
|
if x is not None:
|
2018-10-17 23:55:16 -03:00
|
|
|
raise PreconditionFailedException("Receiving CAMERA_FEEDBACK?!")
|
2018-08-03 07:50:15 -03:00
|
|
|
self.set_rc(12, 2000)
|
|
|
|
tstart = self.get_sim_time()
|
2019-03-07 18:34:09 -04:00
|
|
|
while self.get_sim_time_cached() - tstart < 10:
|
2018-08-03 07:50:15 -03:00
|
|
|
x = self.mav.messages.get("CAMERA_FEEDBACK", None)
|
|
|
|
if x is not None:
|
|
|
|
break
|
2018-12-13 18:17:02 -04:00
|
|
|
self.wait_heartbeat()
|
2018-08-03 07:50:15 -03:00
|
|
|
self.set_rc(12, 1000)
|
|
|
|
if x is None:
|
2018-10-17 23:55:16 -03:00
|
|
|
raise NotAchievedException("No CAMERA_FEEDBACK message received")
|
2018-08-03 07:50:15 -03:00
|
|
|
|
2018-08-20 21:55:59 -03:00
|
|
|
def test_throttle_failsafe(self):
|
|
|
|
self.change_mode('MANUAL')
|
|
|
|
m = self.mav.recv_match(type='SYS_STATUS', blocking=True)
|
|
|
|
receiver_bit = mavutil.mavlink.MAV_SYS_STATUS_SENSOR_RC_RECEIVER
|
|
|
|
self.progress("Testing receiver enabled")
|
|
|
|
if (not (m.onboard_control_sensors_enabled & receiver_bit)):
|
|
|
|
raise PreconditionFailedException()
|
|
|
|
self.progress("Testing receiver present")
|
|
|
|
if (not (m.onboard_control_sensors_present & receiver_bit)):
|
|
|
|
raise PreconditionFailedException()
|
|
|
|
self.progress("Testing receiver health")
|
|
|
|
if (not (m.onboard_control_sensors_health & receiver_bit)):
|
|
|
|
raise PreconditionFailedException()
|
|
|
|
|
|
|
|
self.progress("Ensure we know original throttle value")
|
|
|
|
self.wait_rc_channel_value(3, 1000)
|
|
|
|
|
|
|
|
self.set_parameter("THR_FS_VALUE", 960)
|
|
|
|
self.progress("Failing receiver (throttle-to-950)")
|
|
|
|
self.set_parameter("SIM_RC_FAIL", 2) # throttle-to-950
|
|
|
|
self.wait_mode('CIRCLE') # short failsafe
|
|
|
|
self.wait_mode('RTL') # long failsafe
|
|
|
|
self.progress("Ensure we've had our throttle squashed to 950")
|
|
|
|
self.wait_rc_channel_value(3, 950)
|
2019-08-26 03:37:42 -03:00
|
|
|
self.drain_mav_unparsed()
|
2018-08-20 21:55:59 -03:00
|
|
|
m = self.mav.recv_match(type='SYS_STATUS', blocking=True)
|
|
|
|
print("%s" % str(m))
|
|
|
|
self.progress("Testing receiver enabled")
|
|
|
|
if (not (m.onboard_control_sensors_enabled & receiver_bit)):
|
|
|
|
raise NotAchievedException("Receiver not enabled")
|
|
|
|
self.progress("Testing receiver present")
|
|
|
|
if (not (m.onboard_control_sensors_present & receiver_bit)):
|
|
|
|
raise NotAchievedException("Receiver not present")
|
2019-02-13 18:50:46 -04:00
|
|
|
# skip this until RC is fixed
|
|
|
|
# self.progress("Testing receiver health")
|
|
|
|
# if (m.onboard_control_sensors_health & receiver_bit):
|
|
|
|
# raise NotAchievedException("Sensor healthy when it shouldn't be")
|
2018-08-20 21:55:59 -03:00
|
|
|
self.set_parameter("SIM_RC_FAIL", 0)
|
2019-08-26 03:37:42 -03:00
|
|
|
self.drain_mav_unparsed()
|
2019-09-16 22:46:47 -03:00
|
|
|
# have to allow time for RC to be fetched from SITL
|
|
|
|
self.delay_sim_time(0.5)
|
2018-08-20 21:55:59 -03:00
|
|
|
m = self.mav.recv_match(type='SYS_STATUS', blocking=True)
|
|
|
|
self.progress("Testing receiver enabled")
|
|
|
|
if (not (m.onboard_control_sensors_enabled & receiver_bit)):
|
|
|
|
raise NotAchievedException("Receiver not enabled")
|
|
|
|
self.progress("Testing receiver present")
|
|
|
|
if (not (m.onboard_control_sensors_present & receiver_bit)):
|
|
|
|
raise NotAchievedException("Receiver not present")
|
|
|
|
self.progress("Testing receiver health")
|
|
|
|
if (not (m.onboard_control_sensors_health & receiver_bit)):
|
2019-08-26 03:37:42 -03:00
|
|
|
raise NotAchievedException("Receiver not healthy2")
|
2018-08-20 21:55:59 -03:00
|
|
|
self.change_mode('MANUAL')
|
|
|
|
|
|
|
|
self.progress("Failing receiver (no-pulses)")
|
|
|
|
self.set_parameter("SIM_RC_FAIL", 1) # no-pulses
|
|
|
|
self.wait_mode('CIRCLE') # short failsafe
|
|
|
|
self.wait_mode('RTL') # long failsafe
|
2019-08-26 03:37:42 -03:00
|
|
|
self.drain_mav_unparsed()
|
2018-08-20 21:55:59 -03:00
|
|
|
m = self.mav.recv_match(type='SYS_STATUS', blocking=True)
|
|
|
|
print("%s" % str(m))
|
|
|
|
self.progress("Testing receiver enabled")
|
|
|
|
if (not (m.onboard_control_sensors_enabled & receiver_bit)):
|
|
|
|
raise NotAchievedException("Receiver not enabled")
|
|
|
|
self.progress("Testing receiver present")
|
|
|
|
if (not (m.onboard_control_sensors_present & receiver_bit)):
|
|
|
|
raise NotAchievedException("Receiver not present")
|
|
|
|
self.progress("Testing receiver health")
|
|
|
|
if (m.onboard_control_sensors_health & receiver_bit):
|
|
|
|
raise NotAchievedException("Sensor healthy when it shouldn't be")
|
2019-03-07 19:06:46 -04:00
|
|
|
self.progress("Making RC work again")
|
2018-08-20 21:55:59 -03:00
|
|
|
self.set_parameter("SIM_RC_FAIL", 0)
|
2019-10-06 18:17:12 -03:00
|
|
|
# have to allow time for RC to be fetched from SITL
|
2019-02-26 00:29:12 -04:00
|
|
|
self.progress("Giving receiver time to recover")
|
2019-10-06 18:17:12 -03:00
|
|
|
self.delay_sim_time(0.5)
|
|
|
|
self.drain_mav_unparsed()
|
|
|
|
m = self.mav.recv_match(type='SYS_STATUS', blocking=True)
|
2018-08-20 21:55:59 -03:00
|
|
|
self.progress("Testing receiver enabled")
|
|
|
|
if (not (m.onboard_control_sensors_enabled & receiver_bit)):
|
|
|
|
raise NotAchievedException("Receiver not enabled")
|
|
|
|
self.progress("Testing receiver present")
|
|
|
|
if (not (m.onboard_control_sensors_present & receiver_bit)):
|
|
|
|
raise NotAchievedException("Receiver not present")
|
|
|
|
self.progress("Testing receiver health")
|
|
|
|
if (not (m.onboard_control_sensors_health & receiver_bit)):
|
|
|
|
raise NotAchievedException("Receiver not healthy")
|
|
|
|
self.change_mode('MANUAL')
|
|
|
|
|
2019-08-14 20:51:23 -03:00
|
|
|
self.progress("Ensure long failsafe can trigger when short failsafe disabled")
|
|
|
|
self.context_push()
|
|
|
|
ex = None
|
|
|
|
try:
|
|
|
|
self.set_parameter("FS_SHORT_ACTN", 3) # 3 means disabled
|
|
|
|
self.set_parameter("SIM_RC_FAIL", 1)
|
|
|
|
self.wait_statustext("Long event on")
|
2019-08-20 23:22:34 -03:00
|
|
|
self.wait_mode("RTL")
|
|
|
|
self.set_parameter("SIM_RC_FAIL", 0)
|
|
|
|
self.wait_text("Long event off")
|
|
|
|
self.change_mode("MANUAL")
|
|
|
|
|
|
|
|
self.progress("Trying again with THR_FS_VALUE")
|
|
|
|
self.set_parameter("THR_FS_VALUE", 960)
|
|
|
|
self.set_parameter("SIM_RC_FAIL", 2)
|
|
|
|
self.wait_statustext("Long event on")
|
|
|
|
self.wait_mode("RTL")
|
2019-08-14 20:51:23 -03:00
|
|
|
except Exception as e:
|
|
|
|
self.progress("Exception caught:")
|
|
|
|
self.progress(self.get_exception_stacktrace(e))
|
|
|
|
ex = e
|
|
|
|
self.context_pop()
|
|
|
|
if ex is not None:
|
|
|
|
raise ex
|
|
|
|
|
2019-11-02 19:08:07 -03:00
|
|
|
def test_throttle_failsafe_fence(self):
|
|
|
|
fence_bit = mavutil.mavlink.MAV_SYS_STATUS_GEOFENCE
|
|
|
|
|
|
|
|
self.progress("Checking fence is not present before being configured")
|
|
|
|
m = self.mav.recv_match(type='SYS_STATUS', blocking=True)
|
|
|
|
print("%s" % str(m))
|
|
|
|
if (m.onboard_control_sensors_enabled & fence_bit):
|
|
|
|
raise NotAchievedException("Fence enabled before being configured")
|
|
|
|
|
|
|
|
self.change_mode('MANUAL')
|
|
|
|
self.wait_ready_to_arm()
|
|
|
|
|
|
|
|
self.load_fence("CMAC-fence.txt")
|
|
|
|
|
|
|
|
self.set_parameter("FENCE_CHANNEL", 7)
|
|
|
|
self.set_parameter("FENCE_ACTION", 4)
|
|
|
|
self.set_rc(3, 1000)
|
|
|
|
self.set_rc(7, 2000)
|
|
|
|
|
|
|
|
self.progress("Checking fence is initially OK")
|
|
|
|
m = self.mav.recv_match(type='SYS_STATUS', blocking=True)
|
|
|
|
print("%s" % str(m))
|
|
|
|
if (not (m.onboard_control_sensors_enabled & fence_bit)):
|
|
|
|
raise NotAchievedException("Fence not initially enabled")
|
|
|
|
|
|
|
|
self.set_parameter("THR_FS_VALUE", 960)
|
|
|
|
self.progress("Failing receiver (throttle-to-950)")
|
|
|
|
self.set_parameter("SIM_RC_FAIL", 2) # throttle-to-950
|
|
|
|
self.wait_mode("CIRCLE")
|
|
|
|
self.delay_sim_time(1) # give
|
|
|
|
self.drain_mav_unparsed()
|
|
|
|
|
|
|
|
self.progress("Checking fence is OK after receiver failure (bind-values)")
|
|
|
|
fence_bit = mavutil.mavlink.MAV_SYS_STATUS_GEOFENCE
|
|
|
|
m = self.mav.recv_match(type='SYS_STATUS', blocking=True)
|
|
|
|
print("%s" % str(m))
|
|
|
|
if (not (m.onboard_control_sensors_enabled & fence_bit)):
|
|
|
|
raise NotAchievedException("Fence not enabled after RC fail")
|
|
|
|
|
2018-10-23 01:56:36 -03:00
|
|
|
def test_gripper_mission(self):
|
|
|
|
self.context_push()
|
|
|
|
ex = None
|
|
|
|
try:
|
2018-11-09 08:32:02 -04:00
|
|
|
self.load_mission("plane-gripper-mission.txt")
|
2018-10-23 01:57:10 -03:00
|
|
|
self.mavproxy.send("wp set 1\n")
|
2018-12-16 18:54:05 -04:00
|
|
|
self.change_mode('AUTO')
|
2018-10-23 01:56:36 -03:00
|
|
|
self.wait_ready_to_arm()
|
|
|
|
self.arm_vehicle()
|
|
|
|
self.mavproxy.expect("Gripper Grabbed")
|
|
|
|
self.mavproxy.expect("Gripper Released")
|
|
|
|
self.mavproxy.expect("Auto disarmed")
|
|
|
|
except Exception as e:
|
2019-07-08 02:24:56 -03:00
|
|
|
self.progress("Exception caught:")
|
|
|
|
self.progress(self.get_exception_stacktrace(e))
|
2018-10-23 01:56:36 -03:00
|
|
|
ex = e
|
|
|
|
self.context_pop()
|
|
|
|
if ex is not None:
|
|
|
|
raise ex
|
|
|
|
|
2019-06-01 02:07:49 -03:00
|
|
|
def assert_fence_sys_status(self, present, enabled, health):
|
|
|
|
self.delay_sim_time(1)
|
|
|
|
self.drain_mav_unparsed()
|
|
|
|
m = self.mav.recv_match(type='SYS_STATUS', blocking=True, timeout=1)
|
|
|
|
if m is None:
|
|
|
|
raise NotAchievedException("Did not receive SYS_STATUS")
|
|
|
|
tests = [ ( "present", present, m.onboard_control_sensors_present ),
|
|
|
|
( "enabled", enabled, m.onboard_control_sensors_enabled ),
|
|
|
|
( "health", health, m.onboard_control_sensors_health ),
|
|
|
|
]
|
|
|
|
bit = mavutil.mavlink.MAV_SYS_STATUS_GEOFENCE
|
|
|
|
for test in tests:
|
|
|
|
(name, want, field) = test
|
|
|
|
got = (field & bit) != 0
|
|
|
|
if want != got:
|
|
|
|
raise NotAchievedException("fence status incorrect; %s want=%u got=%u" %
|
|
|
|
(name, want, got))
|
|
|
|
|
|
|
|
def do_fence_en_or_dis_able(self, value, want_result=mavutil.mavlink.MAV_RESULT_ACCEPTED):
|
|
|
|
if value:
|
|
|
|
p1 = 1
|
|
|
|
else:
|
|
|
|
p1 = 0
|
|
|
|
self.run_cmd(mavutil.mavlink.MAV_CMD_DO_FENCE_ENABLE,
|
|
|
|
p1, # param1
|
|
|
|
0, # param2
|
|
|
|
0, # param3
|
|
|
|
0, # param4
|
|
|
|
0, # param5
|
|
|
|
0, # param6
|
|
|
|
0, # param7
|
|
|
|
want_result=want_result)
|
|
|
|
|
|
|
|
def do_fence_enable(self, want_result=mavutil.mavlink.MAV_RESULT_ACCEPTED):
|
|
|
|
self.do_fence_en_or_dis_able(True, want_result=want_result)
|
|
|
|
|
|
|
|
def do_fence_disable(self, want_result=mavutil.mavlink.MAV_RESULT_ACCEPTED):
|
|
|
|
self.do_fence_en_or_dis_able(False, want_result=want_result)
|
|
|
|
|
2019-06-25 06:23:22 -03:00
|
|
|
def wait_circling_point_with_radius(self, loc, want_radius, epsilon=5.0, min_circle_time=5, timeout=120):
|
2019-06-01 02:07:49 -03:00
|
|
|
on_radius_start_heading = None
|
|
|
|
average_radius = 0.0
|
|
|
|
circle_time_start = 0
|
|
|
|
done_time = False
|
|
|
|
done_angle = False
|
2019-06-25 06:23:22 -03:00
|
|
|
tstart = self.get_sim_time()
|
2019-06-01 02:07:49 -03:00
|
|
|
while True:
|
2019-06-25 06:23:22 -03:00
|
|
|
if self.get_sim_time() - tstart > timeout:
|
|
|
|
raise AutoTestTimeoutException("Did not get onto circle")
|
2019-06-01 02:07:49 -03:00
|
|
|
here = self.mav.location()
|
|
|
|
got_radius = self.get_distance(loc, here)
|
|
|
|
average_radius = 0.95*average_radius + 0.05*got_radius
|
|
|
|
on_radius = abs(got_radius - want_radius) < epsilon
|
|
|
|
m = self.mav.recv_match(type='VFR_HUD', blocking=True)
|
|
|
|
heading = m.heading
|
|
|
|
on_string = "off"
|
|
|
|
got_angle = ""
|
|
|
|
if on_radius_start_heading is not None:
|
|
|
|
got_angle = "%0.2f" % abs(on_radius_start_heading - heading) # FIXME
|
|
|
|
on_string = "on"
|
|
|
|
|
|
|
|
want_angle = 180 # we don't actually get this (angle-substraction issue. But we get enough...
|
|
|
|
self.progress("wait-circling: got-r=%0.2f want-r=%f avg-r=%f %s want-a=%0.1f got-a=%s" %
|
|
|
|
(got_radius, want_radius, average_radius, on_string, want_angle, got_angle))
|
|
|
|
if on_radius:
|
|
|
|
if on_radius_start_heading is None:
|
|
|
|
on_radius_start_heading = heading
|
|
|
|
average_radius = got_radius
|
|
|
|
circle_time_start = self.get_sim_time()
|
|
|
|
continue
|
|
|
|
if abs(on_radius_start_heading - heading) > want_angle: # FIXME
|
|
|
|
done_angle = True
|
|
|
|
if self.get_sim_time() - circle_time_start > min_circle_time:
|
|
|
|
done_time = True
|
|
|
|
if done_time and done_angle:
|
|
|
|
return
|
|
|
|
continue
|
|
|
|
if on_radius_start_heading is not None:
|
|
|
|
average_radius = 0.0
|
|
|
|
on_radius_start_heading = None
|
|
|
|
circle_time_start = 0
|
|
|
|
|
|
|
|
def test_fence_static(self):
|
|
|
|
ex = None
|
|
|
|
try:
|
|
|
|
self.progress("Checking for bizarre healthy-when-not-present-or-enabled")
|
|
|
|
self.assert_fence_sys_status(False, False, True)
|
2019-08-05 01:43:27 -03:00
|
|
|
self.load_fence("CMAC-fence.txt")
|
2019-06-01 02:07:49 -03:00
|
|
|
m = self.mav.recv_match(type='FENCE_STATUS', blocking=True, timeout=2)
|
|
|
|
if m is not None:
|
|
|
|
raise NotAchievedException("Got FENCE_STATUS unexpectedly");
|
|
|
|
self.drain_mav_unparsed()
|
|
|
|
self.set_parameter("FENCE_ACTION", mavutil.mavlink.FENCE_ACTION_NONE) # report only
|
|
|
|
self.assert_fence_sys_status(False, False, True)
|
|
|
|
self.set_parameter("FENCE_ACTION", mavutil.mavlink.FENCE_ACTION_RTL) # report only
|
|
|
|
self.assert_fence_sys_status(True, False, True)
|
|
|
|
self.mavproxy.send('fence enable\n')
|
|
|
|
self.mavproxy.expect("fence enabled")
|
|
|
|
self.assert_fence_sys_status(True, True, True)
|
|
|
|
m = self.mav.recv_match(type='FENCE_STATUS', blocking=True, timeout=2)
|
|
|
|
if m is None:
|
|
|
|
raise NotAchievedException("Did not get FENCE_STATUS");
|
|
|
|
if m.breach_status:
|
|
|
|
raise NotAchievedException("Breached fence unexpectedly (%u)" %
|
|
|
|
(m.breach_status))
|
|
|
|
self.mavproxy.send('fence disable\n')
|
|
|
|
self.mavproxy.expect("fence disabled")
|
|
|
|
self.assert_fence_sys_status(True, False, True)
|
|
|
|
self.set_parameter("FENCE_ACTION", mavutil.mavlink.FENCE_ACTION_NONE)
|
|
|
|
self.assert_fence_sys_status(False, False, True)
|
|
|
|
self.set_parameter("FENCE_ACTION", mavutil.mavlink.FENCE_ACTION_RTL)
|
|
|
|
self.assert_fence_sys_status(True, False, True)
|
|
|
|
self.mavproxy.send("fence clear\n")
|
|
|
|
self.mavproxy.expect("fence removed")
|
|
|
|
if self.get_parameter("FENCE_TOTAL") != 0:
|
|
|
|
raise NotAchievedException("Expected zero points remaining")
|
|
|
|
self.assert_fence_sys_status(False, False, True)
|
|
|
|
self.progress("Trying to enable fence with no points")
|
|
|
|
self.do_fence_enable(want_result=mavutil.mavlink.MAV_RESULT_FAILED)
|
|
|
|
|
|
|
|
# test a rather unfortunate behaviour:
|
|
|
|
self.progress("Killing a live fence with fence-clear")
|
2019-08-05 01:43:27 -03:00
|
|
|
self.load_fence("CMAC-fence.txt")
|
2019-06-01 02:07:49 -03:00
|
|
|
self.set_parameter("FENCE_ACTION", mavutil.mavlink.FENCE_ACTION_RTL)
|
|
|
|
self.do_fence_enable()
|
|
|
|
self.assert_fence_sys_status(True, True, True)
|
|
|
|
self.mavproxy.send("fence clear\n")
|
|
|
|
self.mavproxy.expect("fence removed")
|
|
|
|
if self.get_parameter("FENCE_TOTAL") != 0:
|
|
|
|
raise NotAchievedException("Expected zero points remaining")
|
|
|
|
self.assert_fence_sys_status(False, False, True)
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
self.progress("Exception caught:")
|
|
|
|
self.progress(self.get_exception_stacktrace(e))
|
|
|
|
ex = e
|
|
|
|
self.mavproxy.send('fence clear\n')
|
|
|
|
if ex is not None:
|
|
|
|
raise ex
|
|
|
|
|
2019-06-13 23:02:12 -03:00
|
|
|
def test_fence_breach_circle_at(self, loc, disable_on_breach=False):
|
2019-06-01 02:07:49 -03:00
|
|
|
ex = None
|
|
|
|
try:
|
2019-08-05 01:43:27 -03:00
|
|
|
self.load_fence("CMAC-fence.txt")
|
2019-06-01 02:07:49 -03:00
|
|
|
want_radius = 100
|
|
|
|
# when ArduPlane is fixed, remove this fudge factor
|
|
|
|
REALLY_BAD_FUDGE_FACTOR = 1.16
|
|
|
|
expected_radius = REALLY_BAD_FUDGE_FACTOR * want_radius
|
|
|
|
self.set_parameter("RTL_RADIUS", want_radius)
|
|
|
|
self.set_parameter("NAVL1_LIM_BANK", 60)
|
|
|
|
self.set_parameter("FENCE_ACTION", mavutil.mavlink.FENCE_ACTION_RTL)
|
|
|
|
|
|
|
|
self.do_fence_enable()
|
|
|
|
self.assert_fence_sys_status(True, True, True)
|
|
|
|
|
|
|
|
self.takeoff(alt=45, alt_max=300)
|
|
|
|
|
|
|
|
tstart = self.get_sim_time()
|
|
|
|
while True:
|
|
|
|
if self.get_sim_time() - tstart > 30:
|
|
|
|
raise NotAchievedException("Did not breach fence")
|
|
|
|
m = self.mav.recv_match(type='FENCE_STATUS', blocking=True, timeout=2)
|
|
|
|
if m is None:
|
|
|
|
raise NotAchievedException("Did not get FENCE_STATUS");
|
|
|
|
if m.breach_status == 0:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# we've breached; check our state;
|
|
|
|
if m.breach_type != mavutil.mavlink.FENCE_BREACH_BOUNDARY:
|
|
|
|
raise NotAchievedException("Unexpected breach type %u" %
|
|
|
|
(m.breach_type,))
|
|
|
|
if m.breach_count == 0:
|
|
|
|
raise NotAchievedException("Unexpected breach count %u" %
|
|
|
|
(m.breach_count,))
|
|
|
|
self.assert_fence_sys_status(True, True, False)
|
|
|
|
break
|
|
|
|
|
2019-06-13 23:02:12 -03:00
|
|
|
if disable_on_breach:
|
|
|
|
self.do_fence_disable()
|
|
|
|
|
2019-06-01 02:07:49 -03:00
|
|
|
self.wait_circling_point_with_radius(loc, expected_radius)
|
|
|
|
|
|
|
|
self.disarm_vehicle(force=True)
|
|
|
|
self.reboot_sitl()
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
self.progress("Exception caught:")
|
|
|
|
self.progress(self.get_exception_stacktrace(e))
|
|
|
|
ex = e
|
|
|
|
self.mavproxy.send('fence clear\n')
|
|
|
|
if ex is not None:
|
|
|
|
raise ex
|
|
|
|
|
|
|
|
def test_fence_rtl(self):
|
|
|
|
self.progress("Testing FENCE_ACTION_RTL no rally point")
|
2019-06-13 23:02:12 -03:00
|
|
|
# have to disable the fence once we've breached or we breach
|
|
|
|
# it as part of the loiter-at-home!
|
|
|
|
self.test_fence_breach_circle_at(self.home_position_as_mav_location(),
|
|
|
|
disable_on_breach=True)
|
2019-06-01 02:07:49 -03:00
|
|
|
|
|
|
|
def test_fence_rtl_rally(self):
|
|
|
|
ex = None
|
|
|
|
target_system = 1
|
|
|
|
target_component = 1
|
|
|
|
try:
|
|
|
|
self.progress("Testing FENCE_ACTION_RTL with rally point")
|
|
|
|
|
|
|
|
self.wait_ready_to_arm()
|
|
|
|
loc = self.home_position_as_mav_location()
|
|
|
|
self.location_offset_ne(loc, 50, -50)
|
|
|
|
|
|
|
|
self.set_parameter("RALLY_TOTAL", 1)
|
|
|
|
self.mav.mav.rally_point_send(target_system,
|
|
|
|
target_component,
|
|
|
|
0, # sequence number
|
|
|
|
1, # total count
|
|
|
|
int(loc.lat * 1e7),
|
|
|
|
int(loc.lng * 1e7),
|
|
|
|
15,
|
|
|
|
0, # "break" alt?!
|
|
|
|
0, # "land dir"
|
|
|
|
0) # flags
|
|
|
|
self.delay_sim_time(1)
|
|
|
|
self.mavproxy.send("rally list\n")
|
|
|
|
self.test_fence_breach_circle_at(loc)
|
|
|
|
except Exception as e:
|
|
|
|
self.progress("Exception caught:")
|
|
|
|
self.progress(self.get_exception_stacktrace(e))
|
|
|
|
ex = e
|
|
|
|
self.mavproxy.send('rally clear\n')
|
|
|
|
if ex is not None:
|
|
|
|
raise ex
|
|
|
|
|
2019-01-31 19:11:25 -04:00
|
|
|
def test_parachute(self):
|
|
|
|
self.set_rc(9, 1000)
|
|
|
|
self.set_parameter("CHUTE_ENABLED", 1)
|
|
|
|
self.set_parameter("CHUTE_TYPE", 10)
|
|
|
|
self.set_parameter("SERVO9_FUNCTION", 27)
|
|
|
|
self.set_parameter("SIM_PARA_ENABLE", 1)
|
|
|
|
self.set_parameter("SIM_PARA_PIN", 9)
|
|
|
|
|
|
|
|
self.load_mission("plane-parachute-mission.txt")
|
|
|
|
self.mavproxy.send("wp set 1\n")
|
|
|
|
self.change_mode('AUTO')
|
|
|
|
self.wait_ready_to_arm()
|
|
|
|
self.arm_vehicle()
|
|
|
|
self.mavproxy.expect("BANG")
|
2019-02-26 00:29:12 -04:00
|
|
|
self.disarm_vehicle(force=True)
|
2019-01-31 19:11:25 -04:00
|
|
|
self.reboot_sitl()
|
|
|
|
|
2019-04-25 21:57:19 -03:00
|
|
|
def test_parachute_sinkrate(self):
|
|
|
|
self.set_rc(9, 1000)
|
|
|
|
self.set_parameter("CHUTE_ENABLED", 1)
|
|
|
|
self.set_parameter("CHUTE_TYPE", 10)
|
|
|
|
self.set_parameter("SERVO9_FUNCTION", 27)
|
|
|
|
self.set_parameter("SIM_PARA_ENABLE", 1)
|
|
|
|
self.set_parameter("SIM_PARA_PIN", 9)
|
|
|
|
|
|
|
|
self.set_parameter("CHUTE_CRT_SINK", 9)
|
|
|
|
|
|
|
|
self.progress("Takeoff")
|
|
|
|
self.takeoff(alt=300)
|
|
|
|
|
|
|
|
self.progress("Diving")
|
|
|
|
self.set_rc(2, 2000)
|
|
|
|
self.mavproxy.expect("BANG")
|
|
|
|
|
|
|
|
self.disarm_vehicle(force=True)
|
|
|
|
self.reboot_sitl()
|
|
|
|
|
2018-12-16 18:54:05 -04:00
|
|
|
def run_subtest(self, desc, func):
|
|
|
|
self.start_subtest(desc)
|
|
|
|
func()
|
|
|
|
|
|
|
|
def test_main_flight(self):
|
|
|
|
|
|
|
|
self.change_mode('MANUAL')
|
|
|
|
|
|
|
|
# grab home position:
|
2019-09-21 03:04:51 -03:00
|
|
|
self.mav.recv_match(type='HOME_POSITION', blocking=True)
|
2018-12-16 18:54:05 -04:00
|
|
|
self.homeloc = self.mav.location()
|
2018-04-27 15:21:53 -03:00
|
|
|
|
2018-12-16 18:54:05 -04:00
|
|
|
self.run_subtest("Takeoff", self.takeoff)
|
2018-08-13 08:07:34 -03:00
|
|
|
|
2018-12-16 18:54:05 -04:00
|
|
|
self.run_subtest("Set Attitude Target", self.set_attitude_target)
|
2018-09-07 08:15:02 -03:00
|
|
|
|
2018-12-16 18:54:05 -04:00
|
|
|
self.run_subtest("Fly left circuit", self.fly_left_circuit)
|
2018-04-27 15:21:53 -03:00
|
|
|
|
2018-12-16 18:54:05 -04:00
|
|
|
self.run_subtest("Left roll", lambda: self.axial_left_roll(1))
|
2018-05-31 07:27:41 -03:00
|
|
|
|
2018-12-16 18:54:05 -04:00
|
|
|
self.run_subtest("Inside loop", self.inside_loop)
|
2018-04-27 15:21:53 -03:00
|
|
|
|
2018-12-16 18:54:05 -04:00
|
|
|
self.run_subtest("Stablize test", self.test_stabilize)
|
2018-04-27 15:21:53 -03:00
|
|
|
|
2018-12-16 18:54:05 -04:00
|
|
|
self.run_subtest("ACRO test", self.test_acro)
|
2018-04-27 15:21:53 -03:00
|
|
|
|
2018-12-16 18:54:05 -04:00
|
|
|
self.run_subtest("FBWB test", self.test_FBWB)
|
2018-04-27 15:21:53 -03:00
|
|
|
|
2018-12-16 18:54:05 -04:00
|
|
|
self.run_subtest("CRUISE test", lambda: self.test_FBWB(mode='CRUISE'))
|
2018-04-27 15:21:53 -03:00
|
|
|
|
2018-12-16 18:54:05 -04:00
|
|
|
self.run_subtest("RTL test", self.fly_RTL)
|
2018-04-27 15:21:53 -03:00
|
|
|
|
2018-12-16 18:54:05 -04:00
|
|
|
self.run_subtest("LOITER test", self.fly_LOITER)
|
2018-04-27 15:21:53 -03:00
|
|
|
|
2018-12-16 18:54:05 -04:00
|
|
|
self.run_subtest("CIRCLE test", self.fly_CIRCLE)
|
2018-04-27 15:21:53 -03:00
|
|
|
|
2018-12-16 18:54:05 -04:00
|
|
|
self.run_subtest("Mission test",
|
|
|
|
lambda: self.fly_mission(
|
|
|
|
os.path.join(testdir, "ap1.txt")))
|
2018-04-27 15:21:53 -03:00
|
|
|
|
2019-03-01 22:24:00 -04:00
|
|
|
def airspeed_autocal(self):
|
|
|
|
self.progress("Ensure no AIRSPEED_AUTOCAL on ground")
|
|
|
|
self.set_parameter("ARSPD_AUTOCAL", 1)
|
|
|
|
m = self.mav.recv_match(type='AIRSPEED_AUTOCAL',
|
|
|
|
blocking=True,
|
|
|
|
timeout=5)
|
|
|
|
if m is not None:
|
|
|
|
raise NotAchievedException("Got autocal on ground")
|
|
|
|
mission_filepath = os.path.join(testdir, "flaps.txt")
|
|
|
|
self.load_mission(mission_filepath)
|
|
|
|
self.wait_ready_to_arm()
|
|
|
|
self.arm_vehicle()
|
|
|
|
self.change_mode("AUTO")
|
|
|
|
self.progress("Ensure AIRSPEED_AUTOCAL in air")
|
|
|
|
m = self.mav.recv_match(type='AIRSPEED_AUTOCAL',
|
|
|
|
blocking=True,
|
|
|
|
timeout=5)
|
|
|
|
self.mav.motors_disarmed_wait()
|
|
|
|
|
2019-04-08 23:26:18 -03:00
|
|
|
def test_rangefinder(self):
|
|
|
|
ex = None
|
|
|
|
self.context_push()
|
|
|
|
self.progress("Making sure we don't ordinarily get RANGEFINDER")
|
2019-09-21 03:04:51 -03:00
|
|
|
m = None
|
2019-04-08 23:26:18 -03:00
|
|
|
try:
|
|
|
|
m = self.mav.recv_match(type='RANGEFINDER',
|
|
|
|
blocking=True,
|
|
|
|
timeout=5)
|
|
|
|
except Exception as e:
|
2019-08-07 01:58:25 -03:00
|
|
|
self.progress("Caught exception: %s" %
|
|
|
|
self.get_exception_stacktrace(e))
|
2019-04-08 23:26:18 -03:00
|
|
|
|
|
|
|
if m is not None:
|
|
|
|
raise NotAchievedException("Received unexpected RANGEFINDER msg")
|
|
|
|
|
|
|
|
try:
|
2019-07-10 10:57:46 -03:00
|
|
|
self.set_analog_rangefinder_parameters()
|
2019-04-08 23:26:18 -03:00
|
|
|
|
|
|
|
self.reboot_sitl()
|
|
|
|
|
|
|
|
'''ensure rangefinder gives height-above-ground'''
|
|
|
|
self.load_mission("plane-gripper-mission.txt") # borrow this
|
|
|
|
self.mavproxy.send("wp set 1\n")
|
|
|
|
self.change_mode('AUTO')
|
|
|
|
self.wait_ready_to_arm()
|
|
|
|
self.arm_vehicle()
|
2019-07-23 02:52:59 -03:00
|
|
|
self.wait_waypoint(5, 5, max_dist=100)
|
2019-04-08 23:26:18 -03:00
|
|
|
rf = self.mav.recv_match(type="RANGEFINDER", timeout=1, blocking=True)
|
|
|
|
if rf is None:
|
|
|
|
raise NotAchievedException("Did not receive rangefinder message")
|
|
|
|
gpi = self.mav.recv_match(type='GLOBAL_POSITION_INT', blocking=True, timeout=1)
|
|
|
|
if gpi is None:
|
|
|
|
raise NotAchievedException("Did not receive GLOBAL_POSITION_INT message")
|
|
|
|
if abs(rf.distance - gpi.relative_alt/1000.0) > 3:
|
|
|
|
raise NotAchievedException("rangefinder alt (%s) disagrees with global-position-int.relative_alt (%s)" % (rf.distance, gpi.relative_alt/1000.0))
|
|
|
|
self.mavproxy.expect("Auto disarmed")
|
|
|
|
|
|
|
|
self.progress("Ensure RFND messages in log")
|
|
|
|
if not self.current_onboard_log_contains_message("RFND"):
|
|
|
|
raise NotAchievedException("No RFND messages in log")
|
|
|
|
|
|
|
|
except Exception as e:
|
2019-07-08 02:24:56 -03:00
|
|
|
self.progress("Exception caught:")
|
|
|
|
self.progress(self.get_exception_stacktrace(e))
|
2019-04-08 23:26:18 -03:00
|
|
|
ex = e
|
|
|
|
self.context_pop()
|
|
|
|
self.reboot_sitl()
|
|
|
|
if ex is not None:
|
|
|
|
raise ex
|
|
|
|
|
2019-02-03 06:43:07 -04:00
|
|
|
def rc_defaults(self):
|
|
|
|
ret = super(AutoTestPlane, self).rc_defaults()
|
|
|
|
ret[3] = 1000
|
|
|
|
ret[8] = 1800
|
|
|
|
return ret
|
2018-04-27 15:21:53 -03:00
|
|
|
|
2018-12-16 18:54:05 -04:00
|
|
|
def default_mode(self):
|
|
|
|
return "MANUAL"
|
2018-04-27 15:21:53 -03:00
|
|
|
|
2019-02-28 19:04:23 -04:00
|
|
|
def test_pid_tuning(self):
|
|
|
|
self.change_mode("FBWA") # we don't update PIDs in MANUAL
|
|
|
|
super(AutoTestPlane, self).test_pid_tuning()
|
|
|
|
|
2019-04-05 02:15:33 -03:00
|
|
|
|
|
|
|
def test_setting_modes_via_auxswitches(self):
|
|
|
|
self.set_parameter("FLTMODE5", 1)
|
|
|
|
self.mavproxy.send('switch 1\n') # random mode
|
|
|
|
self.wait_heartbeat()
|
|
|
|
self.change_mode('MANUAL')
|
|
|
|
self.mavproxy.send('switch 5\n') # acro mode
|
|
|
|
self.wait_mode("CIRCLE")
|
|
|
|
self.set_rc(9, 1000)
|
|
|
|
self.set_rc(10, 1000)
|
|
|
|
self.set_parameter("RC9_OPTION", 4) # RTL
|
|
|
|
self.set_parameter("RC10_OPTION", 55) # guided
|
|
|
|
self.set_rc(9, 1900)
|
|
|
|
self.wait_mode("RTL")
|
|
|
|
self.set_rc(10, 1900)
|
|
|
|
self.wait_mode("GUIDED")
|
|
|
|
|
|
|
|
self.progress("resetting both switches - should go back to CIRCLE")
|
|
|
|
self.set_rc(9, 1000)
|
|
|
|
self.set_rc(10, 1000)
|
|
|
|
self.wait_mode("CIRCLE")
|
|
|
|
|
|
|
|
self.set_rc(9, 1900)
|
|
|
|
self.wait_mode("RTL")
|
|
|
|
self.set_rc(10, 1900)
|
|
|
|
self.wait_mode("GUIDED")
|
|
|
|
|
|
|
|
self.progress("Resetting switch should repoll mode switch")
|
|
|
|
self.set_rc(10, 1000) # this re-polls the mode switch
|
|
|
|
self.wait_mode("CIRCLE")
|
|
|
|
self.set_rc(9, 1000)
|
|
|
|
|
2019-11-05 21:52:28 -04:00
|
|
|
def wait_for_collision_threat_to_clear(self):
|
|
|
|
'''wait to get a "clear" collision message", then slurp remaining
|
|
|
|
messages'''
|
|
|
|
last_collision = self.get_sim_time()
|
|
|
|
while True:
|
|
|
|
now = self.get_sim_time()
|
|
|
|
if now - last_collision > 5:
|
|
|
|
return
|
|
|
|
self.progress("Waiting for collision message")
|
|
|
|
m = self.mav.recv_match(type='COLLISION', blocking=True, timeout=1)
|
|
|
|
self.progress("Got (%s)" % str(m))
|
|
|
|
if m is None:
|
|
|
|
continue
|
|
|
|
last_collision = now
|
|
|
|
|
|
|
|
def test_adsb_send_threatening_adsb_message(self, here):
|
|
|
|
self.progress("Sending ABSD_VEHICLE message")
|
2019-07-09 10:39:32 -03:00
|
|
|
self.mav.mav.adsb_vehicle_send(37, # ICAO address
|
2019-08-28 09:38:45 -03:00
|
|
|
int(here.lat * 1e7),
|
|
|
|
int(here.lng * 1e7),
|
2019-07-09 10:39:32 -03:00
|
|
|
mavutil.mavlink.ADSB_ALTITUDE_TYPE_PRESSURE_QNH,
|
2019-08-28 09:38:45 -03:00
|
|
|
int(here.alt*1000 + 10000), # 10m up
|
2019-07-09 10:39:32 -03:00
|
|
|
0, # heading in cdeg
|
|
|
|
0, # horizontal velocity cm/s
|
|
|
|
0, # vertical velocity cm/s
|
2019-08-28 09:38:45 -03:00
|
|
|
"bob".encode("ascii"), # callsign
|
2019-07-09 10:39:32 -03:00
|
|
|
mavutil.mavlink.ADSB_EMITTER_TYPE_LIGHT,
|
|
|
|
1, # time since last communication
|
|
|
|
65535, # flags
|
|
|
|
17 # squawk
|
|
|
|
)
|
2019-11-05 21:52:28 -04:00
|
|
|
|
|
|
|
def test_adsb(self):
|
|
|
|
self.context_push()
|
|
|
|
ex = None
|
|
|
|
try:
|
|
|
|
# message ADSB_VEHICLE 37 -353632614 1491652305 0 584070 0 0 0 "bob" 3 1 255 17
|
|
|
|
self.set_parameter("RC12_OPTION", 38) # avoid-adsb
|
|
|
|
self.set_rc(12, 2000)
|
|
|
|
self.set_parameter("ADSB_ENABLE", 1)
|
|
|
|
self.set_parameter("AVD_ENABLE", 1)
|
|
|
|
self.set_parameter("AVD_F_ACTION", mavutil.mavlink.MAV_COLLISION_ACTION_RTL)
|
|
|
|
self.reboot_sitl()
|
|
|
|
self.wait_ready_to_arm()
|
|
|
|
here = self.mav.location()
|
|
|
|
self.change_mode("FBWA")
|
|
|
|
self.delay_sim_time(2) # TODO: work out why this is required...
|
|
|
|
self.test_adsb_send_threatening_adsb_message(here)
|
|
|
|
self.progress("Waiting for collision message")
|
|
|
|
m = self.mav.recv_match(type='COLLISION', blocking=True, timeout=4)
|
|
|
|
if m is None:
|
|
|
|
raise NotAchievedException("Did not get collision message")
|
|
|
|
if m.threat_level != 2:
|
|
|
|
raise NotAchievedException("Expected some threat at least")
|
|
|
|
if m.action != mavutil.mavlink.MAV_COLLISION_ACTION_RTL:
|
|
|
|
raise NotAchievedException("Incorrect action; want=%u got=%u" %
|
|
|
|
(mavutil.mavlink.MAV_COLLISION_ACTION_RTL, m.action))
|
|
|
|
self.wait_mode("RTL")
|
|
|
|
|
|
|
|
self.progress("Sending far-away ABSD_VEHICLE message")
|
|
|
|
self.mav.mav.adsb_vehicle_send(37, # ICAO address
|
|
|
|
int(here.lat+1 * 1e7),
|
|
|
|
int(here.lng * 1e7),
|
|
|
|
mavutil.mavlink.ADSB_ALTITUDE_TYPE_PRESSURE_QNH,
|
|
|
|
int(here.alt*1000 + 10000), # 10m up
|
|
|
|
0, # heading in cdeg
|
|
|
|
0, # horizontal velocity cm/s
|
|
|
|
0, # vertical velocity cm/s
|
|
|
|
"bob".encode("ascii"), # callsign
|
|
|
|
mavutil.mavlink.ADSB_EMITTER_TYPE_LIGHT,
|
|
|
|
1, # time since last communication
|
|
|
|
65535, # flags
|
|
|
|
17 # squawk
|
|
|
|
)
|
|
|
|
self.wait_for_collision_threat_to_clear()
|
|
|
|
self.change_mode("FBWA")
|
|
|
|
|
|
|
|
self.progress("Disabling ADSB-avoidance with RC channel")
|
|
|
|
self.set_rc(12, 1000)
|
|
|
|
self.delay_sim_time(1) # let the switch get polled
|
|
|
|
self.test_adsb_send_threatening_adsb_message(here)
|
|
|
|
m = self.mav.recv_match(type='COLLISION', blocking=True, timeout=4)
|
|
|
|
print("Got (%s)" % str(m))
|
|
|
|
if m is not None:
|
|
|
|
raise NotAchievedException("Got collision message when I shouldn't have")
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
ex = e
|
|
|
|
self.context_pop()
|
|
|
|
self.reboot_sitl()
|
|
|
|
if ex is not None:
|
|
|
|
raise ex
|
2019-07-09 10:39:32 -03:00
|
|
|
|
2019-11-10 20:20:03 -04:00
|
|
|
def fly_do_guided_request(self, target_system=1, target_component=1):
|
|
|
|
self.progress("Takeoff")
|
|
|
|
self.takeoff(alt=50)
|
|
|
|
self.set_rc(3, 1500)
|
|
|
|
self.start_subtest("Ensure command bounced outside guided mode")
|
|
|
|
desired_relative_alt = 33
|
|
|
|
loc = self.mav.location()
|
|
|
|
self.location_offset_ne(loc, 300, 300)
|
|
|
|
loc.alt += desired_relative_alt
|
|
|
|
self.mav.mav.mission_item_int_send(
|
|
|
|
target_system,
|
|
|
|
target_component,
|
|
|
|
0, # seq
|
|
|
|
mavutil.mavlink.MAV_FRAME_GLOBAL,
|
|
|
|
mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,
|
|
|
|
2, # current - guided-mode request
|
|
|
|
0, # autocontinue
|
|
|
|
0, # p1
|
|
|
|
0, # p2
|
|
|
|
0, # p3
|
|
|
|
0, # p4
|
|
|
|
int(loc.lat *1e7), # latitude
|
|
|
|
int(loc.lng *1e7), # longitude
|
|
|
|
loc.alt, # altitude
|
|
|
|
mavutil.mavlink.MAV_MISSION_TYPE_MISSION)
|
|
|
|
m = self.mav.recv_match(type='MISSION_ACK', blocking=True, timeout=5)
|
|
|
|
if m is None:
|
|
|
|
raise NotAchievedException("Did not get MISSION_ACK")
|
|
|
|
if m.type != mavutil.mavlink.MAV_MISSION_ERROR:
|
|
|
|
raise NotAchievedException("Did not get appropriate error")
|
|
|
|
|
|
|
|
self.start_subtest("Enter guided and flying somewhere constant")
|
|
|
|
self.change_mode("GUIDED")
|
|
|
|
self.mav.mav.mission_item_int_send(
|
|
|
|
target_system,
|
|
|
|
target_component,
|
|
|
|
0, # seq
|
|
|
|
mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,
|
|
|
|
mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,
|
|
|
|
2, # current - guided-mode request
|
|
|
|
0, # autocontinue
|
|
|
|
0, # p1
|
|
|
|
0, # p2
|
|
|
|
0, # p3
|
|
|
|
0, # p4
|
|
|
|
int(loc.lat *1e7), # latitude
|
|
|
|
int(loc.lng *1e7), # longitude
|
|
|
|
desired_relative_alt, # altitude
|
|
|
|
mavutil.mavlink.MAV_MISSION_TYPE_MISSION)
|
|
|
|
m = self.mav.recv_match(type='MISSION_ACK', blocking=True, timeout=5)
|
|
|
|
if m is None:
|
|
|
|
raise NotAchievedException("Did not get MISSION_ACK")
|
|
|
|
if m.type != mavutil.mavlink.MAV_MISSION_ACCEPTED:
|
|
|
|
raise NotAchievedException("Did not get accepted response")
|
|
|
|
self.wait_location(loc, accuracy=100) # based on loiter radius
|
|
|
|
self.delay_sim_time(20)
|
|
|
|
self.wait_altitude(alt_min=desired_relative_alt-3,
|
|
|
|
alt_max=desired_relative_alt+3,
|
|
|
|
relative=True)
|
|
|
|
|
|
|
|
self.fly_home_land_and_disarm()
|
|
|
|
|
2018-12-16 18:54:05 -04:00
|
|
|
def tests(self):
|
|
|
|
'''return list of all tests'''
|
|
|
|
ret = super(AutoTestPlane, self).tests()
|
|
|
|
ret.extend([
|
2018-10-23 01:56:36 -03:00
|
|
|
|
2019-04-05 02:15:33 -03:00
|
|
|
("AuxModeSwitch",
|
|
|
|
"Set modes via auxswitches",
|
|
|
|
self.test_setting_modes_via_auxswitches),
|
|
|
|
|
2018-12-16 18:54:05 -04:00
|
|
|
("TestRCCamera",
|
|
|
|
"Test RC Option - Camera Trigger",
|
|
|
|
self.test_rc_option_camera_trigger),
|
2018-04-27 15:21:53 -03:00
|
|
|
|
2018-12-16 18:54:05 -04:00
|
|
|
("TestRCRelay", "Test Relay RC Channel Option", self.test_rc_relay),
|
2013-07-16 00:23:48 -03:00
|
|
|
|
2018-08-20 21:55:59 -03:00
|
|
|
("ThrottleFailsafe",
|
|
|
|
"Fly throttle failsafe",
|
|
|
|
self.test_throttle_failsafe),
|
|
|
|
|
2019-11-02 19:08:07 -03:00
|
|
|
("ThrottleFailsafeFence",
|
|
|
|
"Fly fence survives throttle failsafe",
|
|
|
|
self.test_throttle_failsafe_fence),
|
|
|
|
|
2018-12-16 18:54:05 -04:00
|
|
|
("TestFlaps", "Flaps", self.fly_flaps),
|
2011-11-12 07:13:17 -04:00
|
|
|
|
2019-05-20 09:47:01 -03:00
|
|
|
("DO_CHANGE_SPEED", "Test mavlink DO_CHANGE_SPEED command", self.fly_do_change_speed),
|
|
|
|
|
2019-08-05 08:09:07 -03:00
|
|
|
("DO_REPOSITION",
|
|
|
|
"Test mavlink DO_REPOSITION command",
|
|
|
|
self.fly_do_reposition),
|
|
|
|
|
2019-11-10 20:20:03 -04:00
|
|
|
("GuidedRequest",
|
|
|
|
"Test handling of MISSION_ITEM in guided mode",
|
|
|
|
self.fly_do_guided_request),
|
|
|
|
|
2018-12-16 18:54:05 -04:00
|
|
|
("MainFlight",
|
|
|
|
"Lots of things in one flight",
|
|
|
|
self.test_main_flight),
|
2018-09-07 20:48:45 -03:00
|
|
|
|
2018-12-16 18:54:05 -04:00
|
|
|
("TestGripperMission",
|
|
|
|
"Test Gripper mission items",
|
|
|
|
self.test_gripper_mission),
|
2018-09-07 20:48:45 -03:00
|
|
|
|
2019-01-31 19:11:25 -04:00
|
|
|
("Parachute", "Test Parachute", self.test_parachute),
|
|
|
|
|
2019-04-25 21:57:19 -03:00
|
|
|
("ParachuteSinkRate", "Test Parachute (SinkRate triggering)", self.test_parachute_sinkrate),
|
|
|
|
|
2019-03-01 22:24:00 -04:00
|
|
|
("AIRSPEED_AUTOCAL", "Test AIRSPEED_AUTOCAL", self.airspeed_autocal),
|
|
|
|
|
2019-04-08 23:26:18 -03:00
|
|
|
("RangeFinder",
|
|
|
|
"Test RangeFinder Basic Functionality",
|
|
|
|
self.test_rangefinder),
|
|
|
|
|
2019-06-01 02:07:49 -03:00
|
|
|
("FenceStatic",
|
|
|
|
"Test Basic Fence Functionality",
|
|
|
|
self.test_fence_static),
|
|
|
|
|
|
|
|
("FenceRTL",
|
|
|
|
"Test Fence RTL",
|
|
|
|
self.test_fence_rtl),
|
|
|
|
|
|
|
|
("FenceRTLRally",
|
|
|
|
"Test Fence RTL Rally",
|
|
|
|
self.test_fence_rtl_rally),
|
|
|
|
|
2019-07-09 10:39:32 -03:00
|
|
|
("ADSB",
|
|
|
|
"Test ADSB",
|
|
|
|
self.test_adsb),
|
|
|
|
|
2019-11-27 18:34:21 -04:00
|
|
|
("Button",
|
|
|
|
"Test Buttons",
|
|
|
|
self.test_button),
|
|
|
|
|
2019-09-14 01:40:06 -03:00
|
|
|
("AdvancedFailsafe",
|
|
|
|
"Test Advanced Failsafe",
|
|
|
|
self.test_advanced_failsafe),
|
|
|
|
|
2019-10-17 17:33:07 -03:00
|
|
|
("DeepStall",
|
|
|
|
"Test DeepStall Landing",
|
|
|
|
self.fly_deepstall),
|
|
|
|
|
2018-12-16 18:54:05 -04:00
|
|
|
("LogDownLoad",
|
|
|
|
"Log download",
|
|
|
|
lambda: self.log_download(
|
|
|
|
self.buildlogs_path("ArduPlane-log.bin"),
|
2018-12-14 19:17:45 -04:00
|
|
|
timeout=450,
|
2018-12-16 18:54:05 -04:00
|
|
|
upload_logs=True))
|
|
|
|
])
|
|
|
|
return ret
|