Giter Site home page Giter Site logo

Comments (8)

Morphlng avatar Morphlng commented on June 7, 2024 1

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

from macad-gym.

Morphlng avatar Morphlng commented on June 7, 2024

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
}

from macad-gym.

ggstar00 avatar ggstar00 commented on June 7, 2024

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?

from macad-gym.

Morphlng avatar Morphlng commented on June 7, 2024

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
}

from macad-gym.

ggstar00 avatar ggstar00 commented on June 7, 2024

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?

from macad-gym.

ggstar00 avatar ggstar00 commented on June 7, 2024

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

from macad-gym.

Morphlng avatar Morphlng commented on June 7, 2024

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.

from macad-gym.

ggstar00 avatar ggstar00 commented on June 7, 2024

THA====

from macad-gym.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.