mirror of https://github.com/ArduPilot/ardupilot
autotest: add basic tests for Copter sprayer
This commit is contained in:
parent
edab0d12bf
commit
bac96363f4
|
@ -11,6 +11,7 @@ import os
|
|||
import shutil
|
||||
import time
|
||||
import numpy
|
||||
import operator
|
||||
|
||||
from pymavlink import quaternion
|
||||
from pymavlink import mavutil
|
||||
|
@ -8950,6 +8951,115 @@ class AutoTestCopter(AutoTest):
|
|||
self.context_pop()
|
||||
self.reboot_sitl()
|
||||
|
||||
def Sprayer(self):
|
||||
"""Test sprayer functionality."""
|
||||
self.context_push()
|
||||
ex = None
|
||||
try:
|
||||
rc_ch = 9
|
||||
pump_ch = 5
|
||||
spinner_ch = 6
|
||||
pump_ch_min = 1050
|
||||
pump_ch_trim = 1520
|
||||
pump_ch_max = 1950
|
||||
spinner_ch_min = 975
|
||||
spinner_ch_trim = 1510
|
||||
spinner_ch_max = 1975
|
||||
|
||||
self.set_parameters({
|
||||
"SPRAY_ENABLE": 1,
|
||||
|
||||
"SERVO%u_FUNCTION" % pump_ch: 22,
|
||||
"SERVO%u_MIN" % pump_ch: pump_ch_min,
|
||||
"SERVO%u_TRIM" % pump_ch: pump_ch_trim,
|
||||
"SERVO%u_MAX" % pump_ch: pump_ch_max,
|
||||
|
||||
"SERVO%u_FUNCTION" % spinner_ch: 23,
|
||||
"SERVO%u_MIN" % spinner_ch: spinner_ch_min,
|
||||
"SERVO%u_TRIM" % spinner_ch: spinner_ch_trim,
|
||||
"SERVO%u_MAX" % spinner_ch: spinner_ch_max,
|
||||
|
||||
"SIM_SPR_ENABLE": 1,
|
||||
"SIM_SPR_PUMP": pump_ch,
|
||||
"SIM_SPR_SPIN": spinner_ch,
|
||||
|
||||
"RC%u_OPTION" % rc_ch: 15,
|
||||
"LOG_DISARMED": 1,
|
||||
})
|
||||
|
||||
self.reboot_sitl()
|
||||
|
||||
self.wait_ready_to_arm()
|
||||
self.arm_vehicle()
|
||||
|
||||
self.progress("test bootup state - it's zero-output!")
|
||||
self.wait_servo_channel_value(spinner_ch, 0)
|
||||
self.wait_servo_channel_value(pump_ch, 0)
|
||||
|
||||
self.progress("Enable sprayer")
|
||||
self.set_rc(rc_ch, 2000)
|
||||
|
||||
self.progress("Testing zero-speed state")
|
||||
self.wait_servo_channel_value(spinner_ch, spinner_ch_min)
|
||||
self.wait_servo_channel_value(pump_ch, pump_ch_min)
|
||||
|
||||
self.progress("Testing turning it off")
|
||||
self.set_rc(rc_ch, 1000)
|
||||
self.wait_servo_channel_value(spinner_ch, spinner_ch_min)
|
||||
self.wait_servo_channel_value(pump_ch, pump_ch_min)
|
||||
|
||||
self.progress("Testing turning it back on")
|
||||
self.set_rc(rc_ch, 2000)
|
||||
self.wait_servo_channel_value(spinner_ch, spinner_ch_min)
|
||||
self.wait_servo_channel_value(pump_ch, pump_ch_min)
|
||||
|
||||
self.takeoff(30, mode='LOITER')
|
||||
|
||||
self.progress("Testing speed-ramping")
|
||||
self.set_rc(1, 1700) # start driving forward
|
||||
|
||||
# this is somewhat empirical...
|
||||
self.wait_servo_channel_value(pump_ch, 1458, timeout=60)
|
||||
|
||||
self.progress("Turning it off again")
|
||||
self.set_rc(rc_ch, 1000)
|
||||
self.wait_servo_channel_value(spinner_ch, spinner_ch_min)
|
||||
self.wait_servo_channel_value(pump_ch, pump_ch_min)
|
||||
|
||||
self.start_subtest("Checking mavlink commands")
|
||||
self.progress("Starting Sprayer")
|
||||
self.run_cmd(mavutil.mavlink.MAV_CMD_DO_SPRAYER,
|
||||
1, # p1
|
||||
0, # p2
|
||||
0, # p3
|
||||
0, # p4
|
||||
0, # p5
|
||||
0, # p6
|
||||
0) # p7
|
||||
|
||||
self.progress("Testing speed-ramping")
|
||||
self.wait_servo_channel_value(pump_ch, 1458, timeout=60, comparator=operator.gt)
|
||||
self.start_subtest("Stopping Sprayer")
|
||||
self.run_cmd(mavutil.mavlink.MAV_CMD_DO_SPRAYER,
|
||||
0, # p1
|
||||
0, # p2
|
||||
0, # p3
|
||||
0, # p4
|
||||
0, # p5
|
||||
0, # p6
|
||||
0) # p7
|
||||
self.wait_servo_channel_value(pump_ch, pump_ch_min)
|
||||
|
||||
self.progress("Sprayer OK")
|
||||
except Exception as e:
|
||||
self.print_exception_caught(e)
|
||||
ex = e
|
||||
self.context_pop()
|
||||
self.disarm_vehicle(force=True)
|
||||
self.reboot_sitl()
|
||||
if ex:
|
||||
raise ex
|
||||
|
||||
def tests1a(self):
|
||||
'''return list of all tests'''
|
||||
ret = super(AutoTestCopter, self).tests() # about 5 mins and ~20 initial tests from autotest/common.py
|
||||
|
@ -9135,6 +9245,7 @@ class AutoTestCopter(AutoTest):
|
|||
self.MultipleGPS,
|
||||
self.WatchAlts,
|
||||
self.GuidedEKFLaneChange,
|
||||
self.Sprayer,
|
||||
])
|
||||
return ret
|
||||
|
||||
|
|
Loading…
Reference in New Issue