huawei-noah / SMARTS

Scalable Multi-Agent RL Training School for Autonomous Driving
MIT License
954 stars 190 forks source link

[Help Request] entry tactic #2104

Closed knightcalvert closed 1 year ago

knightcalvert commented 1 year ago

High Level Description

my scenarios is intersections/4lane, I wanna build a contolled zone which a little bigger than the junction area.

zone = ConfigurableZone(
    ext_coordinates=[(25.0, 25.0),(-25.0, -25.0)],
)
entry_tactic = TrapEntryTactic(start_time=0, wait_to_hijack_limit_s=0, zone=zone)
ego_missions = [
    Mission(route=Route(begin=("edge-north-NS", 1, 50), end=("edge-east-WE" , 1, "max")),entry_tactic=entry_tactic),
    Mission(route=Route(begin=("edge-north-NS", 0, 50), end=("edge-south-NS", 0, "max")),entry_tactic=entry_tactic),
]

I need a help about:

  1. what's the difference about start_time and wait_to_hijack_limit_s?
  2. am i right about making the controlled zone
  3. my entry tactic doesn't work, all the agent generate at the beginning in the designated place("edge-north-NS", 1, 50). and I wish the agent can replace an existing car in flow and inherit it place when the car run into the controlled zone Thank you for your answer, have a nice day

Version

1.4.0

Operating System

No response

Problems

No response

knightcalvert commented 1 year ago

by the way, maybe it's an irrelevant problem but easy to fix. Where can I turn off the signal? when reseting the env, the signal always appears

Gamenot commented 1 year ago

Hello @knightcalvert, thank you for reaching out.

I need a help about:

  1. what's the difference about start_time and wait_to_hijack_limit_s?

These represent time qualities. start_time represents the first possible simulation time that the vehicle can exist. Then wait_to_hijack_limit_s represents a time window where the simulation will wait for up to that amount of seconds to acquire a vehicle. If a vehicle is not found within the Zone a vehicle will be emitted centred on the road at the mission.route.begin. This means with your configuration it would immediately emit a vehicle on the first step.

  1. am i right about making the controlled zone

I believe so.

  1. my entry tactic doesn't work, all the agent generate at the beginning in the designated place("edge-north-NS", 1, 50). and I wish the agent can replace an existing car in flow and inherit it place when the car run into the controlled zone

What is happening here is that the capture window is expiring before any vehicle is captured. This causes the vehicles to be emitted immediately at the mission start location. The reason is when we emit a default vehicle without we do not know where that vehicle will be.

by the way, maybe it's an irrelevant problem but easy to fix. Where can I turn off the signal? when reseting the env, the signal always appears

What kind of signal are you trying to remove? Are you talking about warnings? The following should handle suppressing warnings:

import logging
import warnings

logging.basicConfig(level=logging.ERROR) # As early as possible so loggers inherit logging level
...
env = gym.make(...)
warnings.filterwarnings("ignore") # As late as possible so it does not get overridden.

With that said, I am fixing some logging configuration that manage to weasel into some of the core files.

knightcalvert commented 1 year ago

Hello @knightcalvert, thank you for reaching out.

I need a help about:

  1. what's the difference about start_time and wait_to_hijack_limit_s?

These represent time qualities. start_time represents the first possible simulation time that the vehicle can exist. Then wait_to_hijack_limit_s represents a time window where the simulation will wait for up to that amount of seconds to acquire a vehicle. If a vehicle is not found within the Zone a vehicle will be emitted centred on the road at the mission.route.begin. This means with your configuration it would immediately emit a vehicle on the first step.

  1. am i right about making the controlled zone

I believe so.

  1. my entry tactic doesn't work, all the agent generate at the beginning in the designated place("edge-north-NS", 1, 50). and I wish the agent can replace an existing car in flow and inherit it place when the car run into the controlled zone

What is happening here is that the capture window is expiring before any vehicle is captured. This causes the vehicles to be emitted immediately at the mission start location. The reason is when we emit a default vehicle without we do not know where that vehicle will be.

by the way, maybe it's an irrelevant problem but easy to fix. Where can I turn off the signal? when reseting the env, the signal always appears

What kind of signal are you trying to remove? Are you talking about warnings? The following should handle suppressing warnings:

import logging
import warnings

logging.basicConfig(level=logging.ERROR) # As early as possible so loggers inherit logging level
...
env = gym.make(...)
warnings.filterwarnings("ignore") # As late as possible so it does not get overridden.

With that said, I am fixing some logging configuration that manage to weasel into some of the core files.

thank you for your help, my signal means traffic light

Gamenot commented 1 year ago

thank you for your help, my signal means traffic light

Is it that there is a red light you are trying to get rid of or are the signals incorrectly showing up in the observations?

If you are trying to get rid of the red light you would need to either:

Netedit

For SUMO maps you could use netedit https://sumo.dlr.de/docs/sumo-gui.html#switching_traffic_lights on the sumo map.net.xml to change the traffic lights embedded in the map.

Traffic junction model

Or you could use the JunctionModel to cause the traffic to tune how they ignore signals https://sumo.dlr.de/docs/Definition_of_Vehicles%2C_Vehicle_Types%2C_and_Routes.html#junction_model_parameters.

from smarts.sstudio.types import JunctionModel
TrafficActor(
    name="car",
    speed=Distribution(sigma=0.2, mean=0.8),
    lane_changing_model=LaneChangingModel(impatience=1, cooperative=0.25),
    junction_model=JunctionModel(drive_after_yellow_time=1.0, impatience=0.5),
)

Error

If you think the signals are incorrectly showing up in the observations, could you further describe what is happening?

knightcalvert commented 1 year ago

I just want to get rid of the traffic light. about Netedit, it's seems not a flexible method? every time i change the scenario.py, it looks like i need edit the net as well. I remember hiway-v0 didn't have a traffic light by default, could i turn off the light permanently? about Traffic junction model, the ego agent can ignore signals now, but the flows still wait, is there a better way that both agent and the traffic flows can ignore signals?

Gamenot commented 1 year ago

I just want to get rid of the traffic light. about Netedit, it's seems not a flexible method?

Yes, there is some issue, generally the traffic lights are considered integrated as part of the map because they are a static routine (generally). We did not implement a control against the signals because it can be stripped out of the map definition by users and it does not generalize to data replay.

every time i change the scenario.py, it looks like i need edit the net as well. I remember hiway-v0 didn't have a traffic light by default, could i turn off the light permanently?

I am unsure what you mean. The hiway-v0 environment has traffic lights but they might not be in the observations.

about Traffic junction model, the ego agent can ignore signals now, but the flows still wait, is there a better way that both agent and the traffic flows can ignore signals?

Sorry, I might not have been clear, traffic flows could be modified with a model like the following which would cause them to ignore traffic lights as mentioned https://sumo.dlr.de/docs/sumo-gui.html#switching_traffic_lights:

from smarts.sstudio.types import JunctionModel
TrafficActor(
    ...,
    JunctionModel(
       drive_after_red_time=180.0, # i.e. sumo's `jmDriveAfterRedTime`
       drive_after_yellow_time=180.0, # i.e. sumo's `jmDriveAfterYellowTime`
       # ignore_keep_clear_time=10, # sumo's `jmIgnoreKeepClearTime`
       impatience=0.5
    ), 
)

Then the scenario would need to be rebuilt scl scenario build --clean <scenario>.

Other option

The only other possibility I can think of is that I could add an engine.ini configuration which would allow for turning traffic lights off globally, if that is useful enough.

knightcalvert commented 1 year ago

I'm sorry i made a mistake, you are right. I changed the map xml

   <tlLogic id="junction-intersection" type="static" programID="0" offset="0">
        <phase duration="1000" state="GGGGGGGGGGGGGGGG"/>
        <phase duration="1000" state="GGGGGGGGGGGGGGGG"/>
        <phase duration="1000" state="GGGGGGGGGGGGGGGG"/>
        <phase duration="1000" state="GGGGGGGGGGGGGGGG"/>
    </tlLogic>

and all the traffic lights are green now