2021-02-11 18:47:10 -04:00
|
|
|
'''
|
|
|
|
Test AntennaTracker vehicle in SITL
|
|
|
|
|
|
|
|
AP_FLAKE8_CLEAN
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
2019-02-20 19:07:53 -04:00
|
|
|
from __future__ import print_function
|
2019-11-10 17:11:50 -04:00
|
|
|
|
|
|
|
import math
|
2019-12-03 07:00:01 -04:00
|
|
|
import operator
|
2019-02-20 19:07:53 -04:00
|
|
|
import os
|
2019-11-10 17:11:50 -04:00
|
|
|
|
|
|
|
from pymavlink import mavextra
|
2019-02-20 19:07:53 -04:00
|
|
|
from pymavlink import mavutil
|
|
|
|
|
2022-02-23 08:07:15 -04:00
|
|
|
import vehicle_test_suite
|
|
|
|
from vehicle_test_suite import NotAchievedException
|
2019-02-20 19:07:53 -04:00
|
|
|
|
|
|
|
# get location of scripts
|
|
|
|
testdir = os.path.dirname(os.path.realpath(__file__))
|
2019-03-09 00:20:36 -04:00
|
|
|
SITL_START_LOCATION = mavutil.location(-27.274439, 151.290064, 343, 8.7)
|
2019-02-20 19:07:53 -04:00
|
|
|
|
2021-02-11 18:47:10 -04:00
|
|
|
|
2022-02-23 08:07:15 -04:00
|
|
|
class AutoTestTracker(vehicle_test_suite.TestSuite):
|
2019-03-09 00:20:36 -04:00
|
|
|
|
|
|
|
def log_name(self):
|
|
|
|
return "AntennaTracker"
|
|
|
|
|
2021-03-16 21:17:02 -03:00
|
|
|
def default_speedup(self):
|
|
|
|
'''Tracker seems to be race-free'''
|
|
|
|
return 100
|
|
|
|
|
2019-03-09 00:20:36 -04:00
|
|
|
def test_filepath(self):
|
2021-02-11 18:47:10 -04:00
|
|
|
return os.path.realpath(__file__)
|
2019-03-09 00:20:36 -04:00
|
|
|
|
|
|
|
def sitl_start_location(self):
|
|
|
|
return SITL_START_LOCATION
|
2019-02-20 19:07:53 -04:00
|
|
|
|
|
|
|
def default_mode(self):
|
|
|
|
return "AUTO"
|
|
|
|
|
|
|
|
def is_tracker(self):
|
|
|
|
return True
|
|
|
|
|
2019-03-09 00:20:36 -04:00
|
|
|
def default_frame(self):
|
|
|
|
return "tracker"
|
2019-02-20 19:07:53 -04:00
|
|
|
|
2020-03-10 12:03:57 -03:00
|
|
|
def set_current_test_name(self, name):
|
|
|
|
self.current_test_name_directory = "AntennaTracker_Tests/" + name + "/"
|
|
|
|
|
2019-03-09 00:20:36 -04:00
|
|
|
def apply_defaultfile_parameters(self):
|
|
|
|
# tracker doesn't have a default parameters file
|
|
|
|
pass
|
2019-02-20 19:07:53 -04:00
|
|
|
|
|
|
|
def sysid_thismav(self):
|
|
|
|
return 2
|
|
|
|
|
2019-11-10 17:11:50 -04:00
|
|
|
def achieve_attitude(self, desyaw, despitch, tolerance=1, target_system=2, target_component=1):
|
|
|
|
'''use set_attitude_target to achieve desyaw / despitch'''
|
|
|
|
tstart = self.get_sim_time()
|
|
|
|
last_attitude_target_sent = 0
|
|
|
|
last_debug = 0
|
|
|
|
self.progress("Using set_attitude_target to achieve attitude")
|
|
|
|
while True:
|
|
|
|
now = self.get_sim_time()
|
2020-01-07 20:43:40 -04:00
|
|
|
if now - tstart > 60:
|
2019-11-10 17:11:50 -04:00
|
|
|
raise NotAchievedException("Did not achieve attitude")
|
|
|
|
if now - last_attitude_target_sent > 0.5:
|
|
|
|
last_attitude_target_sent = now
|
|
|
|
type_mask = (
|
|
|
|
1 << 0 | # ignore roll rate
|
|
|
|
1 << 6 # ignore throttle
|
|
|
|
)
|
|
|
|
self.mav.mav.set_attitude_target_send(
|
|
|
|
0, # time_boot_ms
|
|
|
|
target_system, # target sysid
|
|
|
|
target_component, # target compid
|
|
|
|
type_mask, # bitmask of things to ignore
|
|
|
|
mavextra.euler_to_quat([0,
|
|
|
|
math.radians(despitch),
|
|
|
|
math.radians(desyaw)]), # att
|
|
|
|
0, # yaw rate (rad/s)
|
|
|
|
0, # pitch rate
|
|
|
|
0, # yaw rate
|
|
|
|
0) # thrust, 0 to 1, translated to a climb/descent rate
|
2022-02-09 20:59:34 -04:00
|
|
|
m = self.assert_receive_message('ATTITUDE', timeout=2)
|
2019-11-10 17:11:50 -04:00
|
|
|
if now - last_debug > 1:
|
|
|
|
last_debug = now
|
|
|
|
self.progress("yaw=%f desyaw=%f pitch=%f despitch=%f" %
|
|
|
|
(math.degrees(m.yaw), desyaw,
|
|
|
|
math.degrees(m.pitch), despitch))
|
|
|
|
yaw_ok = abs(math.degrees(m.yaw) - desyaw) < tolerance
|
|
|
|
pitch_ok = abs(math.degrees(m.pitch) - despitch) < tolerance
|
|
|
|
if yaw_ok and pitch_ok:
|
|
|
|
self.progress("Achieved attitude")
|
|
|
|
break
|
|
|
|
|
2020-03-24 23:39:40 -03:00
|
|
|
def reboot_sitl(self, *args, **kwargs):
|
|
|
|
self.disarm_vehicle()
|
|
|
|
super(AutoTestTracker, self).reboot_sitl(*args, **kwargs)
|
|
|
|
|
2019-11-10 17:11:50 -04:00
|
|
|
def GUIDED(self):
|
2022-09-09 22:24:28 -03:00
|
|
|
'''Test GUIDED mode'''
|
2020-03-24 23:39:40 -03:00
|
|
|
self.reboot_sitl() # temporary hack around control issues
|
2019-11-10 17:11:50 -04:00
|
|
|
self.change_mode(4) # "GUIDED"
|
|
|
|
self.achieve_attitude(desyaw=10, despitch=30)
|
|
|
|
self.achieve_attitude(desyaw=0, despitch=0)
|
|
|
|
self.achieve_attitude(desyaw=45, despitch=10)
|
|
|
|
|
2019-12-01 19:15:55 -04:00
|
|
|
def MANUAL(self):
|
2022-09-09 22:24:28 -03:00
|
|
|
'''Test MANUAL mode'''
|
2019-12-01 19:15:55 -04:00
|
|
|
self.change_mode(0) # "MANUAL"
|
2019-12-03 21:44:47 -04:00
|
|
|
for chan in 1, 2:
|
|
|
|
for pwm in 1200, 1600, 1367:
|
2021-02-11 18:47:10 -04:00
|
|
|
self.set_rc(chan, pwm)
|
2019-12-03 21:44:47 -04:00
|
|
|
self.wait_servo_channel_value(chan, pwm)
|
2019-12-01 19:15:55 -04:00
|
|
|
|
2023-08-25 05:00:12 -03:00
|
|
|
def MAV_CMD_DO_SET_SERVO(self):
|
2022-09-09 22:24:28 -03:00
|
|
|
'''Test SERVOTEST mode'''
|
2019-12-02 01:33:52 -04:00
|
|
|
self.change_mode(0) # "MANUAL"
|
|
|
|
# magically changes to SERVOTEST (3)
|
2023-08-25 05:00:12 -03:00
|
|
|
for method in self.run_cmd, self.run_cmd_int:
|
|
|
|
for value in 1900, 1200:
|
|
|
|
channel = 1
|
|
|
|
method(
|
|
|
|
mavutil.mavlink.MAV_CMD_DO_SET_SERVO,
|
|
|
|
p1=channel,
|
|
|
|
p2=value,
|
|
|
|
timeout=1,
|
|
|
|
)
|
|
|
|
self.wait_servo_channel_value(channel, value)
|
|
|
|
for value in 1300, 1670:
|
|
|
|
channel = 2
|
|
|
|
method(
|
|
|
|
mavutil.mavlink.MAV_CMD_DO_SET_SERVO,
|
|
|
|
p1=channel,
|
|
|
|
p2=value,
|
|
|
|
timeout=1,
|
|
|
|
)
|
|
|
|
self.wait_servo_channel_value(channel, value)
|
|
|
|
|
|
|
|
def MAV_CMD_MISSION_START(self):
|
|
|
|
'''test MAV_CMD_MISSION_START mavlink command'''
|
|
|
|
for method in self.run_cmd, self.run_cmd_int:
|
|
|
|
self.change_mode(0) # "MANUAL"
|
|
|
|
method(mavutil.mavlink.MAV_CMD_MISSION_START)
|
|
|
|
self.wait_mode("AUTO")
|
2019-12-02 01:33:52 -04:00
|
|
|
|
2019-12-03 07:00:01 -04:00
|
|
|
def SCAN(self):
|
2022-09-09 22:24:28 -03:00
|
|
|
'''Test SCAN mode'''
|
2019-12-03 07:00:01 -04:00
|
|
|
self.change_mode(2) # "SCAN"
|
|
|
|
self.set_parameter("SCAN_SPEED_YAW", 20)
|
|
|
|
for channel in 1, 2:
|
|
|
|
self.wait_servo_channel_value(channel,
|
|
|
|
1900,
|
|
|
|
timeout=90,
|
|
|
|
comparator=operator.ge)
|
|
|
|
for channel in 1, 2:
|
|
|
|
self.wait_servo_channel_value(channel,
|
|
|
|
1200,
|
|
|
|
timeout=90,
|
|
|
|
comparator=operator.le)
|
2019-12-02 01:33:52 -04:00
|
|
|
|
2019-02-27 23:14:28 -04:00
|
|
|
def disabled_tests(self):
|
2021-01-19 17:17:57 -04:00
|
|
|
return {
|
2019-02-27 23:14:28 -04:00
|
|
|
"ArmFeatures": "See https://github.com/ArduPilot/ardupilot/issues/10652",
|
2020-02-28 20:14:11 -04:00
|
|
|
"CPUFailsafe": " tracker doesn't have a CPU failsafe",
|
2021-01-19 17:17:57 -04:00
|
|
|
}
|
2019-02-27 23:14:28 -04:00
|
|
|
|
2019-02-20 19:07:53 -04:00
|
|
|
def tests(self):
|
|
|
|
'''return list of all tests'''
|
|
|
|
ret = super(AutoTestTracker, self).tests()
|
|
|
|
ret.extend([
|
2022-09-09 22:24:28 -03:00
|
|
|
self.GUIDED,
|
|
|
|
self.MANUAL,
|
2023-08-25 05:00:12 -03:00
|
|
|
self.MAV_CMD_DO_SET_SERVO,
|
|
|
|
self.MAV_CMD_MISSION_START,
|
2022-09-09 22:24:28 -03:00
|
|
|
self.NMEAOutput,
|
|
|
|
self.SCAN,
|
2019-02-20 19:07:53 -04:00
|
|
|
])
|
|
|
|
return ret
|