praveen-palanisamy / macad-gym

Multi-Agent Connected Autonomous Driving (MACAD) Gym environments for Deep RL. Code for the paper presented in the Machine Learning for Autonomous Driving Workshop at NeurIPS 2019:
https://arxiv.org/abs/1911.04175
MIT License
334 stars 74 forks source link

when I use urban_signal_intersection_3c env ,happen error,please help me #83

Closed ggstar00 closed 1 year ago

ggstar00 commented 1 year ago

Traceback (most recent call last): File "/home/ggstar/pythonproject/macad-gym-master/src/macad_gym/envs/intersection/urban_signal_intersection_3c.py", line 109, in env = UrbanSignalIntersection3Car() File "/home/ggstar/pythonproject/macad-gym-master/src/macad_gym/envs/intersection/urban_signal_intersection_3c.py", line 105, in init super(UrbanSignalIntersection3Car, self).init(self.configs) File "/home/ggstar/pythonproject/macad-gym-master/src/macad_gym/carla/multi_env.py", line 275, in init configs["scenarios"] KeyError: 'scenarios'

Morphlng commented 1 year ago

I think this is a deprecated env, you should use HomoNcomIndePOIntrxMASS3CTWN3 instead. You can also manually add "scenarios" in the USI3C_CONFIGS, that is:

USI3C_CONFIGS = {
  "scenarios": "SSUI3C_TOWN3",
  # Keep the rest untouched
}
ggstar00 commented 1 year ago

thanks,I have found the error, but in fact the generated vehicle position is not at the observation point. I will use HomoNcomIndePOIntrxMASS3CTWN3 instead. Is there any way to increase the simulated traffic flow of vehicles driven by intersection rules?

Morphlng commented 1 year ago

Is there any way to increase the simulated traffic flow of vehicles driven by intersection rules?

Macad-Gym only support spawning npcs at random places. To do so, you have to copy the definition of scenario and change the number of num_vehicles and num_pedestrains. Unfortunately, you can't spawn npcs right at the intersection area for now.

# Scenario definition from SSUI3C_TOWN3
env_config = {
  "scenarios": {
      "map": "Town03",
      "actors": {
          "car1": {
              "start": [170.5, 80, 0.4],
              "end": [144, 59, 0]
          },
          "car2": {
              "start": [188, 59, 0.4],
              "end": [167, 75.7, 0.13],
          },
          "car3": {
              "start": [147.6, 62.6, 0.4],
              "end": [191.2, 62.7, 0],
          }
      },
      "weather_distribution": [0],
      "max_steps": 500,
      "num_vehicles": 0,    # Change this to spawn npc vehicles at random place, they are controlled by autopilot
      "num_pedestrians": 0,
  }

  # keep "env" and "actors" config untouched
}
ggstar00 commented 1 year ago

When I modify scenarios.py as you said, but random npcs are not generated on the map, can you provide an example for me to learn from?

Morphlng commented 1 year ago

When I modify scenarios.py as you said, but random npcs are not generated on the map, can you provide an example for me to learn from?

Are you using the latest version in this repository instead of Pypi version? If so, you can try this script:

from macad_gym.envs import MultiCarlaEnv

configs = {
    "scenarios": {
        "map": "Town03",
        "actors": {
            "car1": {
                "start": [170.5, 80, 0.4],
                "end": [144, 59, 0]
            },
            "car2": {
                "start": [188, 59, 0.4],
                "end": [167, 75.7, 0.13],
            },
            "car3": {
                "start": [147.6, 62.6, 0.4],
                "end": [191.2, 62.7, 0],
            }
        },
        "weather_distribution": [0],
        "max_steps": 500,
        "num_vehicles": 20,     # The number of npc vehicles
        "num_pedestrians": 0,
    },
    "env": {
        "server_map": "/Game/Carla/Maps/Town03",
        "render": True,
        "render_x_res": 800,
        "render_y_res": 600,
        "x_res": 168,
        "y_res": 168,
        "framestack": 1,
        "discrete_actions": True,
        "squash_action_logits": False,
        "verbose": False,
        "use_depth_camera": False,
        "send_measurements": False,
        "enable_planner": True,
        "spectator_loc": [140, 68, 9],
        "sync_server": True,
        "fixed_delta_seconds": 0.05,
    },
    "actors": {
        "car1": {
            "type": "vehicle_4W",
                    "enable_planner": True,
                    "convert_images_to_video": False,
                    "early_terminate_on_collision": True,
                    "reward_function": "corl2017",
                    "scenarios": "SSUI3C_TOWN3_CAR1",
                    "manual_control": False,
                    "auto_control": False,
                    "camera_type": "rgb",
                    "collision_sensor": "on",
                    "lane_sensor": "on",
                    "log_images": False,
                    "log_measurements": False,
                    "render": True,
                    "x_res": 168,
                    "y_res": 168,
                    "use_depth_camera": False,
                    "send_measurements": False,
        },
        "car2": {
            "type": "vehicle_4W",
                    "enable_planner": True,
                    "convert_images_to_video": False,
                    "early_terminate_on_collision": True,
                    "reward_function": "corl2017",
                    "scenarios": "SSUI3C_TOWN3_CAR2",
                    "manual_control": False,
                    "auto_control": False,
                    "camera_type": "rgb",
                    "collision_sensor": "on",
                    "lane_sensor": "on",
                    "log_images": False,
                    "log_measurements": False,
                    "render": True,
                    "x_res": 168,
                    "y_res": 168,
                    "use_depth_camera": False,
                    "send_measurements": False,
        },
        "car3": {
            "type": "vehicle_4W",
                    "enable_planner": True,
                    "convert_images_to_video": False,
                    "early_terminate_on_collision": True,
                    "reward_function": "corl2017",
                    "scenarios": "SSUI3C_TOWN3_CAR3",
                    "manual_control": False,
                    "auto_control": False,
                    "camera_type": "rgb",
                    "collision_sensor": "on",
                    "lane_sensor": "on",
                    "log_images": False,
                    "log_measurements": False,
                    "render": True,
                    "x_res": 168,
                    "y_res": 168,
                    "use_depth_camera": False,
                    "send_measurements": False,
        },
    },
}

if __name__ == "__main__":
    env = MultiCarlaEnv(configs)

    for ep in range(2):
        obs = env.reset()

        total_reward_dict = {}
        action_dict = {}

        env_config = configs["env"]
        actor_configs = configs["actors"]
        for actor_id in actor_configs.keys():
            total_reward_dict[actor_id] = 0
            if env._discrete_actions:
                action_dict[actor_id] = 4  # Brake
            else:
                action_dict[actor_id] = [0, 0]  # test values

        i = 0
        done = {"__all__": False}
        while not done["__all__"]:
            # while i < 20:  # TEST
            i += 1
            obs, reward, done, info = env.step(action_dict)
            # action_dict = get_next_actions(info, env.discrete_actions)
            for actor_id in total_reward_dict.keys():
                total_reward_dict[actor_id] += reward[actor_id]
            print(":{}\n\t".join(["Step#", "rew", "ep_rew",
                                  "done{}"]).format(i, reward,
                                                    total_reward_dict, done))

Remember the spawn point is at random, you might not easily see those npc if you set a relateively small number of them.

npc

ggstar00 commented 1 year ago

Thanks,I solved this problem. I tried your open source code of marllib on macad, but the environment of macad cannot be registered successfully on marllib,I tried to solve it but failed

Morphlng commented 1 year ago

I tried your open source code of marllib on macad, but the environment of macad cannot be registered successfully on marllib,I tried to solve it but failed

This is not related to the current issue. If the problem has been solved, please close this one and start a new issue in that repo.

ggstar00 commented 1 year ago

THA====