microsoft / AirSim-Drone-Racing-Lab

A framework for drone racing research, built on Microsoft AirSim.
MIT License
191 stars 44 forks source link

MultiRotorClient has no attribute race_tier #3

Open yannbouteiller opened 3 years ago

yannbouteiller commented 3 years ago

Hello,

I am upgrading the Gym environment that I made during the 2019 competition to ADRL, and I found this bug.

When calling simGetObjectPause() before simStartRace(), there is an error because race_tier is not in initialized:

File "C:\Users\Yann\Desktop\git\gym_game_of_drones\gym_game_of_drones\envs\multi_agent\gym_airsimdroneracinglab\rewardfunction.py", line 192, in get_ground_truth_gate_poses_and_half_dims
    p = self.airsim_client.simGetObjectPose(object_name=gate_name)
  File "C:\Users\Yann\anaconda3\envs\adrl\lib\site-packages\airsimdroneracinglab\client.py", line 411, in simGetObjectPose
    if self.race_tier is None:
AttributeError: 'MultirotorClient' object has no attribute 'race_tier'
Exception ignored in: <function GameOfDatasets.__del__ at 0x000001962260B3A0>
Traceback (most recent call last):
  File "C:\Users\Yann\Desktop\git\gym_game_of_drones\gym_game_of_drones\dataset_collector_game.py", line 495, in __del__
    self.env.stop()
AttributeError: 'GameOfDatasets' object has no attribute 'env'

Process finished with exit code 1
yannbouteiller commented 3 years ago

Oh well and it is not related but if you modify the API's code can you also modify simStartRace() to allow for controlling both drones instead of competing against the baseline @madratman please?

Personally I replace it with this:

def simStartRace(self, tier=1, competitor=True):
        """ Starts an instance of a race in your given level, if valid."""
        self.race_tier = tier
        if tier == 2 or not competitor:
            self.client.call("simStartRace", tier)
            return
        else:
            client_instance = self.__class__()
            competitor = BaselineRacer(
                client_instance,
                viz_traj=False,
                viz_traj_color_rgba=[1.0, 1.0, 0.0, 1.0],
            )
            competitor.level_name = self.level_name
            competitor.initialize_drone()
            competitor.gate_poses_ground_truth = [
                self.__internalRandomGoalZone(gate)
                for gate in sorted(self.simListSceneObjects(".*[Gg]ate.*"))
            ]
            if self.level_name == "Soccer_Field_Medium":
                curr_pose = deepcopy(competitor.gate_poses_ground_truth[19])
                curr_pose.position.x_val = (
                    competitor.gate_poses_ground_truth[19].position.x_val
                    + competitor.gate_poses_ground_truth[20].position.x_val
                ) / 2
                competitor.gate_poses_ground_truth.insert(20, curr_pose)

            if self.level_name == "Building99_Hard":
                competitor.gate_poses_ground_truth.insert(
                    3,
                    Pose(
                        Vector3r(
                            (-21.49 - 41.89) / 2.0,
                            (-5.44 - 1.84) / 2,
                            (1.51 + 1.82) / 2,
                        )
                    ),
                )

            if self.level_name == "ZhangJiaJie_Medium":
                num_gates = len(competitor.gate_poses_ground_truth)
                last_gate_position = deepcopy(
                    competitor.gate_poses_ground_truth[-1].position
                )
                second_last_gate_position = deepcopy(
                    competitor.gate_poses_ground_truth[-2].position
                )
                competitor.gate_poses_ground_truth.insert(
                    num_gates - 1,
                    Pose(
                        Vector3r(
                            (last_gate_position.x_val + second_last_gate_position.x_val)
                            / 2.0,
                            (last_gate_position.y_val + second_last_gate_position.y_val)
                            / 2.0,
                            (last_gate_position.z_val + second_last_gate_position.z_val)
                            / 2.0,
                        )
                    ),
                )

            self.client.call("simStartRace", tier)
            competitor.run_in_thread()