macad-gym
macad-gym copied to clipboard
PathTracker generate wrong route
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:
https://github.com/praveen-palanisamy/macad-gym/blob/1006e849ff4c5bf5d29cb43ab8c2a0bdcc992367/src/macad_gym/carla/scenarios.py#L43-L61
Take car1
as an example, this car should take a left turn. But the route generated by PathTracker is like this (green line):

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

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.
Ok, so using BasicAgent
in Carla 0.9.13's PythonAPI, I've successfully generated correct route. It can be seen as below:

There is something need to be addressed:
- 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 butcar2
andcar3
remain incorrect. - 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)
Hi, Good to see your investigation with details.
- Thanks for the test code to reproduce the issues you described! I'll take a look.
- 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.