def getDrone(self, args, handlers): """ Start a simulation if requested by not specifying a connection string. Then establish a connection to the drone using connection string. :param args: Th parsed command line arguments :param handlers: Handlers to pass to the Cyclone class :return: an instance of the Cyclone class """ connection_string = args.connect #sitl = None if not connection_string: # start a sitl if connection string is not specified. import dronekit_sitl self.sitl = dronekit_sitl.start_default( 51.449, 5.492) # Start the sitl at specified coordinates. #sitl = dronekit_sitl.SITL() #sitl.download("copter", "3.3") #sitl.launch(["--home=51.449,5.492,1,0 -- rate 30"], await_ready=True) # sitl.block_until_ready(verbose=True) connection_string = self.sitl.connection_string( ) # Retrieve the connection string. return Cyclone(connection_string, configs, handlers=handlers ) # Return a Cyclone object connected to the drone.
def run_game(): pygame.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) pygame.display.set_caption("yasuo is coming...") yasuo = Yasuo(ai_settings, screen) cyclone = Cyclone(ai_settings, screen, yasuo) while True: "监视键盘和鼠标事件3" #gf.check_events(ai_settings, screen, yasuo) gf.check_events(yasuo) yasuo.update() cyclone.update() gf.update_screen(ai_settings, screen, yasuo, cyclone)
def find_all_cyclones(self): self.pressures = np.arange(94000, 103000, 100) cn = plt.contour(self.ncdata.psl, levels=self.pressures) self.grid_coords_contours = get_contour_verts(cn) pressures = self.pressures grid_coords_contours = self.grid_coords_contours pmins = self.ncdata.pmins all_cyclones = [] for p, ploc in pmins: # Note swapped x, y all_cyclones.append(Cyclone(ploc[0], ploc[1], self.date)) # Create all isobars and add them to any cyclones centres they encompass, # but only if it's the only cyclone centre. for pressure, contour_set in zip(pressures, grid_coords_contours): for grid_coord_contour in contour_set: contour = np.zeros_like(grid_coord_contour) contour[:, 0] = self.f_lon(grid_coord_contour[:, 0]) contour[:, 1] = self.f_lat(grid_coord_contour[:, 1]) isobar = Isobar(pressure, contour) contained_cyclones = [] for cyclone in all_cyclones: if isobar.contains(cyclone.cell_pos): contained_cyclones.append(cyclone) # Only one cyclone contained, simple. if len(contained_cyclones) == 1: contained_cyclones[0].isobars.append(isobar) # More than one cyclone contained, see if centres are adjacent. elif len(contained_cyclones) > 1: is_found = True for i in range(len(contained_cyclones)): for j in range(i + 1, len(contained_cyclones)): cp1 = contained_cyclones[i].cell_pos cp2 = contained_cyclones[j].cell_pos #p1 = self.psl[cp1[0], cp1[1]] #p2 = self.psl[cp2[0], cp2[1]] if abs(cp1[0] - cp2[0]) > 2 or abs(cp1[1] - cp2[1]) > 2: is_found = False #if p1 != p2: #is_found = False #break if is_found: contained_cyclones[0].isobars.append(isobar) self.all_cyclones = all_cyclones
description= 'Print out vehicle state information. Connects to SITL on local PC by default.' ) parser.add_argument( '--connect', help= "vehicle connection target string. If not specified, SITL automatically started and used." ) args = parser.parse_args() connection_string = args.connect sitl = None if not connection_string: import dronekit_sitl sitl = dronekit_sitl.start_default() connection_string = sitl.connection_string() drone = Cyclone(connection_string, configs) # drone.awake_script() drone.arm_and_takeoff(5) drone.set_airspeed(5) print(drone.vehicle.location.local_frame) # drone.goto_global_NED(0, 5, 0) drone.goto_local_NED(5, 0, 0, mavutil.mavlink.MAV_FRAME_LOCAL_OFFSET_NED) # drone.goto_local_NED(0, 5, -5, mavutil.mavlink.MAV_FRAME_LOCAL_NED) # drone.set_position_target_local_NED(0, 5, -5, mavutil.mavlink.MAV_FRAME_LOCAL_NED) # time.sleep(10) print(drone.vehicle.location.local_frame) del drone
parser.add_argument( '--connect', help= "vehicle connection target string. If not specified, SITL automatically started and used." ) args = parser.parse_args() connection_string = args.connect sitl = None if not connection_string: import dronekit_sitl sitl = dronekit_sitl.SITL() sitl.download("copter", "3.3") sitl.launch(["--home=51.449,5.493,1,0 --rate 30"], await_ready=True) connection_string = sitl.connection_string() drone = Cyclone(connection_string, configs) # drone.awake_script() drone.arm_and_takeoff(5) drone.set_airspeed(5) for i in range(len(listWPs)): print('Start Mission %d' % (i + 1)) drone.goto_wp_global(LocationGlobalRelative(*listWPs[i])) # drone.mode_rtl() del drone if sitl: sitl.stop()
parser = argparse.ArgumentParser( description='Print out vehicle state information. Connects to SITL on local PC by default.') parser.add_argument( '--connect', help="vehicle connection target string. If not specified, SITL automatically started and used.") args = parser.parse_args() connection_string = args.connect sitl = None if not connection_string: import dronekit_sitl sitl = dronekit_sitl.start_default() connection_string = sitl.connection_string() drone = Cyclone(connection_string, configs) # Import compiled library of vision and pathplanning. import ctypes so = ctypes.cdll.LoadLibrary lib = so("../Python-C++ interface/libcpp_py_vision.so") path_planning = lib.output_to_py path_planning.restype = ctypes.POINTER(ctypes.c_double) # Tuples and lists for storing the trajectory information. LocationTuples = [] # VelocityTuples = [] list_location = [] # list_velocity = [] # Flag for deciding whether to plan the path (if hoop is still in sight).
handlers = [streamHandler] args = parser.parse_args() connection_string = args.connect simulate = False if args.simulate: simulate = True sitl = None if not connection_string: import dronekit_sitl sitl = dronekit_sitl.start_default() connection_string = sitl.connection_string() drone = Cyclone(connection_string, configs, handlers=handlers) # drone.awake_script() drone.obtain_home_location() if simulate: groundHeight = drone.vehicle.location.global_relative_frame.alt drone.arm_and_takeoff(groundHeight + 5) drone.obtain_home_location() else: drone.wait_for_user() drone.obtain_home_location() #drone.set_home_location() #print("Set home location. Waiting for 10 seconds") #time.sleep(10) drone.set_airspeed(5) startPosition = drone.vehicle.location.local_frame ang = drone.vehicle.attitude