Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PathTracker generate wrong route #81

Open
Morphlng opened this issue Feb 1, 2023 · 2 comments
Open

PathTracker generate wrong route #81

Morphlng opened this issue Feb 1, 2023 · 2 comments

Comments

@Morphlng
Copy link
Contributor

Morphlng commented Feb 1, 2023

I want to apply traffic_manager.set_path(actor, route) (This api is missed in the doc, but actually available and described in this PR) to navigate the actor to desired end point when "auto_control" is enabled.

However, the path generated by Macad's PathTracker is not correct. I've tested Scenario SSUI3C_TOWN3, the start/end position is defined as:

SSUI3C_TOWN3 = {
"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
}

Take car1 as an example, this car should take a left turn. But the route generated by PathTracker is like this (green line):

path_draw

It takes a right turn, and we can check the end point, it's far away from what we defined:

planner_route

I've noticed that Macad-Gym copied a PythonAPI from Carla 0.9.6 distribution, maybe this is the reason why the generated path is incorrect. I'm trying to apply the Carla 0.9.13 PythonAPI to see whether it will make a difference.

@Morphlng
Copy link
Contributor Author

Morphlng commented Feb 2, 2023

Ok, so using BasicAgent in Carla 0.9.13's PythonAPI, I've successfully generated correct route. It can be seen as below:

SSUI3C_TOWN3

There is something need to be addressed:

  1. This bug seems hard to reproduce the exact same behavior, but it generally exists. I've tried to run the same scenario under Ubuntu 22.04, it turns out the car1's route is correct but car2 and car3 remain incorrect.
  2. I think copying a specific version of PythonAPI isn't a good idea, this part of API is rapidly changing. Since each distribution contains a version of BasicAgent, why don't we just wrap around this class?

I'll leave the test code below, for reproducibility:

import carla
import random
import time
from agents.navigation.basic_agent import BasicAgent
from agents.tools.misc import draw_waypoints

scenario = {
    "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,
    "spectator_location": [140, 68, 9],
}


class PathTracker:
    '''Path tracker for the agent to follow the path
    '''

    def __init__(self, origin, destination, actor):
        self.agent = BasicAgent(actor)
        self.agent.set_destination(
            carla.Location(x=destination[0],
                           y=destination[1], z=destination[2]),
            carla.Location(x=origin[0], y=origin[1], z=origin[2])
        )

    def get_path(self):
        return self.agent._local_planner.get_plan()


def create_scenario(client, scenario):
    world = client.load_world(scenario["map"])
    map = world.get_map()
    vehicle_blueprints = world.get_blueprint_library().filter('vehicle.*')

    actors = {}
    for actor_id in scenario["actors"]:
        bp = random.choice(vehicle_blueprints)
        start_loc = carla.Location(x=scenario["actors"][actor_id]["start"][0],
                                   y=scenario["actors"][actor_id]["start"][1],
                                   z=scenario["actors"][actor_id]["start"][2])
        spawn_point = carla.Transform(
            start_loc,
            map.get_waypoint(
                start_loc, project_to_road=True).transform.rotation
        )
        actors[actor_id] = world.spawn_actor(bp, spawn_point)

    if scenario.get("spectator_location", None) is not None:
        spectator_transform = carla.Transform(
            carla.Location(x=scenario["spectator_location"][0],
                           y=scenario["spectator_location"][1],
                           z=scenario["spectator_location"][2]),
            carla.Rotation(pitch=-90)
        )
        world.get_spectator().set_transform(spectator_transform)

    return actors


if __name__ == "__main__":
    client = carla.Client("localhost", 2000)
    client.set_timeout(10)

    actors = create_scenario(client, scenario)

    path_trackers = [PathTracker(scenario["actors"][actor_id]["start"],
                                 scenario["actors"][actor_id]["end"], actors[actor_id]) for actor_id in scenario["actors"]]

    while True:
        for path_tracker in path_trackers:
            path = path_tracker.get_path()
            draw_waypoints(client.get_world(), [p[0] for p in path], 1.0)
        time.sleep(0.1)

@praveen-palanisamy
Copy link
Owner

Hi,
Good to see your investigation with details.

  1. Thanks for the test code to reproduce the issues you described! I'll take a look.
  2. Yes, the carla/PythonAPI module is directly from CARLA) as stated in the README. When MACAD-Gym package was developed, that module was included in code instead of importing because we didn't publish CARLA python wheels for versions 0.9.6 to 0.9.11 as you can see on the package registry here: https://pypi.org/project/carla/#history. The reason for using the specific API version was to ensure the results in the MACAG-Gym paper is reproducible.

Recently, MACAD-Gym started adding support for CARLA 0.9.13 and later. It is a good idea to update the Traffic Manager APIs to the latest versions. From your #82 PR description, it sounds like you also tried the autopilot and path tracking with CARLA v0.9.13 and found it to be unusable because the autopilot chooses destinations/path at random especially at the intersections. We need to use a deterministic planner to ensure that every agent in a specific Multi-Agent RL environment behaves as expected and is reproducible (deterministic env). Any randomness in the behaviour should be driven by a random seed to make the RL problem tractable and reproducible.
I'll take a look into the path tracking issue you raised and update when I have one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants