macad-gym
macad-gym copied to clipboard
Try to fix PathTracker
This work is still in progress. Also, this PR might contain some radical changes
Description
This PR is an attempt to cope with https://github.com/praveen-palanisamy/macad-gym/issues/81. Instead of fixing the original PathTracker
, I've decided to wrap around BasicAgent
class in Carla PythonAPI. This BasicAgent
comes with every distribution of Carla and the API we need (set_destination) haven't changed since 0.9.4. I think using a specific version of PythonAPI might lead to unknown issue in the future, so it is better to always use the compatible one.
Besides refractoring the PathTracker
class, there's some other things I've done in this branch.
Changes
1. Autopilot with navigation
Carla's autopilot will randomly choose a way to go at intersection, thus just using set_autopilot(True)
will not lead one actor to destination defined in scenario. I've mentioned two undocumented API in the issue, but it turned out both of them does not work properly (I guess that's why they don't document it).
So instead of using autopilot, I choose to apply the control planned by BasicAgent.run_step()
. This will navigate the actor to its desired end point. However, BasicAgent
only take traffic light and other vehicle in to account, meaning that some of its behavior might violate driving rules, e.g. it won't stop at stop-sign. There are also some potential undesired behavior, I'll describe in Known issue section below.
2. Removal of unused files
There are some files never used in Macad-Gym, most code in them are currently in another file. I've decided to remove them.
Also, since PythonAPI is no longer fixed with one version, I removed the whole folder and added PYTHONPATH
requirement in Readme.
Known issue
1. Endless episode
In scenario SSUI3C_TOWN3, even with correct route and above navigation enabled, the done
check will never meet. The problem is caused by get_orientation_difference_to_end_in_radians()
. The destination waypoint generate by BasicAgent
(or the GlobalRoutePlanner in current PathTracker) sometime has a strange rotation, resulting in ORIENTATION_TO_GOAL_THRESHOLD
can't pass.
BasicAgent
itself checks the planned route's length to decide whether the vehicle has reached its destination or not, which is similar to distance check. I wonder is the orientation really important for the done check?
I also observed endless episode in some other scenario, like FollowLeadingVehicle. BasicAgent
has some configurable parameter, such as base_vehicle_threshold
and base_tlight_threshold
. These parameters will affect control given by run_step()
. In scenario FLV, the leading car might stop before traffic light even though it hasn't reached destination because of base_tlight_threshold
. And the following car might stop too early because of base_vehicle_threshold
. This is similar to some adjustment in autopilot (e.g. set_global_distance_to_leading_vehicle()
), I think each scenario should have their own configuration.
2. Undesired Behavior
With the new navigation of autopilot feature enabled, it is very likely to meet some unexpected incident. For example, SSUI3C's planned route is like this:
It is possible that the fire truck turns left first, and it gets in the way of the bike. Vehicle will stop if they are already at their destination, and the bike will stop because of base_vehicle_threshold
. I've added a feature that if an actor controlled by PathTracker has reached its destination then let Carla's autopilot take over the control.
This solution might lead to some other unexpected, especially for the actor controlled by RL algorithm. So, I want to hear your opinion on that.
PS
I know that Macad-Gym is designed for multi-Agent RL training, so these changes might seem redundant. However, an actor with auto control enabled can be seen as a NPC, and to navigate the NPC to some specific destination is a potentially demanded feature. (at least for our group :)