"Qualifier_Tier_3", "Final_Tier_1", "Final_Tier_2",
                            "Final_Tier_3"
                        ],
                        default="Qualifier_Tier_2")
    parser.add_argument('--planning_baseline_type',
                        type=str,
                        choices=["all_gates_at_once", "all_gates_one_by_one"],
                        default="all_gates_at_once")
    parser.add_argument('--planning_and_control_api',
                        type=str,
                        choices=["moveOnSpline", "moveOnSplineVelConstraints"],
                        default="moveOnSpline")
    parser.add_argument('--enable_viz_traj',
                        dest='viz_traj',
                        action='store_true',
                        default=False)
    parser.add_argument('--enable_viz_image_cv2',
                        dest='viz_image_cv2',
                        action='store_true',
                        default=False)
    parser.add_argument('--race_tier', type=int, choices=[1, 2, 3], default=1)
    args = parser.parse_args()
    baseline_racer = BaselineRacer(drone_name="drone_1",
                                   viz_traj=args.viz_traj,
                                   viz_traj_color_rgba=[1.0, 1.0, 1.0, 1.0],
                                   viz_image_cv2=args.viz_image_cv2)
    log_monitor = log_monitor.LogMonitor()
    data_logging = open(baseline_racer.save_to_file_name, "a")

    main(args)
Ejemplo n.º 2
0
    def __init__(self,
                 drone_name="drone_1",
                 viz_traj=True,
                 viz_traj_color_rgba=[1.0, 0.0, 0.0, 1.0],
                 viz_image_cv2=True):
        ## gate idx trackers
        self.last_gate_passed_idx = -1
        self.last_gate_idx_moveOnSpline_was_called_on = -1
        self.next_gate_idx = 0
        self.next_next_gate_idx = 1

        self.drone_name = drone_name
        self.gate_poses_ground_truth = None
        self.gate_object_names_sorted = None
        self.viz_image_cv2 = viz_image_cv2
        self.viz_traj = viz_traj
        self.viz_traj_color_rgba = viz_traj_color_rgba

        self.log_monitor = log_monitor.LogMonitor()

        self.airsim_client = airsim.MultirotorClient()
        self.airsim_client.confirmConnection()
        # we need two airsim MultirotorClient objects because the comm lib we use (rpclib) is not thread safe
        # so we poll images in a thread using one airsim MultirotorClient object
        # and use another airsim MultirotorClient for querying state commands
        self.airsim_client_images = airsim.MultirotorClient()
        self.airsim_client_images.confirmConnection()
        self.airsim_client_odom = airsim.MultirotorClient()
        self.airsim_client_odom.confirmConnection()
        self.level_name = None

        self.image_callback_thread = threading.Thread(
            target=self.repeat_timer_image_callback,
            args=(self.image_callback, 0.03))
        self.is_image_thread_active = False

        self.got_odom = False
        self.odometry_callback_thread = threading.Thread(
            target=self.repeat_timer_odometry_callback,
            args=(self.odometry_callback, 0.5))
        self.is_odometry_thread_active = False

        self.MAX_NUMBER_OF_GETOBJECTPOSE_TRIALS = 10  # see https://github.com/microsoft/AirSim-NeurIPS2019-Drone-Racing/issues/383
        self.finished_race = False
        self.terminated_program = False

        ################### gate detection result variables #################
        self.img_mutex = threading.Lock()
        self.W = 0
        self.H = 0
        self.Mx = 0
        self.My = 0
        self.detect_flag = False
        self.previous_detect_flag = False

        ################# Hyper-parameter Optimization#####################
        self.hyper_opt = hyOpt.hyOpt(FINISH_GATE_IDX + 1)
        self.hyper_opt.best_hyper.set_v_range((V_MIN, V_MAX))
        self.hyper_opt.best_hyper.set_a_range((A_MIN, A_MAX))
        self.hyper_opt.best_hyper.set_d_range((D_MIN, D_MAX))
        self.hyper_opt.best_hyper.init_hypers(12, 50, 3.5)
        self.hyper_opt.best_hyper.init_time()
        self.use_new_hyper_for_next_race(self.hyper_opt.best_hyper)

        ## if the simulation crashes, continue from last iteration by putting best hyperparameters here
        # self.hyper_opt.best_hyper.v = np.array([16.7, 33.22, 31.97, 28.64, 18.95, 17.24, 22.92, 29.94, 24.93, 17.79, 11.01, 22.89, 21.46, 10.12])
        # self.hyper_opt.best_hyper.a = np.array([81.65, 114.28, 46.86, 58.83, 48.87, 108.65, 57.41, 59.12, 77.98, 65.46, 121.88, 49.9, 124.03, 74.1])
        # self.hyper_opt.best_hyper.d = np.array([4.16, 4.84, 5.19, 3.84, 3.62, 6.29, 5.65, 4.2, 5.01, 5.02, 4.61, 5.65, 5.64, 4.56])
        # self.hyper_opt.best_hyper.time = np.array([6.08, 7.51, 10.38, 13.24, 16.72, 20.04, 32.28, 35.32, 37.0, 38.96, 41.04, 43.53, 45.16, 46.21])

        self.save_to_file_name = "testaa.txt"
        self.data_logging = open(self.save_to_file_name, "a")

        # self.use_new_hyper_for_next_race(self.hyper_opt.best_hyper)

        self.iteration = 1
        self.racing_started = False