def test_sitl(): sitl = SITL() sitl.download('copter', '3.3') sitl.launch(copter_args) sitl.block_until_ready() assert_equals(sitl.poll(), None, 'SITL should still be running.') assert_equals(sitl.using_sim, False, 'SITL for copter-3.3 should not be using pysim') sitl.stop() assert sitl.poll() != None, 'SITL should stop running after kill.' # Test "relaunch" sitl.launch(copter_args) try: sitl.launch(copter_args) assert False, 'SITL should fail to launch() again when running' except: pass try: sitl.launch(copter_args, restart=True) except: assert False, 'SITL should succeed in launch() when restart=True' sitl.stop()
def copter_sitl_guided_to(): """ Returns a copter SITL instance for use in test cases Status: hovering at 10m AGL Mode: Guided """ # Launch a SITL using local copy of Copter 4 sitl = SITL(sitl_filename, instance=0) sitl.launch(['--home=51.454531,-2.629158,589,353']) # Wait for sitl to be ready before passing to test cases sitl.block_until_ready() # Connect to UAV to setup base parameters veh = connect(sitl.connection_string(), vehicle_class=DroneTreeVehicle) veh.parameters['SIM_SONAR_SCALE'] = 0.00001 veh.parameters['RNGFND2_ORIENT'] = 0 veh.parameters['RNGFND2_SCALING'] = 10 veh.parameters['RNGFND2_PIN'] = 0 veh.parameters['RNGFND2_TYPE'] = 1 veh.parameters['RNGFND2_MAX_CM'] = 5000 veh.parameters['RNGFND2_MIN_CM'] = 5000 veh.parameters['SIM_BATT_VOLTAGE'] = 12.59 veh.parameters['BATT_MONITOR'] = 4 veh.parameters['TERRAIN_ENABLE'] = 0 veh.parameters['ARMING_CHECK'] = 16384 # mission only veh.parameters['SIM_SPEEDUP'] = 10 # speed up SITL for rapid startup veh.parameters['FRAME_CLASS'] = 2 # I'm a hex veh.close() # close vehicle instance after setting base parameters # Stop and relaunch SITL to enable distance sensor and battery monitor sitl.stop() sitl.launch(['--home=51.454531,-2.629158,589,353'], use_saved_data=True, verbose=True) # Wait for sitl to be ready before passing to test cases sitl.block_until_ready() # Connect again veh = connect(sitl.connection_string(), vehicle_class=DroneTreeVehicle) # wait until armable while not veh.is_armable: sleep(0.5) veh.parameters['SIM_SPEEDUP'] = 5 # set sim speed for rapid take-off veh.arm() # arm veh veh.mode = VehicleMode('GUIDED') # set veh mode to GUIDED veh.wait_simple_takeoff(10) # take-off to 10m AGL veh.close() # close vehicle after guided takeoff yield sitl # Shut down simulator if it was started. if sitl is not None: sitl.stop()
def start_sitl_rover(): '''start a SITL session using sensible defaults. This should be the simplest way to start a sitl session''' print("Starting copter simulator (SITL)") sitl = SITL() sitl.download('rover', '2.50', verbose=True) sitl_args = [ '-I0', '--model', 'rover', '--home=42.2278287,-8.72184010,584,353' ] sitl.launch(sitl_args, await_ready=False, restart=True, verbose=True) sitl.block_until_ready(verbose=True) return sitl
def copter_sitl_ground(): """ Returns a copter SITL instance for use in test cases Status: on ground Mode: Stabilize """ # Launch a SITL using local copy of Copter 4 sitl = SITL(sitl_filename, instance=0) sitl.launch(['--home=51.454531,-2.629158,589,353']) # Wait for sitl to be ready before passing to test cases sitl.block_until_ready() print(sitl.connection_string()) # Connect to UAV to setup base parameters veh = connect(sitl.connection_string(), vehicle_class=DroneTreeVehicle) veh.parameters['SIM_SONAR_SCALE'] = 0.00001 veh.parameters['RNGFND2_ORIENT'] = 0 veh.parameters['RNGFND2_SCALING'] = 10 veh.parameters['RNGFND2_PIN'] = 0 veh.parameters['RNGFND2_TYPE'] = 1 veh.parameters['RNGFND2_MAX_CM'] = 5000 veh.parameters['RNGFND2_MIN_CM'] = 5000 veh.parameters['SIM_BATT_VOLTAGE'] = 12.59 veh.parameters['BATT_MONITOR'] = 4 veh.parameters['TERRAIN_ENABLE'] = 0 veh.parameters['ARMING_CHECK'] = 16384 # mission only veh.parameters['SIM_SPEEDUP'] = 10 # speed up SITL for rapid startup veh.parameters['FRAME_CLASS'] = 2 # I'm a hex veh.close() # close veh instance after setting base parameters # Stop and relaunch SITL to enable distance sensor and battery monitor sitl.stop() sitl.launch(['--home=51.454531,-2.629158,589,353'], use_saved_data=True, verbose=True) # Wait for sitl to be ready before passing to test cases sitl.block_until_ready() yield sitl # Shut down simulator if it was started. if sitl is not None: sitl.stop()
def _start_SITL(self): from dronekit_sitl import SITL sitl = SITL() sitl.download( system="copter", version="3.3", verbose=False ) # ...or download system (e.g. "copter") and version (e.g. "3.3") sitl.launch(["--home=52.52.512593, 13.321893,0,90"], verbose=False, await_ready=False, restart=False) sitl.block_until_ready( verbose=False) # explicitly wait until receiving commands connection_string = sitl.connection_string() return connection_string
def start_sitl(): """Launch a SITL using local copy of Copter 4, then set up the simulator for a rangefinder. Only works for Windows or Linux. Including binary in the project is ugly, but only used for testing.""" sitl_path = sitl_file_path() sitl = SITL(sitl_path) sitl.launch(['--home=51.454531,-2.629158,589,353']) veh = connect(sitl.connection_string(), vehicle_class=DroneTreeVehicle) veh.parameters['SIM_SONAR_SCALE'] = 0.00001 veh.parameters['RNGFND2_ORIENT'] = 0 veh.parameters['RNGFND2_SCALING'] = 10 veh.parameters['RNGFND2_PIN'] = 0 veh.parameters['RNGFND2_TYPE'] = 1 veh.parameters['RNGFND2_MAX_CM'] = 5000 veh.parameters['RNGFND2_MIN_CM'] = 5000 veh.parameters['SIM_BATT_VOLTAGE'] = 12.59 veh.parameters['BATT_MONITOR'] = 4 veh.parameters['TERRAIN_ENABLE'] = 0 veh.parameters['ARMING_CHECK'] = 16384 # mission only veh.parameters['FRAME_CLASS'] = 2 # I'm a hex veh.close() sitl.stop() sitl.launch(['--home=51.454531,-2.629158,589,353'], use_saved_data=True, verbose=True) sitl.block_until_ready() return sitl
sys.exit(0) versions = version_list() models = list(versions.keys()) print models.sort() download('copter','3.3', None) connection_string = sitl.connection_string() vehicle = dronekit.connect(connection_string, wait_ready=True) new_compass_use = 10 sitl.block_until_ready() sitl.poll() sitl.using_sim sitl.stop() sitl.poll() sitl.launch(copter_args) sitl.stop() print("Changing COMPASS_USE to {0}".format(new_compass_use)) while vehicle.parameters["COMPASS_USE"] != new_compass_use: vehicle.parameters["COMPASS_USE"] = new_compass_use time.sleep(0.1)
sitl.stop() sys.exit(0) versions = version_list() models = list(versions.keys()) print models.sort() download('copter', '3.3', None) connection_string = sitl.connection_string() vehicle = dronekit.connect(connection_string, wait_ready=True) new_compass_use = 10 sitl.block_until_ready() sitl.poll() sitl.using_sim sitl.stop() sitl.poll() sitl.launch(copter_args) sitl.stop() print("Changing COMPASS_USE to {0}".format(new_compass_use)) while vehicle.parameters["COMPASS_USE"] != new_compass_use: vehicle.parameters["COMPASS_USE"] = new_compass_use time.sleep(0.1)
from dronekit_sitl import SITL import mission args = ['--model', 'plane',] sitl = SITL() # load a binary path (optional) sitl.download("plane", "3.8.0", verbose=False) sitl.launch(args, verbose=False, await_ready=True, restart=False) sitl.block_until_ready(verbose=False) mission.start_flight(sitl.connection_string()) print(sitl.position) code = sitl.complete(verbose=False) sitl.poll() sitl.stop()
def copter_sitl_auto_to(): """ Returns a copter SITL instance for use in test cases Status: starting auto takeoff(to 20m AGL), 13 waypoints Mode: Auto """ # Launch a SITL using local copy of Copter 4 sitl = SITL(sitl_filename, instance=0) sitl.launch(['--home=51.454531,-2.629158,589,353']) # Wait for sitl to be ready before passing to test cases sitl.block_until_ready() # Connect to UAV to setup base parameters veh = connect(sitl.connection_string(), vehicle_class=DroneTreeVehicle) veh.parameters['SIM_SONAR_SCALE'] = 0.00001 veh.parameters['RNGFND2_ORIENT'] = 0 veh.parameters['RNGFND2_SCALING'] = 10 veh.parameters['RNGFND2_PIN'] = 0 veh.parameters['RNGFND2_TYPE'] = 1 veh.parameters['RNGFND2_MAX_CM'] = 5000 veh.parameters['RNGFND2_MIN_CM'] = 5000 veh.parameters['SIM_BATT_VOLTAGE'] = 12.59 veh.parameters['BATT_MONITOR'] = 4 veh.parameters['TERRAIN_ENABLE'] = 0 veh.parameters['ARMING_CHECK'] = 16384 # mission only veh.parameters['SIM_SPEEDUP'] = 10 # speed up SITL for rapid startup veh.parameters['FRAME_CLASS'] = 2 # I'm a hex veh.close() # close vehicle instance after setting base parameters # Stop and relaunch SITL to enable distance sensor and battery monitor sitl.stop() sitl.launch(['--home=51.454531,-2.629158,589,353'], use_saved_data=True, verbose=True) # Wait for sitl to be ready before passing to test cases sitl.block_until_ready() # Connect again veh = connect(sitl.connection_string(), wait_ready=True, vehicle_class=DroneTreeVehicle) # upload an arbitrary mission mission = MAVWPLoader() filename = join(abspath(sys.path[0]), 'executable_mission.txt') mission.load(filename) # bit of a hack: fix the sequence number for w in mission.wpoints: w.seq = w.seq + 1 cmds = veh.commands cmds.clear() wplist = mission.wpoints[:] # add a dummy command on the front # just the first WP used as a placeholder # upload seems to skip the first WP cmds.add(wplist[0]) for wp in wplist: cmds.add(wp) cmds.upload() # wait until armable while not veh.is_armable: sleep(0.5) veh.parameters['SIM_SPEEDUP'] = 5 # set sim speed for rapid take-off sleep(0.5) # wait for parameter change to take place veh.arm() # arm vehicle # Perform an auto take-off veh.mode = VehicleMode('AUTO') # change mode to auto veh.channels.overrides['3'] = 1700 # raise throttle to confirm T/O # wait for take-off while veh.location.global_relative_frame.alt < 0.5: sleep(0.5) veh.close() # close vehicle instance after auto takeoff yield sitl # Shut down simulator if it was started. if sitl is not None: sitl.stop()