def deliver_most_items_from_product(customer_id, product_id, maximum_load, weights, order, warehouses, commands, total_time, deadline, number_of_drones): last_drone_id = 0 number_of_items_left = 1 drone = Drone.Drone(last_drone_id, maximum_load, warehouses[0].position) warehouse_chosen = order.find_next_best_warehouse(drone, warehouses, product_id) if not warehouse_chosen: pass while number_of_items_left != 0 and warehouse_chosen: next_drone_id = get_next_drone_number(last_drone_id, number_of_drones) drone = Drone.Drone(next_drone_id, maximum_load, warehouses[0].position) loaded = load_product_from_warehouse_to_drone(product_id, weights, number_of_items_left, warehouse_chosen, drone, order, warehouses, total_time, commands, 1) if not loaded: break number_of_items_loaded, total_time = loaded total_time = deliver_product_to_location_with_drone( customer_id, product_id, weights, number_of_items_loaded, drone, order, order.position, total_time, commands, 1) if total_time > deadline: break last_drone_id = drone.drone_id number_of_items_left = 0 return total_time
def setup(self): #global Drones # Create a list of all drones # If Tello mode is set then it creates Tello drones if GC.TelloMode: #self.Drones = [TD.TelloDrone(200,300), TD.TelloDrone(400,300,IP_Address="0.0.0.1")] #self.Drones = [TD.TelloDrone(200,300,65*2), TD.TelloDrone(400,300,65*3), TD.TelloDrone(300,200)] self.Drones = [] for i in range(GC.Drone_Number): self.Drones.append(TD.TelloDrone(100 + 100*i, 300, MaxSpeed=GC.Uniform_Drones_Speed, MaxYawSpeed=GC.Uniform_Yaw_Speed, IP_Address=f'0.0.0.{i}')) # Otherwise it creates 3 drones with joystick, or 2 without joystick else: if pygame.joystick.get_count() == 0: self.Drones = [Drone.Drone(200, 300, GC.FPS), Drone.Drone(800, 300, GC.FPS, GC.Uniform_Drones_Speed, 0, pygame.K_j, pygame.K_l,pygame.K_k, pygame.K_i)] else: self.Drones = [Drone.Drone(200, 300, GC.FPS), Drone.Drone(800, 300, GC.FPS, GC.Uniform_Drones_Speed, 1, Joystick_xAxis="Axis0", Joystick_yAxis="Axis1"), Drone.Drone(500, 300, GC.FPS, GC.Uniform_Drones_Speed, 2, "Button13", "Button14", "Button12", "Button11")] # Creates collision array for colouring stuff red on collision self.DronesCollided = [] for i in range(len(self.Drones)): self.DronesCollided.append(False) #self.Drones = [Drone.Drone(200,300), Drone.Drone(820,300), Drone.Drone(510, 100, 1, pygame.K_j, pygame.K_l, pygame.K_k, pygame.K_i),Drone.Drone(510, 500, 1, pygame.K_j, pygame.K_l, pygame.K_k, pygame.K_i)] # Sets up the Tello communication object by providing the Tello drones for i in self.Drones: if i.__class__ == TD.TelloDrone: if GC.TelloMode: self.TC.Add_Drone(i) else: continue
def test_that_udpate_drones_deletes_items_in_drone_list(): drone_list = [ Drone(0, AppchannelCommunicate(1)), Drone(1, AppchannelCommunicate(1)) ] expected_length = 0 updateDrones(drone_list) actual_length = len(drone_list) assert expected_length == actual_length
def test_that_udpate_drones_add_new_drones_to_the_list(mocker): drone_list = [ Drone(0, AppchannelCommunicate(1)), Drone(1, AppchannelCommunicate(1)) ] expected_list = ['2', '3'] mocker.patch('Appchannel.connectToDrone', return_value=[('2', ), ('3', )]) updateDrones(drone_list) actual_list = [i.getId() for i in drone_list] assert expected_list == actual_list
def test_that_udpate_drones_doesnt_add_already_included_drones(mocker): drone_list = [ Drone(0, AppchannelCommunicate(1)), Drone(1, AppchannelCommunicate(1)) ] expected_list = ["2", "3"] mocker.patch('Appchannel.connectToDrone', return_value=[("2", ), ("3", ), ("2", )]) updateDrones(drone_list) actual_list = [i.getId() for i in drone_list] assert expected_list == actual_list
def getObjects(): trees = set() sheep = set() wolves = set() drones = set() for i in range(num_trees): trees.add(Tree.Tree()) for i in range(num_drones): drones.add(Drone.Drone(num_sheep)) for i in range(num_wolves): if (i == num_wolves-1): wolves.add(Wolf.Wolf(True)) else: wolves.add(Wolf.Wolf(False)) for i in range(num_sheep): if (i == num_sheep-1): sheep.add(Sheep.Sheep(True)) else: sheep.add(Sheep.Sheep(False)) return {"trees": trees, "sheep": sheep, "wolves": wolves, "drones": drones}
def __init__(self): self.drone = Drone.Drone() try: self.settings = MultiwiiSettings.Settings() self.serial = self.settings.serial_port self.serial.open() time.sleep(self.settings.wakeup) except ValueError as err: print('Serial port exception:' + str(err) + '\n')
def __init__(self): self.initialize_variables() self.initialize_pub_sub() # self.uav = Drone(self.vehical_id,2*ID,0) # id, x, y self.uav = Drone(self.vehical_id) self.uav.desired_pose.pose.position.x = 1 * ID self.uav.desired_pose.pose.position.y = 0 self.uav.desired_pose.pose.position.z = 3 self.uav.command_format = 0 # Postion self.uav.set_offset(1 * ID, 0) self.uav.start_controller = True # Starts giving the commands. # rospy.Timer(rospy.Duration(0.025), self.controller) # rospy.Timer(rospy.Duration(0.5), self.update_parameters) rospy.Timer(rospy.Duration(0.001), self.get_sensor_data)
def start(): #we create the environment e = Environment() e.loadEnvironment("test2.map") #print(str(e)) # we create the map m = DMap() # initialize the pygame module pygame.init() # load and set the logo logo = pygame.image.load("logo32x32.png") pygame.display.set_icon(logo) pygame.display.set_caption("drone exploration") # we position the drone somewhere in the area x = randint(0, 19) y = randint(0, 19) #cream drona d = Drone(x, y) # create a surface on screen that has the size of 800 x 480 screen = pygame.display.set_mode((800, 400)) screen.fill(WHITE) screen.blit(e.image(), (0, 0)) # define a variable to control the main loop running = True stack.append((x, y)) # main loop while running: m.markDetectedWalls(e, d.x, d.y) d.moveDSF(m) screen.blit(m.image(d.x, d.y), (400, 0)) pygame.display.flip() time.sleep(0.3) if not stack: running = False pygame.quit()
def start(self): # init drones self.drones = [Drone(i) for i in range(Constants.num_drones)] Constants.renderer = MapRenderer(Constants.grid_dimension.x, Constants.grid_dimension.y) Constants.network = NetworkLayer(self.drones, self) # First get blocks of image points and drones self.blocks = Utility.getGridBlocks() # Equally Distribute blocks in drones self.allocations_list = Utility.get_grid_distribution(self.blocks) # Reshuffle without considering relay time already alternated self.allocations_list = Utility.shuffle_distribution(self.allocations_list, self.drones) self.connected_drones = [] self.all_connected = False self.all_connected_time = None self.relay_points = [] self.near_blocks = [] self.empty_allocations = []
import Drone import time #here you should interact with the drone voresDrone = Drone.Drone("192.168.10.1", 8889) isConnected = voresDrone.connect() if (isConnected == 'Succes'): time.sleep(2) voresDrone.takeOff() time.sleep(2) voresDrone.down(90) time.sleep(2) voresDrone.StaircaseClimbing(170, 210, [5, 5, 5], 19) voresDrone.land()
f.close() return paras if __name__ == "__main__": #Parameters.Parameters().run() paras = get_paras() row = int(paras[0].split()[0]) col = int(paras[0].split()[1]) board = Board.board policy = Policy.Policy(board, (0, 0), (0, row - 1), col, row) update_thread = Board.Threading() if paras[-3] == "roomba": drone = Drone.Drone( board, policy.roomba, paras[-2], (int(paras[-1]) if paras[-2] == "movement" else float(paras[-1])), row, col) else: drone = Drone.Drone( board, policy.random, paras[-2], (int(paras[-1]) if paras[-2] == "movement" else float(paras[-1])), row, col) drone.run() # drone_info = drone.get_stats_info() # drone_info = drone_info + (paras[-3], ) # board_info = Board.board_info.get_board_info() t = drone.get_time() # Stats.board_stats(board_info) # Stats.drone_stats(drone_info) # Stats.drone_total_stats(drone_info) WriteReport.time_info(t[0], t[1])
import Drone import socket import time voresDrone = Drone.Drone("127.0.0.1", 8889) voresDrone.connect() time.sleep(2) voresDrone.takeOff() time.sleep(2) print("\n") for i in range(5): print("Lap "+str(i+1)) voresDrone.forward("20") time.sleep(2) voresDrone.turn_cw("180") time.sleep(2) voresDrone.forward("20") time.sleep(2) voresDrone.turn_cw("180") time.sleep(2) print("\n") voresDrone.land()
import pyrealsense2 as rs import cv2 as cv import math import pcl import sys import pcl.pcl_visualization import numpy as np import pygame pygame.init() Path_Planner = Planner.Planner() #planner object created Controller = Controller.Controller() FlyBy = Drone.Drone() #pcl visualizer viewer = pcl.pcl_visualization.PCLVisualizering() #initialize the realsense pipeline for the rgb and depth frames pipeline = rs.pipeline() config = rs.config() config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30) config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8,30) # Start streaming pipeline.start(config) # Processing blocks pc = rs.pointcloud()
import CostFunction as pro import Drone as pre import Visualize as post import matplotlib.pyplot as plt import numpy as np drone1 = pre.Drone(70, 7.7, 0.009) drone2 = pre.Drone(200, 10.5, 0.012) drone3 = pre.Drone(450, 13.2, 0.018) wind1 = pre.Wind(np.random.uniform(2.0, 3.5), 0) # this time, we consider that wind goes from west to east, and its magnitude goes from 2.0 m/s to 3.5 m/s depot1 = pre.Depot("Chatenay-Malabry", 0, 0) param1 = pre.DeliveryParameters(drone1, wind1, pro.cost_b) total_cost = 0 total_savings = 0 for i in range(500): print(i) problem_i = pre.Problem(depot1) problem_i.generate_random_clients(amount=np.random.randint(50, 60), x=(-6000, 6000), y=(-3500, 3500), demand=(5, 60)) pro.clarke_and_wright(problem_i, param1, version="sequential") solution_i = problem_i.solutions_list[0] total_cost += solution_i.cost_and_savings()[0] total_savings += solution_i.cost_and_savings()[1] average = total_savings / (total_savings + total_cost)
import Drone import sys import time #here you should interact with the drone print("booting") drone1 = Drone.Drone('192.1.1.1', 8889) #Diagnostics drone1.printinfo() drone1.connect() drone1.battery() #Action #ideen er at dronen letter, vender 180grader for at få højdemåleren tættere på trinet. #flyver 5 gange 26 cm bagud drejer 90 grader mod uret, flyver 5 gange 29cm drone1.takeOff() time.sleep(2) drone1.cw(180) time.sleep(2) ymax1 = 0
import pytest import sys import cflib sys.path.append("..") from DroneDTO import * from Appchannel import AppchannelCommunicate from Drone import * from Dronesim import * drone = Drone(0, AppchannelCommunicate(0)) drone.getChannel().setBattery(90.0) drone.getChannel().setSpeed(10.0) drone.getChannel().setState(1) droneSim = Dronesim(0, 1) droneSim.setBattery("0.90") droneSim.setSpeed("10.0") droneSim.setState("1") def test_init_sim_in_mission(): global droneSim expected_attributes = [0, 90.0, 10.0, "In mission"] actual_attributes = [] droneDTO = DroneDTO(True, droneSim) actual_attributes.append(droneDTO.droneId) actual_attributes.append(droneDTO.battery) actual_attributes.append(droneDTO.speed)
"""Case study - Partitioning clients' lists for pb250_b""" import Drone as dro import CostFunction as cost import Visualize as viz import matplotlib.pyplot as plt import numpy as np drone1 = dro.Drone(180, 10.3, 0.013) drone2 = dro.Drone(510, 12.5, 0.024) wind1 = dro.Wind(0, 0) param1 = dro.DeliveryParameters(drone1, wind1, cost.cost_b) param2 = dro.DeliveryParameters(drone2, wind1, cost.cost_b) problem_g = dro.Problem() problem_g.import_csv('pb250_b.csv') best_cost = float('inf') limit = 0 for i in range(5, 151): clients_list_1 = [] clients_list_2 = [] for client in problem_g.clients_list: if client.demand > i: clients_list_2.append(client) else: clients_list_1.append(client) problem1 = cost.Problem(problem_g.depot, clients_list_1) problem2 = cost.Problem(problem_g.depot, clients_list_2)
import sys import time import Drone drone1 = Drone.Drone("128.1.1.1", 8889) drone1.connect() drone1.printinfo() drone1.takeOff() #time.sleep(2) drone1.up(50) while (drone1.battery() > 10): drone1.forward(50) drone1.cw(90) drone1.land() drone1.end()
import Drone import Controller import sys import time from signal import pause #here you should interact with the drone print("booting") drone1 = Drone.Drone('127.0.0.1', 9000) controller1 = Controller.Controller(drone1) while (True): time.sleep(0.5) if (not controller1.landed): controller1.check_roll() controller1.check_pitch() #TakeOff/landing # After starting the program you make the drone takeoff by pressing and holding the sensehat joystick # landing is done by then pressing and holding the sensehat joystick #Controls #If you pitch the sensehat forward (45-90degrees) the drone will asecend 20cm #If you pitch the sensehat backwards (45-90degrees) the drone will descend 20cm #rolling the sensehat right (45-90degrees) should make the drone Yaw(rotate on own axis) clockwise #rolling the sensehat left (45-90degrees) should make the drone Yaw(rotate on own axis) counterclockwise #**This can be dependent on your sensehat!**
import pytest import sys import cflib sys.path.append("..") from Drone import * from Appchannel import AppchannelCommunicate channel = AppchannelCommunicate(0) drone = Drone(0, channel) def test_get_id(): global drone expected_id = 0 actual_id = drone.getId() assert expected_id == actual_id def test_get_channel(): global drone global channel expected_channel = channel actual_channel = drone.getChannel() assert expected_channel == actual_channel
import Drone import sys import time # Live drone #drone_1 = drone.Drone("128.1.1.1", 8889) # Test drone # drone start up drone_1 = Drone.Drone('192.168.10.1', 8889) drone_1.printInfo(1) drone_1.connect(1) #region old # # Print out start information # print(drone_1.battery(0.1)) # print(drone_1.time(0.1)) # print(drone_1.sdk(0.1)) # print(drone_1.sn(0.1)) # # Drone flightplan # drone_1.takeOff(1) # drone_1.cw("90", 1) # drone_1.ccw("360", 1) # drone_1.cw("180", 1) # drone_1.up("60", 1) # #drone_1.flip("b", 1) # drone_1.down("30", 1) # drone_1.left("20", 1) # drone_1.right("20", 1)
def get_grid_distribution_with_range(num_drones, gridPoints, timeOfFlight, timeToClick, velocity, serverLoc, serverRange, colors): # get new range and tof based on buffer % # considering buffer of 10% tof = 0.9 * timeOfFlight allocated = 0 serverRange = 0.9 * serverRange distribution = {} startPositions = [] droneList = [] drones = 0 while allocated != len(gridPoints): drones += 1 if drones == num_drones: distribution[drones] = [] for grid_pt in gridPoints: if not grid_pt.allocated: distribution[drones].append(grid_pt) drone = Drone(drones, colors[drones - 1], velocity, serverLoc) droneList.append(drone) break startPos = gridPoints[0].coordinate # set start location for first drone if (drones == 1): for grid_pt in gridPoints: if (math.sqrt((grid_pt.coordinate[1] - serverLoc[1])**2 + (grid_pt.coordinate[0] - serverLoc[0])**2) < serverRange): startPos = grid_pt.coordinate startPositions.append(startPos) break # set start location for rest of the drones if (drones > 1): lastDronePos = startPositions[-1] for grid_pt in gridPoints: if get_distance(lastDronePos, grid_pt.coordinate) < serverRange: startPos = grid_pt.coordinate startPositions.append(startPos) break # get distance and time for travel distance = get_distance(startPos, serverLoc) timeToTravel = distance / velocity timeToMap = tof - 2 * timeToTravel if (timeToMap < 0): print( "Drones inefficient to map such a large area. Increase battery :p" ) break # list of locations distribution[drones] = [] # setting distance from server for grid_pt in gridPoints: grid_pt.set_distance_from_server(serverLoc) for grid_pt in gridPoints: if grid_pt.allocated: continue if grid_pt.distance_from_server < serverRange and drones == 1 and timeToMap > 2: distribution[drones].append(grid_pt) grid_pt.color = colors[drones - 1] timeToMap -= timeToClick grid_pt.allocated = True allocated += 1 elif drones != 1: for j in range(0, len(distribution[drones - 1])): dist_obj = distribution[drones - 1][j] loc_ = dist_obj.coordinate if math.sqrt((grid_pt.coordinate[1] - loc_[1])**2 + (grid_pt.coordinate[0] - loc_[0])**2) < serverRange and timeToMap > 2: distribution[drones].append(grid_pt) grid_pt.color = colors[drones - 1] timeToMap -= timeToClick grid_pt.allocated = True allocated += 1 break # create drones drone = Drone(drones, colors[drones - 1], velocity, serverLoc) droneList.append(drone) # print time left for drone one #print("Drone {}: \nStart Pos: {} \ndistance: {} \nTime taken: {}".format(drones,startPos,distance,tof - timeToMap)) if drones < num_drones: while drones == num_drones: drones += 1 drone = Drone(drones, colors[drones - 1], velocity, serverLoc) droneList.append(drone) distribution[drones] = [] #print(gridPoints) # # print(distribution) return droneList, distribution, gridPoints