Exemple #1
0
 def __init__(self,
              drone_model: DroneModel = DroneModel.CF2X,
              num_drones: int = 2,
              neighbourhood_radius: float = np.inf,
              initial_xyzs=None,
              initial_rpys=None,
              physics: Physics = Physics.PYB,
              freq: int = 240,
              aggregate_phy_steps: int = 1,
              gui=False,
              record=False,
              obs: ObservationType = ObservationType.KIN,
              act: ActionType = ActionType.RPM):
     if num_drones < 2:
         print(
             "[ERROR] in BaseMultiagentAviary.__init__(), num_drones should be >= 2"
         )
         exit()
     vision_attributes = True if obs == ObservationType.RGB else False
     dynamics_attributes = True if act in [
         ActionType.DYN, ActionType.ONE_D_DYN
     ] else False
     self.OBS_TYPE = obs
     self.ACT_TYPE = act
     self.EPISODE_LEN_SEC = 5
     #### Create integrated controllers #########################
     if act in [ActionType.PID, ActionType.ONE_D_PID]:
         os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'
         if self.DRONE_MODEL in [DroneModel.CF2X, DroneModel.CF2P]:
             self.ctrl = [
                 DSLPIDControl(BaseAviary(drone_model=DroneModel.CF2X))
                 for i in range(self.NUM_DRONES)
             ]
         elif self.DRONE_MODEL == DroneModel.HB:
             self.ctrl = [
                 SimplePIDControl(BaseAviary(drone_model=DroneModel.HB))
                 for i in range(self.NUM_DRONES)
             ]
     super().__init__(
         drone_model=drone_model,
         num_drones=num_drones,
         neighbourhood_radius=neighbourhood_radius,
         initial_xyzs=initial_xyzs,
         initial_rpys=initial_rpys,
         physics=physics,
         freq=freq,
         aggregate_phy_steps=aggregate_phy_steps,
         gui=gui,
         record=record,
         obstacles=
         True,  # Add obstacles for RGB observations and/or FlyThruGate
         user_debug_gui=
         False,  # Remove of RPM sliders from all single agent learning aviaries
         vision_attributes=vision_attributes,
         dynamics_attributes=dynamics_attributes)
    def __init__(self,
                 drone_model: DroneModel = DroneModel.CF2X,
                 num_drones: int = 2,
                 neighbourhood_radius: float = np.inf,
                 initial_xyzs=None,
                 initial_rpys=None,
                 physics: Physics = Physics.PYB,
                 freq: int = 240,
                 aggregate_phy_steps: int = 1,
                 gui=False,
                 record=False,
                 obs: ObservationType = ObservationType.KIN,
                 act: ActionType = ActionType.RPM):
        """Initialization of a generic multi-agent RL environment.

        Attributes `vision_attributes` and `dynamics_attributes` are selected
        based on the choice of `obs` and `act`; `obstacles` is set to True 
        and overridden with landmarks for vision applications; 
        `user_debug_gui` is set to False for performance.

        Parameters
        ----------
        drone_model : DroneModel, optional
            The desired drone type (detailed in an .urdf file in folder `assets`).
        num_drones : int, optional
            The desired number of drones in the aviary.
        neighbourhood_radius : float, optional
            Radius used to compute the drones' adjacency matrix, in meters.
        initial_xyzs: ndarray | None, optional
            (NUM_DRONES, 3)-shaped array containing the initial XYZ position of the drones.
        initial_rpys: ndarray | None, optional
            (NUM_DRONES, 3)-shaped array containing the initial orientations of the drones (in radians).
        physics : Physics, optional
            The desired implementation of PyBullet physics/custom dynamics.
        freq : int, optional
            The frequency (Hz) at which the physics engine steps.
        aggregate_phy_steps : int, optional
            The number of physics steps within one call to `BaseAviary.step()`.
        gui : bool, optional
            Whether to use PyBullet's GUI.
        record : bool, optional
            Whether to save a video of the simulation in folder `files/videos/`.
        obs : ObservationType, optional
            The type of observation space (kinematic information or vision)
        act : ActionType, optional
            The type of action space (1 or 3D; RPMS, thurst and torques, or waypoint with PID control)

        """
        if num_drones < 2:
            print(
                "[ERROR] in BaseMultiagentAviary.__init__(), num_drones should be >= 2"
            )
            exit()
        vision_attributes = True if obs == ObservationType.RGB else False
        dynamics_attributes = True if act in [
            ActionType.DYN, ActionType.ONE_D_DYN
        ] else False
        self.OBS_TYPE = obs
        self.ACT_TYPE = act
        self.EPISODE_LEN_SEC = 5
        #### Create integrated controllers #########################
        if act in [ActionType.PID, ActionType.ONE_D_PID]:
            os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'
            if self.DRONE_MODEL in [DroneModel.CF2X, DroneModel.CF2P]:
                self.ctrl = [
                    DSLPIDControl(BaseAviary(drone_model=DroneModel.CF2X))
                    for i in range(self.NUM_DRONES)
                ]
            elif self.DRONE_MODEL == DroneModel.HB:
                self.ctrl = [
                    SimplePIDControl(BaseAviary(drone_model=DroneModel.HB))
                    for i in range(self.NUM_DRONES)
                ]
        super().__init__(
            drone_model=drone_model,
            num_drones=num_drones,
            neighbourhood_radius=neighbourhood_radius,
            initial_xyzs=initial_xyzs,
            initial_rpys=initial_rpys,
            physics=physics,
            freq=freq,
            aggregate_phy_steps=aggregate_phy_steps,
            gui=gui,
            record=record,
            obstacles=
            True,  # Add obstacles for RGB observations and/or FlyThruGate
            user_debug_gui=
            False,  # Remove of RPM sliders from all single agent learning aviaries
            vision_attributes=vision_attributes,
            dynamics_attributes=dynamics_attributes)