def setUpClass(self): self.swarm_config = load_json_config("swarm_config") self.swarm = Swarm(self.swarm_config.Swarm) self.ip = self.swarm.ip self.webport = self.swarm.webport self.swarmSize = 0 self.swarm_data_structure = { "Swarm": { "size": self.swarmSize, "ip": self.ip, "webport": self.webport }, "Drones": [] } for idx, drone_cfg in enumerate(self.swarm_config.Drones): drone = Drone(drone_cfg) self.swarm_data_structure.get("Drones").append(drone) self.swarmSize = idx #idx is zero based so we make is not self.swarmSize += 1 ###################################### print("Setup testConfig() complete!")
class FirstSetOfTests(DroneUnitTest): @classmethod def setUpClass(self): super(FirstSetOfTests, self).setUpClass() def test_swarm_size(self): self.assertEqual( self.swarm_data_structure.get("Drones").__len__(), self.swarmSize) def test_drone_put_request(self): for idx, drone in enumerate(self.swarm_data_structure.get("Drones")): status_code = drone.update_self_to_swarm("/Swarm") self.assertEqual(200, status_code) def test_drone_get(self): for idx, drone in enumerate(self.swarm_data_structure.get("Drones")): data = drone.get_data_from_server("/Swarm") self.assertTrue(data) def test_wait_for_swarm_ready(self): self.swarm.wait_for_swarm_ready() def test_swarm(self): swarm_config = load_json_config("swarm_config") self.swarm = Swarm(swarm_config.Swarm) self.assertTrue(self.swarm) def test_add_to_swarm(self): swarm_config = load_json_config("swarm_config") self.swarm = Swarm(swarm_config.Swarm) for idx, drone in enumerate(self.swarm_data_structure.get("Drones")): self.swarm.add_drone(self.drones[idx]) self.assertTrue(self.swarm.swarmSize(), idx + 1) """ def test_swarm_takeoff_altitude(self): altitude = 10 for idx, drone in enumerate(self.swarm_data_structure.get("Drones")): drone.arm_and_takeoff(10) self.swarm_data_structure.get("Drones")[0].wait_for_swarm_to_match_altitude() """ "" """def test_sitl_instance(self):
def __init__(self, swarm): self.swarm = swarm self.app = Flask("abc") self.app = self.app.register_blueprint self.api = Api(self.app) self.api.add_resource(Swarm.get_swarm(self.swarm), '/Swarm') for idx, drone in enumerate(self.swarm): self.newDrone(drone) if __name__ == "__main__": self.gevent_server = gevent.pywsgi.WSGIServer(('', 5000), self.app) self.gevent_server.serve_forever() #instead of self.app.run()
formationList = ["triangle", "xaxis", "yaxis", "stacked"] formationAlt = 15 waypoints = { "lat1": 47.9190654, "lon1": -97.0647079, "lat2": 47.9188605, "lon2": -97.0647106, "lat3": 47.9188623, "lon3": -97.0641875, "lat4": 47.9190798, "lon4": -97.0641875 } """ Initialize drones in the swarm """ swarm = Swarm(swarm_config.Swarm) for idx, drone_cfg in enumerate(swarm_config.Drones): drone = Drone(drone_cfg) drone.update_self_to_swarm('/Swarm') swarm.add_drone(drone) swarm.list_swarm() swarm.wait_for_swarm_ready() swarm.launch_swarm(15) # Cycle through formations and waypoints # Move to a different formation each lap for idx in range(0, 3): for idx2, drone in enumerate(swarm.swarm): drone.goto_formation(formationList[idx2], formationAlt, False)
def test_add_to_swarm(self): swarm_config = load_json_config("swarm_config") self.swarm = Swarm(swarm_config.Swarm) for idx, drone in enumerate(self.swarm_data_structure.get("Drones")): self.swarm.add_drone(self.drones[idx]) self.assertTrue(self.swarm.swarmSize(), idx + 1)
def test_swarm(self): swarm_config = load_json_config("swarm_config") self.swarm = Swarm(swarm_config.Swarm) self.assertTrue(self.swarm)
for idx in (0, instance): drone_config = { "id": default_id + idx, "ip": default_ip, "port": str(int(default_port) + (instance * 10)), "sitl": sitl, "webport": default_webport } swarm_config.get('Drones').append((drone_config)) print(swarm_config.get("Drones").__len__()) #swarm_config = Config(swarm_config) swarm = Swarm(swarm_config.Swarm) for idx in enumerate(swarm_config.Drones): drone = Drone(swarm_config.Drones[idx]) swarm.add_drone(drone) print("Finished!") """ if (sitl): import dronekit_sitl sitl = dronekit_sitl.start_default(47.920198, -97.064737) connection_string = sitl.connection_string() else: connection_string = '/dev/ttyACM0' drone = Drone(connection_string,'http://localhost',id,ip,True)
def newDrone(self, drone): self.api.add_resource(Swarm.get_drone(self.swarm, drone.id)) self.api.add_resource(drone.get_drone_data(), '/Swarm/' + str(drone.id))