Example #1
0
    def __init__(self):
        self.datasetfromfile = filereader.readFile("data_set/busy_day.in")
        self.gridx = self.datasetfromfile[0]
        self.gridy = self.datasetfromfile[1]
        self.warehouseObjects = self.datasetfromfile[2]
        self.droneCount = self.datasetfromfile[3]
        self.maxCommands = self.datasetfromfile[4]
        self.maxPayload = self.datasetfromfile[5]
        self.orderObjects = self.datasetfromfile[6]
        self.productWeights = self.datasetfromfile[7]

        # Create the drones
        for i in xrange(self.droneCount):
            self.drones.append(
                drone.drone(self.warehouseObjects[0].location,
                            self.maxPayload))

        # Calculate the nearest wearhouse to each order and vise-versa
        type(self.orderObjects)
        for order in self.orderObjects:
            calculatedDistances = []
            for wh in self.warehouseObjects:
                calculatedDistances.append(
                    travelTime(order.location, wh.location))
            order.mywarehouse = self.warehouseObjects[
                calculatedDistances.index(min(calculatedDistances))]
            wh.deliveryPoints.append(order)

        # for wh1 in self.warehouseObjects:
        #     calculatedDistances = []
        #     for wh2 in self.warehouseObjects:
        #         calculatedDistances.append(travelTime(order.location,wh.location)
        #     order.mywarehouse = self.warehouseObjects[calculatedDistances.index(min(calculatedDistances))]

        # wh.excessInventory
        # wh.wishlist
        # for wh1 in self.self.warehouseObjects:
        #     for wh2 in self.self.warehouseObjects:

        self.commandList = list()
        for wh1 in self.warehouseObjects:
            for wh2 in self.warehouseObjects:
                if wh1 == wh2:
                    continue
                for wl in wh1.wishlist:
                    for el in wh2.excessInventory:
                        if wl in el:
                            self.commandList.append(
                                (wh1, wh2, wh1.wishlist.index(wl)))
                            wh2.excessInventory.remove(wl)
                            wh2.allProducts.remove(wl)
                            wh1.wishlist.remove(wl)
                            wh1.allProducts.append(wl)
        print self.commandList
Example #2
0
    def __init__(self):
        self.datasetfromfile = filereader.readFile("data_set/busy_day.in")
        self.gridx = self.datasetfromfile[0]
        self.gridy = self.datasetfromfile[1]
        self.warehouseObjects = self.datasetfromfile[2]
        self.droneCount = self.datasetfromfile[3]
        self.maxCommands = self.datasetfromfile[4]
        self.maxPayload = self.datasetfromfile[5]
        self.orderObjects = self.datasetfromfile[6]
        self.productWeights = self.datasetfromfile[7]

        # Create the drones
        for i in xrange(self.droneCount):
            self.drones.append(drone.drone(self.warehouseObjects[0].location, self.maxPayload))

        # Calculate the nearest wearhouse to each order and vise-versa
        type(self.orderObjects)
        for order in self.orderObjects:
            calculatedDistances = []
            for wh in self.warehouseObjects:
                calculatedDistances.append(travelTime(order.location,wh.location))
            order.mywarehouse = self.warehouseObjects[calculatedDistances.index(min(calculatedDistances))]
            wh.deliveryPoints.append(order)


        # for wh1 in self.warehouseObjects:
        #     calculatedDistances = []
        #     for wh2 in self.warehouseObjects:
        #         calculatedDistances.append(travelTime(order.location,wh.location)
        #     order.mywarehouse = self.warehouseObjects[calculatedDistances.index(min(calculatedDistances))]


            # wh.excessInventory
            # wh.wishlist
            # for wh1 in self.self.warehouseObjects:
            #     for wh2 in self.self.warehouseObjects:

        self.commandList = list()
        for wh1 in self.warehouseObjects:
            for wh2 in self.warehouseObjects:
                if wh1 == wh2:
                    continue
                for wl in wh1.wishlist:
                    for el in wh2.excessInventory:
                        if wl in el:
                            self.commandList.append((wh1,wh2,wh1.wishlist.index(wl)))
                            wh2.excessInventory.remove(wl)
                            wh2.allProducts.remove(wl)
                            wh1.wishlist.remove(wl)
                            wh1.allProducts.append(wl)
        print self.commandList
Example #3
0
    def set_environment(self, n):
        # scatter beacons on the map
        self.num_beacon = n

        beacon_position = self.set_beacon(self.num_beacon)
        beacons = []
        beacon_info = []
        for i in range(self.num_beacon):
            bea = beacon()
            position = beacon_position[i, :]
            info = tuple((i + 1, position))
            beacon_info.append(info)
            bea.set_beacon_info(i + 1, position)
            beacons.append(bea)
        self.beacons = beacons

        # true beacon information
        self.beacon_info = beacon_info
        self.drone = drone()
Example #4
0
	def connectDrone(self, secondsPerPhoto):
		self.lock.acquire()
		instanceDrone = drone.drone(self.numVehicle)
		instanceDrone.startDrone()
		print "Connected to vehicle: %s" % instanceDrone.UdpPort
		try:
			self.vehicle = connect('127.0.0.1:%s' % instanceDrone.UdpPort, baud=115200, wait_ready=True, heartbeat_timeout=120)
			#	self.vehicle = connect('/dev/ttyUSB0', baud=57600, wait_ready=True, heartbeat_timeout=120)
			self.vehicle.parameters['SYSID_THISMAV'] = self.numVehicle + 1
		# Bad TCP connection
		except socket.error:
    			print 'No server exists!'
			exit()

		# Bad TTY connection
		except exceptions.OSError as e:
    			print 'No serial exists!'
			exit()

		# API Error
		except APIException:
    			print 'Timeout!'
			exit()
		# Other error
		except:
    			print 'Some other error!'
			exit()

		self.lock.release()
		
		self.FPV = FPVSystem.FPVSystem(secondsPerPhoto, self.numVehicle)
		t = threading.Thread(target=self.FPV.videoCapture)
		t.daemon = True
		t.start()

		self.takeoff(10)
		self.inFlight = True
Example #5
0
import numpy as np
from time import sleep
import cv2 as cv
import glob
import calibrate
import os.path

test = False

if test:
    import drone
    x, y, z, x_vel, y_vel, z_vel, rot, n = 0, 0, 0, 0, 0, 0, 0, 1
    dr = drone.drone(x, y, z, x_vel, y_vel, z_vel, rot, n)

    print("Drone ID: " + str(dr.id))
    print("Drones in range: " + str(dr.dataArr))
    print("Drone info: " + str(dr))

    #print("Camera: " + str(dr.c.physCamera))
    #print("Camera Intrinsic Array: " + str(dr.c.k))

    sleep(2)

    retake = False

    if retake:
        for i in range(12):
            _f = dr.c.photo()
            print(_f)
            print(_f.shape)
            strformat = "%d.jpg" % i
Example #6
0
    def __init__(self, _num_adv, _num_agents, _num_drones):

        g_var.num_of_adverseries = _num_adv
        g_var.num_of_agents = _num_agents
        g_var.num_of_drones = _num_drones

        # re-initialization of result variables

        g_var.arrested_poachers = 0
        g_var.fled_poachers = 0
        g_var.resource_poached = 0
        g_var.resource_recovered = 0
        g_var.distance_travelled = 0

        self.refresh_counter = 0
        #g_var.movement_limit = 100

        print "Parameters: adversaries: " + str(g_var.num_of_adverseries),\
        ", agents: " + str(g_var.num_of_agents),\
        ", drones: " + str(g_var.num_of_drones)

        self.root = Tk()
        self.root.title("Green Security Game")
        self.root.geometry('640x480+600+0')
        self.canvas = Canvas(self.root, bg="#333333", height=480, width=640)
        self.canvas.pack()
        Frame.__init__(self)

        self.agent_pos = [[0 for i in range(g_var.dimension)]
                          for j in range(g_var.dimension)]
        self.adv_pos = [[0 for i in range(g_var.dimension)]
                        for j in range(g_var.dimension)]
        self.drone_pos = [[0 for i in range(g_var.dimension)]
                          for j in range(g_var.dimension)]
        self.drone_signal = [[0 for i in range(g_var.dimension)]
                             for j in range(g_var.dimension)]
        self.target_pos = []
        self.round_marking = []
        self.object_list = []
        self.subarea_y = [[0.0, (1.0 / 3)], [(1.0 / 3), (2.0 / 3)],
                          [(2.0 / 3), 1.0]]
        self.subarea_x = [[0.0, (1.0 / 3)], [(1.0 / 3), (2.0 / 3)],
                          [(2.0 / 3), 1.0]]

        self.subarea_check_agent = [[0 for i in range(3)] for j in range(3)]
        self.subarea_check_drone = [[0 for i in range(3)] for j in range(3)]
        self.cell_resources = [[4, 9, 6, 7, 0, 2, 1, 6, 7, 0],
                               [13, 50, 0, 0, 50, 0, 50, 0, 0, 21],
                               [14, 0, 19, 13, 24, 23, 36, 17, 0, 11],
                               [17, 50, 40, 10, 50, 50, 50, 6, 0, 6],
                               [10, 31, 20, 13, 50, 0, 0, 10, 50, 3],
                               [9, 34, 30, 10, 50, 50, 50, 10, 0, 5],
                               [11, 37, 10, 22, 17, 15, 12, 10, 0, 6],
                               [13, 0, 50, 14, 33, 17, 50, 32, 26, 11],
                               [7, 0, 0, 50, 0, 0, 0, 50, 13, 23],
                               [11, 12, 31, 10, 9, 8, 11, 13, 14, 21]]

        for i in range(g_var.dimension):
            for j in range(g_var.dimension):
                if self.cell_resources[i][j] > 0:
                    self.target_pos.append((i, j))
                if self.cell_resources[i][j] == -1:
                    self.round_marking.append((i, j))
        self.round_marking.append((5, 5))  # temporary dummy

        self.cell_coord = [[
            i.__str__() + "," + j.__str__() for i in range(g_var.dimension)
        ] for j in range(g_var.dimension)]
        self.label_poacher_num = Label(self.root,
                                       text="Number of Total \nPoachers:\n" +
                                       str(g_var.num_of_adverseries))
        self.label_poacher_num.place(relx=0.78, rely=0.05)

        self.label_arrest = Label(self.root, text=g_var.arrested_poachers)
        self.label_arrest.place(relx=0.78, rely=0.2)
        self.label_fled = Label(self.root, text=g_var.fled_poachers)
        self.label_fled.place(relx=0.78, rely=0.3)
        self.label_sack = Label(self.root, text=g_var.resource_poached)
        self.label_sack.place(relx=0.78, rely=0.4)
        self.label_recovered = Label(self.root, text=g_var.resource_poached)
        self.label_recovered.place(relx=0.78, rely=0.5)
        self.label_travelled = Label(self.root, text=g_var.distance_travelled)
        self.label_travelled.place(relx=0.78, rely=0.6)

        self.label_agent_num = Label(self.root,
                                     text="Number of Agents:\n" +
                                     str(g_var.num_of_agents))
        self.label_agent_num.place(relx=0.78, rely=0.7)
        self.label_drone_num = Label(self.root,
                                     text="Number of Drones:\n" +
                                     str(g_var.num_of_drones))
        self.label_drone_num.place(relx=0.78, rely=0.8)

        self.refresh()
        self.canvas.create_rectangle(0,
                                     0,
                                     g_var.dimension * g_var.block_size,
                                     g_var.dimension * g_var.block_size,
                                     fill=g_var.bg_color)

        # for ONE TIME labelling *******************************************
        for i in range(g_var.dimension):
            for j in range(g_var.dimension):
                self.coord_label = Label(self.root,
                                         text=self.cell_coord[i][j],
                                         bg="black",
                                         fg="white")
                self.coord_label.place(x=i * g_var.block_size + 2,
                                       y=j * g_var.block_size + 18)

        for i in range(g_var.dimension + 1):
            for j in range(g_var.dimension + 1):
                self.canvas.create_rectangle(i * g_var.block_size,
                                             j * g_var.block_size,
                                             g_var.block_size,
                                             g_var.block_size,
                                             outline="grey")

        for i in range(g_var.num_of_agents):
            sub_y = random.randint(0, 2)
            sub_x = random.randint(0, 2)
            while self.subarea_check_agent[sub_y][sub_x] >= 1:
                sub_y = random.randint(0, 2)
                sub_x = random.randint(0, 2)
            self.subarea_check_agent[sub_y][sub_x] += 1

            agent_obj = agent(self.canvas, self.root, self.agent_pos,
                              self.cell_resources, self.target_pos,
                              self.round_marking, self.drone_signal,
                              self.subarea_y[sub_y], self.subarea_x[sub_x],
                              self.adv_pos)
            #agent_obj.move_spec_guard()
            agent_obj.move_agent()
            self.object_list.append(agent_obj)

        for i in range(g_var.num_of_drones):
            sub_y = random.randint(0, 2)
            sub_x = random.randint(0, 2)
            while self.subarea_check_drone[sub_y][sub_x] >= 1:
                sub_y = random.randint(0, 2)
                sub_x = random.randint(0, 2)
            #sub_y = 1
            #sub_x = 1
            self.subarea_check_drone[sub_y][sub_x] += 1

            drone_obj = drone(self.canvas, self.root, self.drone_pos,
                              self.drone_signal, self.adv_pos,
                              self.subarea_y[sub_y], self.subarea_x[sub_x])
            drone_obj.move_drone()
            self.object_list.append(drone_obj)

        for i in range(g_var.num_of_adverseries):
            adv_obj = adv(self.canvas, self.root, self.agent_pos,
                          self.drone_pos, self.cell_resources, self.target_pos,
                          self.adv_pos)
            adv_obj.operate_adv()
            self.object_list.append(adv_obj)

        self.root.mainloop()
Example #7
0
                Robot.console.reset_console()
                print("READY READY READY READY READY READY READY READY")
                Robot.sound.tone([(900, 500, 100)], play_type=1)

    # Checks if the user is pressing the right and center buttons

    if Robot.button.right == True:
        print("RUN 4 RUN 4 RUN 4 RUN 4 RUN 4 RUN 4 RUN 4")
        Robot.sound.tone([(500, 350, 50), (500, 350, 50), (500, 350, 50),
                          (500, 350, 50)],
                         play_type=1)
        for int in range(0, 1400):
            if Robot.button.enter == True:
                print("RUN 4 RUN 4 RUN 4 RUN 4 RUN 4 RUN 4 RUN 4")
                Robot.sleep(0.2)

                drone()

                Robot.console.reset_console()
                print("READY READY READY READY READY READY READY READY")
                Robot.sound.tone([(900, 500, 100)], play_type=1)
            elif Robot.button.left == True:
                print("DRONE PLUS DRONE PLUS")
                Robot.sleep(0.2)

                drone_plus()

                Robot.console.reset_console()
                print("READY READY READY READY READY READY READY READY")
                Robot.sound.tone([(900, 500, 100)], play_type=1)
Example #8
0
        # PRE = rE-Econsumed-pathLoss
        # if (PRE > pre):
        #     pre = T
        #     nH = d
        ####-inner for-#####
        # nH.head = True
        cHeads.append(nH)
    ###-outer for-###
    print("New cluster Heads appointed.")


CLOUD = cloud()
# N=int(input("Enter no.of IoT drones:"))
N = 12
invalidTxns = []
dList = [drone(i % 4) for i in range(N)]
zones = {0: [], 1: [], 2: [], 3: []}
cHeads = []
for d in dList:
    zones[d.zone].append(d)
for eachZone in zones:
    node = random.choice(zones[eachZone])
    node.head = True
    cHeads.append(node)

network = {'drones': dList, 'heads': cHeads, 'lastBlock': None, 'txns': []}

winsound.Beep(600, 400)
# start=time()
for S in dList:
    msg = 'X'
Example #9
0
 def addDrone(self):
     self.drones.append(drone.drone())
Example #10
0
        setbasecolors()
        for _ in range(4):
            t = Thread(target=godzilla)
            t.start()
            time.sleep(10)

        setbasecolors()
        for _ in range(5):
            t = Thread(target=witch)
            t.start()
            time.sleep(10)
            setbasecolors()

        name = "spooky_drone"
        drone(name)

        setbasecolors()
        name = "chains"
        for _ in range(2):
            t = Thread(target=chains, args=(name, ))
            t.start()
            time.sleep(10)

        setbasecolors()
        name = "thunder"
        for _ in range(5):
            t = Thread(target=thunder)
            t.start()
            time.sleep(12)
Example #11
0
              setbasecolors()
              for _ in range(4):
                  t = Thread(target=godzilla)
                  t.start()
                  time.sleep(10)

              setbasecolors()
              for _ in range(5):
                  t = Thread(target=witch)
                  t.start()
                  time.sleep(10)
                  setbasecolors()

              name = "spooky_drone"
              drone(name)

              setbasecolors()
              name = "chains"
              for _ in range(2):
                  t = Thread(target=chains, args=(name,))
                  t.start()
                  time.sleep(10)

              setbasecolors()
              name = "thunder"
              for _ in range(5):
                 t = Thread(target=thunder)
                 t.start()
                 time.sleep(12)