num_drones=ARGS.num_drones, aggregate_phy_steps=shared_constants.AGGR_PHY_STEPS, obs=ARGS.obs, act=ARGS.act)) elif ARGS.env == 'meetup': register_env( temp_env_name, lambda _: MeetupAviary( num_drones=ARGS.num_drones, aggregate_phy_steps=shared_constants.AGGR_PHY_STEPS, obs=ARGS.obs, act=ARGS.act)) elif ARGS.env == 'payloadcoop': register_env( temp_env_name, lambda _: PayloadCoop( num_drones=ARGS.num_drones, aggregate_phy_steps=shared_constants.AGGR_PHY_STEPS, obs=ARGS.obs, act=ARGS.act)) else: print("[ERROR] environment not yet implemented") exit() #### Unused env to extract the act and obs spaces ########## if ARGS.env == 'flock': temp_env = FlockAviary( num_drones=ARGS.num_drones, aggregate_phy_steps=shared_constants.AGGR_PHY_STEPS, obs=ARGS.obs, act=ARGS.act) elif ARGS.env == 'leaderfollower':
#### Parameters to recreate the environment ################ NUM_DRONES =shared_constants.NUM_DRONES ACT = ActionType(shared_constants.ACT) OBS = ObservationType(shared_constants.OBS) #### Initialize Ray Tune ################################### ray.shutdown() ray.init(ignore_reinit_error=True, include_dashboard=True) #### Register the environment ############################## temp_env_name = "this-aviary-v0" register_env(temp_env_name, lambda _: PayloadCoop(num_drones=NUM_DRONES, aggregate_phy_steps=shared_constants.AGGR_PHY_STEPS, obs=OBS, act=ACT )) temp_env = PayloadCoop(num_drones=NUM_DRONES, aggregate_phy_steps=shared_constants.AGGR_PHY_STEPS, obs=OBS, act=ACT, ) action_space = temp_env.action_space[0] observation_space = temp_env.observation_space[0] obs_space_dict = { "agent_1": observation_space, "agent_2": observation_space, } act_space_dict = {
num_drones=NUM_DRONES, aggregate_phy_steps=shared_constants.AGGR_PHY_STEPS, obs=OBS, act=ACT)) elif ARGS.exp.split("-")[1] == 'meetup': register_env( temp_env_name, lambda _: MeetupAviary( num_drones=NUM_DRONES, aggregate_phy_steps=shared_constants.AGGR_PHY_STEPS, obs=OBS, act=ACT)) elif ARGS.exp.split("-")[1] == 'payloadcoop': register_env( temp_env_name, lambda _: PayloadCoop( num_drones=NUM_DRONES, aggregate_phy_steps=shared_constants.AGGR_PHY_STEPS, obs=OBS, act=ACT)) else: print("[ERROR] environment not yet implemented") exit() #### Unused env to extract the act and obs spaces ########## if ARGS.exp.split("-")[1] == 'flock': temp_env = FlockAviary( num_drones=NUM_DRONES, aggregate_phy_steps=shared_constants.AGGR_PHY_STEPS, obs=OBS, act=ACT) elif ARGS.exp.split("-")[1] == 'leaderfollower': temp_env = LeaderFollowerAviary(
#### Parameters to recreate the environment ################ NUM_DRONES = shared_constants.NUM_DRONES ACT = ActionType(shared_constants.ACT) OBS = ObservationType(shared_constants.OBS) #### Initialize Ray Tune ################################### ray.shutdown() ray.init(ignore_reinit_error=True, include_dashboard=True) #### Register the environment ############################## temp_env_name = "this-aviary-v0" register_env( temp_env_name, lambda _: PayloadCoop(num_drones=ARGS.num_drones, aggregate_phy_steps= shared_constants.AGGR_PHY_STEPS, obs=ARGS.obs, act=ARGS.act)) temp_env = PayloadCoop( num_drones=ARGS.num_drones, aggregate_phy_steps=shared_constants.AGGR_PHY_STEPS, obs=ARGS.obs, act=ARGS.act, ) observer_space = Dict({ "own_obs": temp_env.observation_space[0], "opponent_obs": temp_env.observation_space[0], "opponent_action": temp_env.action_space[0], }) action_space = temp_env.action_space[0] OWN_OBS_VEC_SIZE = observer_space["own_obs"].shape[0]
#### Initialize the simulation ############################# # R = 0.3 # INIT_XYZS = np.array([[-0.2, 0, 0.5], [0.2, 0, 0.5]]) # INIT_XYZS = np.array([[R*np.cos((i/6)*2*np.pi+np.pi/2), R*np.sin((i/6)*2*np.pi+np.pi/2)-R, 0.5] for i in range(ARGS.num_drones)]) INIT_XYZS = None INIT_RPYS = np.array([[0, 0, i * (np.pi / 2) / ARGS.num_drones] for i in range(ARGS.num_drones)]) AGGR_PHY_STEPS = int(ARGS.simulation_freq_hz / ARGS.control_freq_hz) if ARGS.aggregate else 1 env = PayloadCoop(dest_point=shared_constants.DEST_POINT, drone_model=ARGS.drone, num_drones=ARGS.num_drones, initial_xyzs=INIT_XYZS, initial_rpys=INIT_RPYS, physics=ARGS.physics, neighbourhood_radius=10, freq=ARGS.simulation_freq_hz, aggregate_phy_steps=AGGR_PHY_STEPS, gui=ARGS.gui, episode_len_sec=ARGS.duration_sec) #### Obtain the PyBullet Client ID from the environment #### PYB_CLIENT = env.getPyBulletClient() #### Initialize the logger ################################# logger = Logger(logging_freq_hz=int(ARGS.simulation_freq_hz / AGGR_PHY_STEPS), num_drones=ARGS.num_drones) #### Run the simulation ####################################