Beispiel #1
0
    def test_info(self):
        self.assertEqual(list(self.repo.info()), [
            'id', 'uid', 'user_id', 'namespace', 'name', 'slug', 'scm',
            'git_http_url', 'git_ssh_url', 'link', 'default_branch', 'private',
            'visibility', 'active', 'config_path', 'trusted', 'protected',
            'ignore_forks', 'ignore_pull_requests', 'auto_cancel_pull_requests',
            'auto_cancel_pushes', 'timeout', 'counter', 'synced', 'created',
            'updated', 'version', 'permissions'])
        with self.assertRaises(requests.HTTPError) as err:
            Drone.Repo('tinvaan', 'foobar').info()
            self.assertEqual(err.response.status_code, 404)

            Drone.Repo('foobar', 'barfoo').info()
            self.assertEqual(err.response.status_code, 404)
Beispiel #2
0
 def setUp(self):
     self.cron = Drone.Cron('tinvaan', 'drone-test-ci')
     self.cron.create(**{
         'name': 'nightly',
         'expr': '0 0 1 * * *',
         'branch': 'master'
     })
Beispiel #3
0
    def make_drone(move_strategy, topology_sensors, destination=ExtractionPoint()):
        """
        Makes a drone (factory method). Accepts either objects or Enums as arguments.
        We can use a variety of sensors, navigation strategies, and rules, and then we pass the chosen ones
        the dependencies they need,
        For example, the topology map is needed by everyone.
        :param destination: The Destination we're looking for, such as an ExtractionPoint
        :param move_strategy: either a MoveStrategy, a function, or Enum NavigationStrategyType
        :param topology_sensors: a list containing elements of either TopologySensor, or Enum TopologySensorType
        :return:
        """

        # Map of known areas of the topology. In the future, we could persist this map and then
        # reuse it for this or any drone on subsequent missions
        topology_map = TopologyMap()

        # convert the passed-in sensor list to actual sensors in case enums were passed in
        sensors = [s if isinstance(s, TopologySensor) else DroneFactory.make_sensor(s) for s in topology_sensors]

        navigator = NavigatorFactory.make_navigator(topology_map=topology_map,
                                                    move_strategy=move_strategy,
                                                    destination=destination)

        return Drone(navigator, topology_sensors=sensors)
Beispiel #4
0
    scores[idx] = score
    times[idx] = flight_time

def thread_error_prompt(err):
    traceback.print_exception(type(err), err, err.__traceback__)
    raise type(err)(err)


if __name__ == "__main__":
    # drone = Drone(visualize=False, n_servers=0)
    # sleep(2)
    # fly(drone)
    # exit()

    execution_time = int(time())
    drones = [Drone(visualize=False, n_servers=0) for _ in range(n_drones)]
    scores = [0] * n_drones
    times = [0] * n_drones

    global_best_score = -np.Infinity
    global_best_drone = None

    thread_pool = ThreadPool(1)

    start_time = time()
    for gen in range(n_generations):
        generation_time = time() - start_time
        print(f"Time elapsed for last generation: {generation_time}")
        start_time = time()
        # TODO: find a way to do this in separate threads
        
Beispiel #5
0
 def setUp(self):
     self.repo = Drone.Repo('tinvaan', 'drone-test-ci')
Beispiel #6
0
 def test_all(self):
     self.assertGreater(len(self.repo.all()), 1)
     self.assertGreater(len(Drone.Repo('tinvaan', 'foobar').all()), 1)
     self.assertGreater(len(Drone.Repo('foobar', 'drone-ci-test').all()), 1)
Beispiel #7
0
 def setUp(self):
     self.last = 1
     self.build = Drone.Build('tinvaan', 'drone-test-ci')
     for build in self.build.all():
         self.last = max(self.last, build.get('number'))
Beispiel #8
0
def fly(
    drone: Drone,
    timesteps: int = 2500,
    delta_t: float = 0.01,
    visualize=False,
    n_servers=0,
    punish_time=False,
    reward_time=True,
    idx=None,
):

    # print(f"flying in PID: {os.getpid()}")
    # initialize coin
    coin = Coin(np.array([[5], [5], [10]]), 2, 2000)

    # initialize drone position
    wind_speed = initial_wind_speed

    # set targets
    rot_targets = np.zeros((3, 1))
    lin_targets = coin.position

    # initialize acceleration; drone should be free falling for now
    lab_lin_acc, lab_rot_acc = drone.quadcopter.calculate_accelerations(
        drone.angle, wind_speed, drone.thrust, lin_acc_drone_2_lab=True)

    for time in range(timesteps):
        real_time = time * delta_t
        if punish_time:
            drone.reward -= REWARD_TIME_PASSED
        if reward_time:
            drone.reward += REWARD_TIME_PASSED
        drone.flight_time += 1

        collected_coin = coin.is_in_vicinity(drone.position)
        if collected_coin:
            drone.reward += coin.value
            drone.coins += 1

            coin = Coin(coin.position + np.array([[5.0], [2.5], [0.0]]),
                        1,
                        value=1000)
            # coin = Coin(
            #     coin.position + (10 * np.random.random_sample(coin.position.shape)),
            #     1,
            #     value=1000
            #     )
            lin_targets = coin.position
            if visualize:
                drone.dh.new_setpoints(rot_targets, lin_targets)
                drone.dh.new_setpoints(rot_targets, lin_targets)
                drone.dh.new_setpoints(rot_targets, lin_targets)

        changed_setpoint = False
        if time % 10 == 0:
            changed_setpoint = True

        if visualize and changed_setpoint:
            drone.dh.new_setpoints(rot_targets, lin_targets)

        try:
            if not visualize and n_servers < 2:
                pass
            else:
                sleep(0.1)
        except KeyboardInterrupt:
            drone.dh.finish()

        is_crashed = drone.measure(wind_speed=wind_speed)
        if is_crashed:
            if visualize:
                drone.dh.finish(drone.reward, quit_program=False)
            drone.reward += REWARD_COIN_DISTANCE(
                coin.distance_drone_to_coin(drone.position))
            drone.distance_to_coin = coin.distance_drone_to_coin(
                drone.position)
            return drone.reward, real_time, idx

        drone.translate_input_to_thrust(coin.position)

        if visualize:
            drone.status_update(real_time, lin_targets=coin.position)
            drone.new_data(real_time, wind_speed)

    if visualize:
        drone.dh.finish(drone.reward, quit_program=False)
    drone.reward += REWARD_COIN_DISTANCE(
        coin.distance_drone_to_coin(drone.position))
    drone.distance_to_coin = coin.distance_drone_to_coin(drone.position)
    return drone.reward, real_time, idx