def main(filename, num_frames=None): [unscrambled, scrambled] = parser.parse_file(filename) frames = [] def callback(pos, world, ticks, hopper_contents, capacity): world = copy.deepcopy(world) for x in range(len(world)): for y in range(len(world[x])): world[x][y].append(None) x, y, z = pos world[x][y][z] = (0, 255, 0) frames.append((ticks, world, hopper_contents, capacity)) d = drone.Drone(scrambled, 0, 0, callback) b = brain.Brain(d, unscrambled) try: b.mainloop() except AssertionError: traceback.print_exc() r = renderer.Renderer() if num_frames is None: r.animate(frames) else: r.animate(frames[::len(frames)//int(num_frames)] + [frames[-1]])
def fireDrone(self): """Fire a drone based weapon""" import anwp.sims # once a drone is launched weapon is no longer valid self.operational = 0 myGalaxy = self.myShip.myGalaxy myEmpire = myGalaxy.empires[self.myShip.empireID] # create drone object myDroneDesign = myEmpire.droneDesigns[self.droneID] shipID = myGalaxy.getNextID(myGalaxy.ships) myDrone = drone.Drone({'id':shipID, 'empireID':myEmpire.id}) myDrone.setMyShip(self.myShip) myDrone.setMyDesign(myDroneDesign) myDrone.setMyStatus() (myDrone.posX,myDrone.posY) = self.getMyXY() # create drone sim object imageFileName = '%s%s.png' % (myGalaxy.game.app.simImagePath, myDrone.myDesign.getImageFileName()) # create sim myDrone.setMyEntity(anwp.sims.categories.ShipCategory(imageFileName, string.lower(myDrone.myShipHull.abr)), myDrone.posX, myDrone.posY, myDrone.facing) # add sim to world speed = 0 force = 1 myGalaxy.world.addToWorld(myDrone, myDrone.posX, myDrone.posY, myDrone.facing, speed, force) myDrone.begin()
def __init__(self, socket=None): self.socket = socket self.dronesName = ["Solo Gold", "Solo Green"] self.wifiConnections = { 'Solo Gold': ['SoloLink_gold', 'sololinkmst'], 'Solo Green': ['SoloLink_MST', 'sololinkmst'] } #used to switch connection self.conn = Wireless() #array of drones initializer self.drones = { 'Solo Gold': drone.Drone('Solo Gold', self.wifiConnections['Solo Gold']), 'Solo Green': drone.Drone('Solo Green', self.wifiConnections['Solo Green']) }
def __init__(self, drones): self.drones = {} self.ode = scipy.integrate.ode(self.state_dot).set_integrator( 'vode', nsteps=500, method='bdf') self.time = datetime.datetime.now() self.lock = None for key in drones: self.drones[key] = drone.Drone(key=key, drone=drones[key], swarm=self)
def test_pathing(self): stakk = copy.deepcopy(unscrambled) mydrone = drone.Drone(stakk, 0, 0) mydrone.scan() mybrain = brain.Brain(mydrone, copy.deepcopy(scrambled)) info, goodpath = mybrain.maxInformationPath((0, 0), (3, 3)) self.assertEqual(info, 6) mybrain.travelPath(goodpath) info, goodpath = mybrain.maxInformationPath(( 3, 3, ), (0, 0)) self.assertEqual(info, 5)
def part_two(args, input_lines): "Process part two of the puzzle" # 1. Create the drone uav = drone.Drone(text=input_lines[0]) solution = uav.find_santa_size(watch=args.verbose, size=100) print( "The drone reports that the beam at (%d,%d) is big enough for SANTA, %d" % (solution[0], solution[1], solution[0] * 10000 + solution[1])) # 3. Return result return solution is not None
def part_one(args, input_lines): "Process part one of the puzzle" # 1. Create the drone uav = drone.Drone(text=input_lines[0]) # 2. Explore the beam solution = uav.explore_beam(watch=args.verbose, size=SIZE) print("The drone reports %d points are effected by the tractor beam" % (solution)) # 3. Return result return solution is not None
def wakeup(self): uni.configureLogging('fly') logging.info('good morning') # reconstitute the brain parts self.visualcortex = vc.VisualCortex() self.hippocampus = hc.Hippocampus() self.frontalcortex = fc.FrontalCortex() self.neck = nek.Neck() self.drone = drn.Drone(self.yahoo, self.sensoryMotorCircuit) if self.save_nth: self.dirframe = uni.makedir('frame') self.dirtrain = uni.makedir('train')
def test_placing(self): stakk = copy.deepcopy(unscrambled) mydrone = drone.Drone(stakk, 0, 0) # import pdb; pdb.set_trace() self.assertEqual((0, (255, 0, 0)), mydrone.scan()) mydrone.move(0, 1) self.assertEqual((0, (255, 0, 0)), mydrone.scan()) mydrone.move(1, 0) self.assertEqual((1, (255, 165, 0)), mydrone.scan()) mydrone.pickup() mydrone.dropoff((255, 165, 0), 1) self.assertEqual((1, (255, 165, 0)), mydrone.scan())
def main(): """Main function of the game, contains the game loop and initial setup""" # CONSTANTS # FPS Game_state.FPS_CLOCK = pygame.time.Clock() FPS = 30 # DISPLAY SURFACE # WIDTH AND HEIGHT DISP_INFO = pygame.display.Info() Game_state.WIN_W = round(DISP_INFO.current_w * 0.9) Game_state.WIN_H = round(DISP_INFO.current_h * 0.9) # INIT Game_state.DISP_SURF = pygame.display.set_mode( (Game_state.WIN_W, Game_state.WIN_H)) Game_state.drone = drone.Drone() add_missing_levels() load_level_stats() # CAPTION pygame.display.set_caption("Drone guy") # CREATING A CLASS MENU INSTANCE Game_state.MENU = graphics.Menu(width=Game_state.WIN_W, height=Game_state.WIN_H) Game_state.MENU.make_rects() # GAME LOOP while True: # CHECKING FOR QUIT check_for_quit() handle_key_press() pygame.display.update() pygame.event.clear() Game_state.FPS_CLOCK.tick(FPS)
def __init__(self): # hardcode the drone ID to 1 which is the drone we will be using self.drones = {1: drone.Drone()} # status variables rospy.sleep (1) # wait until everything is running self.run_ready = True self.info_ready = True # Service handlers self.mission_request_service = rospy.Service("/drone_handler/mission_request", Trigger, self.mission_request, buff_size=10) # Topic handlers # self.mavlink_msg_pub = rospy.Publisher(mavlink_lora_pub_topic, mavlink_lora_msg, queue_size=0) self.drone_info_pub = rospy.Publisher("/drone_handler/DroneInfo", DroneInfo, queue_size=0) self.nice_info_pub = rospy.Publisher("/drone_handler/NiceInfo", NiceInfo, queue_size=0) self.heartbeat_main_pub = rospy.Publisher("/drone_handler/heartbeat/main", Time, queue_size=0) self.heartbeat_run_pub = rospy.Publisher("/drone_handler/heartbeat/run", Time, queue_size=0) self.heartbeat_info_pub = rospy.Publisher("/drone_handler/heartbeat/info", Time, queue_size=0) rospy.Subscriber("/gcs/forwardPath", DronePath, self.on_drone_path) rospy.Subscriber("/gcs/moveTo", moveTo, self.on_move) rospy.Subscriber("/telemetry/heartbeat_status", telemetry_heartbeat_status, self.on_heartbeat_status) rospy.Subscriber("/telemetry/mav_mode", telemetry_mav_mode, self.on_mav_mode) rospy.Subscriber("/telemetry/statustext", telemetry_statustext, self.on_statustext) rospy.Subscriber("/telemetry/mission_info", telemetry_mission_info, self.on_mission_info) rospy.Subscriber("/telemetry/vfr_hud", telemetry_vfr_hud, self.on_vfr_hud) rospy.Subscriber("/telemetry/home_position", telemetry_home_position, self.on_home_position) rospy.Subscriber("/telemetry/cmd_retry_fail", telemetry_cmd_retry_fail, self.on_cmd_fail) rospy.Subscriber("/mavlink_interface/mission/ack", mavlink_lora_mission_ack, self.on_mission_ack) rospy.Subscriber("/mavlink_interface/command/ack", mavlink_lora_command_ack, self.on_command_ack) rospy.Subscriber("/mavlink_pos", mavlink_lora_pos, self.on_drone_pos) rospy.Subscriber("/mavlink_attitude", mavlink_lora_attitude, self.on_drone_attitude) rospy.Subscriber("/mavlink_status", mavlink_lora_status, self.on_drone_status) # rospy.Timer(rospy.Duration(0.1), self.mission_info_cb) self.rate = rospy.Rate(update_interval)
def menu_handle_input(): """Return the index of the lvl the user has chosen by clicking on it's rect (=> 0 = LVL 1), if nothing was chosen returns None""" graphics.draw_menu() # RETURN VALUE IS LVL NUMBER CHOSEN - 1 OR NONE IF NO LVL WAS CHOSEN choice = None for button in Game_state.MENU.lvl_buttons: if button.is_over(pygame.mouse.get_pos()): for event in pygame.event.get(pygame.MOUSEBUTTONDOWN): if button.get_unlocked(): choice = Game_state.MENU.lvl_buttons.index(button) # RUN CHOSEN LVL if choice is not None: Game_state.room = "lvl" Game_state.curr_lvl = Game_state.lvl_list[choice] Game_state.curr_lvl.setup() Game_state.drone = drone.Drone() Game_state.drone.rect.topleft = Game_state.curr_lvl.drone_start_pos Game_state.drone.pos_x, Game_state.drone.pos_y = Game_state.drone.rect.center Game_state.score = 0 graphics.make_lvl_UI()
import biasedCoin import drone from sympy import symbols ProbaFilter0, ProbaFilter1, ProbaFilter2, ProbaFilter3, ProbaFilter4 = symbols( 'ProbaFilter0,ProbaFilter1,ProbaFilter2,ProbaFilter3,ProbaFilter4') coin = biasedCoin.BiasedCoin() dro = drone.Drone() # p,icw_p,q,icw_q = coin.simulate(1000) # # print(p) # print(icw_p) # print(q) p, icw_p, q, icw_q = dro.simulate(10000) print("proba =") print(p) print("proba valued") print( p.subs({ ProbaFilter0: 0.30, ProbaFilter1: 0.26, ProbaFilter2: 0.20, ProbaFilter3: 0.14, ProbaFilter4: 0.10 }))
def test_gravity(self): unscrambled, scrambled = parser.parse_file("../data/overhang.txt") self.assertEqual(unscrambled[4][3][2], None) mydrone = drone.Drone(unscrambled, 4, 4) mydrone.pickup() self.assertNotEqual(unscrambled[4][3][2], None)
if t % 10 == 0: vs.draw_scene(0, []) import visuals as vs import drone as dr import pickle # """Loading them back up again""" # with open('grid_file', 'rb') as grid_file: # env.grid = pickle.load(grid_file) # # # for b in range(env.n_hubs): # with open('hub_' + str(b), 'rb') as hub_file: # env.hubs.append(pickle.load(hub_file)) # """ Create a drone each 100 timesteps """ for t in range(env.t_simulation): print(t) if t % 20 == 0: env.drones.append(dr.Drone(t)) i = 0 print(env.drones) """ Draw simulation """ while True: i += 1 if i % 1 == 0: vs.draw_scene(i % env.t_simulation, []) # Draw scene (at time t)
# Top speeds ("rotational top speed" said liberally) velmax = [1.1, 1] # (m/s, rad/s), body-frame # Maximum wrench u_max = np.array([650, 1800]) # (N, N*m) # Effective linear drag coefficients given wrench and speed limits D = np.abs(u_max / velmax) ################################################# DYNAMICS nstates = 12 ncontrols = 4 drone = drone.Drone() def dynamics(x, u, dt): """ Returns next state given last state x, wrench u, and timestep dt. Very car-like characteristics. """ # Velocity in world frame # vwx = np.cos(x[3]) * x[4] # vwy = np.sin(x[3]) * x[4] # vwz = 0.0 # # Actuator saturation # u = np.clip(u[:2], [-u_max[0]/10, -u_max[1]], u_max) # M*vdot + D*v = u and pdot = R*v # print(invM) # print("==================")
import drone import sys import time drone_1 = drone.Drone("128.1.1.1", 8889) ##//print (drone.ip) drone_1.printinfo() drone_1.connect() drone_1.takeOff() time.sleep(1) drone_1.cw("90") time.sleep(1) drone_1.ccw("360") drone_1.cw("180") time.sleep(1) print(drone_1.battery()) drone_1.land() drone_1.end()
def __init__(self): # Set up the user interface from Designer. super(mywindow, self).__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) # Modifications to interface """ add vlc interfaces for ip cameras""" # Create all required objects self.drone = drone.Drone() self.map = map.Map() self.mission = mission.Mission() # TODO add mission_planner_map_image initialisations here self.ui.mission_planner_map_image.setContentsMargins(0, 0, 0, 0) # TODO load default values here self.load_default_values() self.map_image.mousePressEvent = self.get_mouse_click_pos self.camera_1 = camera.Camera() self.camera_1.update_ip_address("192.168.1.1") self.camera_2 = camera.Camera() self.camera_2.update_ip_address("192.168.1.1") self.camera_3 = camera.Camera() self.camera_3.update_ip_address("192.168.1.1") self.camera_4 = camera.Camera() self.camera_4.update_ip_address("192.168.1.1") # set up video feeds self.media_player_1 = QtMultimedia.QMediaPlayer(self) self.media_player_1.setVideoOutput( self.ui.launchpad_monitoring_videofeed_1) # fileName = "/path/of/your/local_file" # url = QtCore.QUrl.fromLocalFile(fileName) url_1 = QtCore.QUrl( "http://devimages.apple.com/iphone/samples/bipbop/gear4/prog_index.m3u8" ) self.media_player_1.setMedia(QtMultimedia.QMediaContent(url_1)) self.media_player_1.play() self.media_player_2 = QtMultimedia.QMediaPlayer(self) self.media_player_2.setVideoOutput( self.ui.launchpad_monitoring_videofeed_2) # fileName = "/path/of/your/local_file" # url = QtCore.QUrl.fromLocalFile(fileName) url_2 = QtCore.QUrl( "http://devimages.apple.com/iphone/samples/bipbop/gear4/prog_index.m3u8" ) self.media_player_2.setMedia(QtMultimedia.QMediaContent(url_2)) self.media_player_2.play() self.media_player_3 = QtMultimedia.QMediaPlayer(self) self.media_player_3.setVideoOutput( self.ui.launchpad_monitoring_videofeed_3) # fileName = "/path/of/your/local_file" # url = QtCore.QUrl.fromLocalFile(fileName) url_3 = QtCore.QUrl( "http://devimages.apple.com/iphone/samples/bipbop/gear4/prog_index.m3u8" ) self.media_player_3.setMedia(QtMultimedia.QMediaContent(url_3)) self.media_player_3.play() self.media_player_4 = QtMultimedia.QMediaPlayer(self) self.media_player_4.setVideoOutput( self.ui.launchpad_monitoring_videofeed_4) # fileName = "/path/of/your/local_file" # url = QtCore.QUrl.fromLocalFile(fileName) url_4 = QtCore.QUrl( "http://devimages.apple.com/iphone/samples/bipbop/gear4/prog_index.m3u8" ) self.media_player_4.setMedia(QtMultimedia.QMediaContent(url_4)) self.media_player_4.play() # CONNECT BUTTONS #configuration buttons self.ui.remove_waypoint_btn.clicked.connect( self.mission.remove_waypoint) self.ui.config_camera_update_btn.clicked.connect( self.config_update_camera_parameters) self.ui.map_select_file_btn.clicked.connect(self.select_map_file) self.ui.config_map_update_btn.clicked.connect( self.config_update_map_parameters) self.ui.config_launchpad_update_btn.clicked.connect( self.config_update_launchpad_parameters) self.ui.config_uas_update_btn.clicked.connect( self.config_update_uas_parameters) # TODO TEST CODE # self.load_default_values() # TODO introduce queue processing here self.station_connection = connection.Connection('localhost', 100)
import drone # position = np.array([[0,0,0]]).T # velocity = np.array([[0,0,0]]).T # angular = np.array([[0,0,0]]).T # # orx = np.array([[1,0,0]]).T # ory = np.array([[0,1,0]]).T position = np.array([0, 0, 0]) velocity = np.array([0, 0, 0]) angular = np.array([0, 0, 0]) orx = np.array([1, 0, 0]) ory = np.array([0, 1, 0]) mass = 1.0 mrf = 5.0 rtorque = 1.0 arm = .3 print('constructing') x = drone.Drone(mass, mrf, position, velocity, angular, rtorque, orx, ory, arm) print('constructed') z = x.getOrientation() print(z) x.update(.1) print(x.getPosition()) print(x.getVelocity()) print(x.getAngular()) print(x.getLoss())
import drone import subprocess if len(sys.argv) != 5: print "Incorrect number of arguments, invoke this script with: \n \ python launch.py adressname target-latitude target-longitude flag. \n \ Addressname of sitl will run it in a simulation \n \ If flag is 1, a new terminal will be created, if it is 0, it will run on the open terminal" sys.exit() if sys.argv[4] == "1": subprocess.Popen("python launch.py %s %s %s 0" % (sys.argv[1], sys.argv[2], sys.argv[3]), creationflags=subprocess.CREATE_NEW_CONSOLE) sys.exit() address = sys.argv[1] lat = float(sys.argv[2]) lon = float(sys.argv[3]) if address == "sitl": start_lat = 41.833474 start_lon = -87.626819 import dronekit_sitl sitl = dronekit_sitl.start_default(start_lat, start_lon) address = sitl.connection_string() d = drone.Drone(address, lat, lon) d.run() d.wait()
roll *= max_power drone_command = drone.get_command_string( roll=roll, pitch=pitch, throttle=throttle, yaw=yaw, command=cmd, altitude_hold=True ) drone1.execute(drone_command) pygame.event.pump() if screen is not None: redraw_screen(screen, roll, pitch, throttle, yaw, drone_command=drone_command, pressed=pressed) clock.tick(20) finally: drone1.disconnect() curses.endwin() if __name__ == "__main__": drone1 = drone.Drone() pygame.init() pygame.joystick.init() # if you are running script without TTY, don't install curses in virtualenv screen = init_screen() if curses else None kbd = None clock = pygame.time.Clock() main_loop(drone1, screen)
GRID.fill((0, 0, 0)) # grid array ROW_MARGIN = GRID.get_height() % CELL COLUMN_MARGIN = GRID.get_width() % CELL ROWS = GRID.get_height() // CELL COLUMNS = GRID.get_width() // CELL ARRAY = [[utils.random_color() for i in range(COLUMNS)] for j in range(ROWS)] # drone constants X = (COLUMNS // 2) * CELL + PANEL.get_width() + COLUMN_MARGIN + WINDOW_MARGIN Y = (ROWS // 2) * CELL + ROW_MARGIN + WINDOW_MARGIN DRONE1 = drone.Drone() RUN = True greenbutton = utils.button((0, 200, 0), int(PANEL.get_width() // 5), 50, int(PANEL.get_width() // 2), int(PANEL.get_width() // 5), 'test') def redrawWindow(): pygame.draw.circle(WINDOW, DRONE1.color, (X, Y), DRONE1.radius) greenbutton.draw(WINDOW, (0, 0, 0)) grid = [] for row in range(ROWS):
pack = battery.BatteryPack(cells_in_series=6, max_capacity=5., weight=716.) bank = battery.BatteryBank(pack=pack, packs_in_series=2, packs_in_parallel=3) # Generator: # https://www.droneassemble.com/product/drone-hybrid-generator-power-system-for-aerial-photography-planting-and-mapping-uav-long-flight-time-endurance/ sim_generator = generator.Generator(weight=GENERATOR_WEIGHT, max_power=MAX_GENERATE_POWER, fuel_consumption=FUEL_CONSUMPTION_RATE, tank_capacity=TANK_CAPACITY, fuel_density=FUEL_DENSITY) sim_drone = drone.Drone(battery_bank=bank, powertrain=powertrain, generator=sim_generator, frame_weight=FRAME_WEIGHT, nist_payload_weight=NIST_PAYLOAD_WEIGHT) time = 0 while True: step_info = sim_drone.run_step(DT) if sim_drone.battery_bank.get_charge_percentage( ) <= MIN_BATTERY_PERCENTAGE / 100: break hours = (math.floor(time / 3600)) minutes = (math.floor(time / 60)) % 60 seconds = math.floor(time % 60)