pyoscx / scenariogeneration

Python library to generate linked OpenDRIVE and OpenSCENARIO files
Mozilla Public License 2.0
258 stars 80 forks source link

Generation of scenarios for CARLA #149

Open arjunsk07 opened 1 year ago

arjunsk07 commented 1 year ago

Hello @johschmitz , I am trying to have a scenario for the CARLA simulator, so I just need to know with the help of scenariogeneration package, Is it possible to write a scenario ( thinking about a logical scenario) that generates a number of other scenarios by changing the parameters and I have to run those scenarios in CARLA simulator as well. Does this kind of approach is possible with this scenariogeneration package?

johschmitz commented 1 year ago

I think you @mentioned the wrong person but I believe it might be possible if both sides speak OepnSCENARIO 1.2 otherwise you could just generate a pile of OpenSCENARIO 1.0/1.1 files with different parameters (should be possible with the scenariogeneration lib) and try running those one by one with the CARLA scenario runner.

mander76 commented 1 year ago

Do you want to do it the "openscenario" way with the "ParameterValueDistribution" file, or just create a number of different xosc files?

arjunsk07 commented 1 year ago

My ultimate aim is to run a specific scenario( for eg an overtaking scenario) multiple times with different parameter values. The scenario can be in openscenario format so that I can also run in CARLA simulator.

So as @mander76 mentioned if it is in the "openscenario" way with the "ParameterValueDistribution" file, then I need to write a openscenario format (xml based) scenario and upon that I need to have an distribution file also right. This approach I already had in mind.

But my another concern is that, is it possible to create a number of xosc files with the help of scenariogeneration lib for a specific scenario with different parameters assigned to different xosc files and at the end with the help of scenario runner I need to run those scenarios contionously one by one in the CARLA simulator. Does this kind of approach is possible with this?

mander76 commented 1 year ago

If I'm following you correctly, you can utilize the ScenarioGenerator class, (see examples here https://github.com/pyoscx/scenariogeneration/tree/main/examples/generator). This is how I use it mostly, these examples will generate a number of xosc/xodr files that are ready to run.

This package was created when only OpenSCENARIO 1.0 was out, and no ParameterValueDistribution existed, so the whole point was to be able to make fast parametrizations of OpenSCENARIO

I cannot speak for CARLA and how to run things there, since I'm mostly use esmini as the scenario-engine.

Side note: previously CARLA only supported OpenSCENARIO 1.0, so check that aswell (scenariogeneration can generate both 1.0 and 1.1)

arjunsk07 commented 1 year ago

I am also using openscenario 1.0 format, since CARLA only supports 1.0 as of now. I have checked out the files that you have mentioned above and from a brief look what I understood is, with that I can generate a number of xosc/xodr files that vary in parameters right?

mander76 commented 1 year ago

yes exactly.

arjunsk07 commented 1 year ago

So one more doubt in the same lane, Is it possible to generate both static and dynamic ones with this package? For example if I have an overtaking scenario, does the scenario generation package will be able to include both the static parameters and the overtaking logic that contains the dynamic entities like maneuvers, trajectories, and so on?

mander76 commented 1 year ago

In general yes, not sure what you mean with static and dynamic ones though.

arjunsk07 commented 1 year ago

In openscenario, we can say a scenario as the combination of static and dynamic elements for example if I say as the dynamic elements as the ego vehicle and the other vehicles interacting with each other, or as a whole the moving objects and the static elements can be the non moving objects like some signboards, trees or something like.

So my question was is it possible with the scenariogeneration package to generate both type of elements in the openscenario file.

johschmitz commented 1 year ago

You should be able to generate all types of supported objects. The question is if there is a convenience API available for whatever you want to do or if you have to use the "low level" API. Why don't you just play a bit with the library and see if you like it and get a feeling for it? At least have a look into the documentation, that'll probably answer a lot of your questions.

arjunsk07 commented 1 year ago

I was now doing research of available packages like this and I am definitely going to try this. Will get back to you if I get into something. Thanks for the answers bro!

mander76 commented 1 year ago

@arjunsk07 for OpenSCEARNIO scenariogenerations xosc module supports everything except some "userdefined" things, so if it works in openscenario, you can do it with scenariogeneration. For opendrive there are still some limitations, but static objects like buidlings signs and so on are supported.

arjunsk07 commented 1 year ago

Hello @mander76 I have tried generating xosc files and running in CARLA simulator and it was successful to some extent. Now I am trying to execute a scenario where a car should stop in front of a pedestrian so for that, which example script will be the best one to start with and to work upon that. Any specific suggestions from your side?

mander76 commented 1 year ago

Hmm, don't have any examples with pedestrians I think, but maybe https://github.com/pyoscx/scenariogeneration/blob/main/examples/xosc/parallel_distance_actions.py for the distance condition that might be useful.

arjunsk07 commented 1 year ago

Hello @mander76 , I tried generating openscenario 1.0 format files by writing the python script.

`

` Here in this, according to the openscenario 1.0 documentation, the sun has attributes intensity, azimuth and elevation but while I am generating the openscenario 1.0 file, the intensity is replaced by illuminance, similarly issue also I found in another part of the generated file. To get the openscenario 1.0 file, ` sce = xosc.Scenario( "lane change", "Arjun", paramdec, entities=entities, storyboard=sb, roadnetwork=road, catalog=catalog, osc_minor_version=0 ) ` This is how I do that. Can you please tell me where I am going wrong.
mander76 commented 1 year ago

What version of scenariogeneration are you using? I recently added xsd checks for all versions and classes, so might be a bug I have fixed these past weeks

arjunsk07 commented 1 year ago

@mander76 I am using v0.11.2

mander76 commented 1 year ago

Then try >0.12.0, I know I fixed a couple of bugs in the Environment class when I did the xsd tests

mander76 commented 1 year ago

https://github.com/pyoscx/scenariogeneration/commit/b3ccf167972414003ed0642463054cca7de27413#diff-b1b8c2724248a25f17bb1fd894b5171dd9f948413bdd2897c3dbd1299f21a6e4 There are a bunch of changes there, but looks like your issue should be solved there

arjunsk07 commented 1 year ago

pip install --upgrade Does this work to get the latest changes?

mander76 commented 1 year ago

pip install scenariogeneration --upgrade should work? If you are not building it from source ofc, then pull and do pip install . --upgrade

arjunsk07 commented 1 year ago

Thanks @mander76 , it is now generating as expected

mander76 commented 1 year ago

Can we close this issue then?

arjunsk07 commented 1 year ago

Hello @mander76 , one more doubt from my side, I am trying to generate a number of xosc files by changing some parameters, I have succeeded in changing the vehicles type, speed, relative distance, fog and sun intensity. But I am not able to sucessfully change the percipitaition type. Is there any way to do that?

` self.parameters["speed"] = [10, 20, 30] self.parameters["cartype"] = ["vehicle.carlamotors.firetruck","vehicle.ford.ambulance","vehicle.dodge.charger_police"] self.parameters["sun_intensity"] = [0.85,0.0]

self.parameters["Precipitation_Type"] = ["dry","snow","rain"]

    self.parameters["fog_intensity"] = ["50","100"]
    self.parameters["relative_distance"] = [6, 10, 20]

` For the percipitation type as it is not passed as any sort of arguments, it is throwing error. Any suggestions from your side?

mander76 commented 1 year ago

if it is a OpenSCENARIO related value, they should be Enums, in this case PrecipitationType.snow In scenariogeneration, all typed enumerations in the standards are Enums in scenariogeneration aswell.

arjunsk07 commented 1 year ago

@mander76 oh okay, so any way to permute those (rain,snow,dry) with other parameter permutations?

mander76 commented 1 year ago

yes, put the enums there self.parameters["Precipitation_Type" = [xosc.PrecipitationType.dry, xosc.PrecipitationType.snow xosc.PrecipitationType.rain] should work

arjunsk07 commented 1 year ago

Oh yeah, it worked, thanks a lot brother. I will close this issue once I run it in CARLA simulator, so that I can make sure there are no other issues with it.

arjunsk07 commented 1 year ago

Hello @mander76 , In my python script I need to generate multiple stop triggers, but in every example python scripts I only found using one stop trigger for the storyboard. So how should I approach to generate multiple stop triggers inside one condition group.

mander76 commented 1 year ago

The triggers work the same way no matter where they are. Here are two examples using both condition groups (AND) and triggers (OR). Just change the Triggering point to "stop"

https://github.com/pyoscx/scenariogeneration/blob/main/examples/xosc/multi_conditional_or_triggers.py https://github.com/pyoscx/scenariogeneration/blob/main/examples/xosc/multi_conditional_and_triggers.py

arjunsk07 commented 1 year ago

`trigger_1 = xosc.ValueTrigger( "Time limit", 0, xosc.ConditionEdge.rising, xosc.SimulationTimeCondition(100000.0, xosc.Rule.greaterThan), "stop",)

    trigger_2 = xosc.ValueTrigger(
            "Time limit2",
            0,
            xosc.ConditionEdge.rising,
            xosc.SimulationTimeCondition(100000.0, xosc.Rule.greaterThan),
            "stop",)

    # create and add them to a ConditionGroup (and logic)
    andtrigger = xosc.ConditionGroup()
    andtrigger.add_condition(trigger_1)
    andtrigger.add_condition(trigger_2)

    ## create the storyboard
    sb = xosc.StoryBoard(
        init,

    )`

Hello @mander76, Here in this, I have 2 triggers and I have also added the conditiongroup also, but I am confused on how to adding those in the storyboard. Can you just help me with this

mander76 commented 1 year ago
        trig_cond1 = xosc.TimeToCollisionCondition(
            2, xosc.Rule.lessThan, entity=targetname
        )
        trig_cond2 = xosc.TimeHeadwayCondition(speedyname, 1, xosc.Rule.greaterThan)

        collision_trigger = xosc.EntityTrigger(
            "trigger", 0, xosc.ConditionEdge.none, trig_cond1, egoname
        )
        headway_trigger = xosc.EntityTrigger(
            "trigger", 0, xosc.ConditionEdge.none, trig_cond2, egoname
        )

        # create and add them to a ConditionGroup (and logic)
        andtrigger = xosc.ConditionGroup('stop')
        andtrigger.add_condition(collision_trigger)
        andtrigger.add_condition(headway_trigger)
        sb = xosc.StoryBoard(init, andtrigger)
arjunsk07 commented 1 year ago

Oh yeah, I was missing the triggerpoint stop in the conditiongroup function. That was the reason. Thanks brother

arjunsk07 commented 1 year ago

Hello @mander76 , While I am generating n number of xosc files from a single python script, I am thinking of having each description with the name and permutation number, for example as of now my xosc.scenario() looks like this: sce = xosc.Scenario( "Lanechange_multiple_stop", "Arjun", xosc.ParameterDeclarations(), entities=entities, storyboard=sb, roadnetwork=road, catalog=catalog, osc_minor_version=0 )

But I need to have an approach where the description should look like "Lanechange_multiple_stop" string and the permutation number. Is that possible with any kind of modifications? so the resulting looks like : "Lanechange_multiple_stop14" if its 14th permutation.

I have tried the variable from the print_permutations(), but didnt get suceed.

mander76 commented 1 year ago

that is possible, if you in your init adds this

self.basename = "Lanechange_multiple_stop"
self.naming = "numerical"
arjunsk07 commented 1 year ago

@mander76 yeah I have this self.basename but this will change only the file names right? but I am trying to change the description of each openscenario file. `

` Here I need the description to be different for each generated file such as testno01, testno02, like that, if it takes the same name as the filename also it is fine. How can I achieve that?

arjunsk07 commented 1 year ago

@mander76 Is it possible to add 2 entityreferences in the triggeringentities section? `

                    </Condition>`

Here in the above code section I need 2 entity references but how this can be done in the python script? trigcond_act1 = xosc.CollisionCondition(xosc.ObjectType.vehicle) overall_start1 = xosc.EntityTrigger("CollisionCondition",0,xosc.ConditionEdge.none,trigcond_act1,targetname) Here now I have one entity references but I am not able to add 2 references at the same time.

mander76 commented 1 year ago

@mander76 yeah I have this self.basename but this will change only the file names right? but I am trying to change the description of each openscenario file. <OpenSCENARIO xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="OpenScenario.xsd"> <FileHeader author="Arjun" date="2023-04-11T13:10:56.271907" description="testno" revMajor="1" revMinor="0"/> Here I need the description to be different for each generated file such as testno01, testno02, like that, if it takes the same name as the filename also it is fine. How can I achieve that?

hmm, not really had this usecase, but a "ugly way" could be to use self.naming = "numerical", and use self._it (very good variable name if you ask me :P )

mander76 commented 1 year ago

@mander76 Is it possible to add 2 entityreferences in the triggeringentities section? <Condition conditionEdge="none" delay="0.0" name="CollisionCondition"> <ByEntityCondition> <TriggeringEntities triggeringEntitiesRule="any"> <EntityRef entityRef="actor"/> <EntityRef entityRef="hero"/> </TriggeringEntities> <EntityCondition> <CollisionCondition> <ByType type="vehicle"/> </CollisionCondition> </EntityCondition> </ByEntityCondition> </Condition>

Here in the above code section I need 2 entity references but how this can be done in the python script? trigcond_act1 = xosc.CollisionCondition(xosc.ObjectType.vehicle) overall_start1 = xosc.EntityTrigger("CollisionCondition",0,xosc.ConditionEdge.none,trigcond_act1,targetname) Here now I have one entity references but I am not able to add 2 references at the same time.

The collision condition only supports one entity or object type (https://www.asam.net/static_downloads/ASAM_OpenSCENARIO_V1.2.0_Model_Documentation/modelDocumentation/content/CollisionCondition.html)

So in this case you need to add multiple conditiongroups (or logic) with each object type there. An example of "or" trigger can be found here: https://github.com/pyoscx/scenariogeneration/blob/main/examples/xosc/multi_conditional_or_triggers.py

A similar example is there if you need an "and" condition

arjunsk07 commented 1 year ago

@mander76 yeah I have this self.basename but this will change only the file names right? but I am trying to change the description of each openscenario file. <OpenSCENARIO xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="OpenScenario.xsd"> <FileHeader author="Arjun" date="2023-04-11T13:10:56.271907" description="testno" revMajor="1" revMinor="0"/> Here I need the description to be different for each generated file such as testno01, testno02, like that, if it takes the same name as the filename also it is fine. How can I achieve that?

hmm, not really had this usecase, but a "ugly way" could be to use self.naming = "numerical", and use self._it (very good variable name if you ask me :P )

@mander76 , I have tried using the self._it in my code, but the problem now I am facing is for example, for the permutation 0, the file name will be generated as "filname0" but when I use self._it in the xosc.scenario function, the description changes to "description1", my expectation here is it should be "description0". Here is my xosc.scenario(): sce = xosc.Scenario( "Lanechange_multiple_stop"+str(self._it), "Arjun", xosc.ParameterDeclarations(), entities=entities, storyboard=sb, roadnetwork=road, catalog=catalog, osc_minor_version=0 ) so when the files are generated I am getting "Lanechange_multiple_stop1" in the description for the permutation 0 instead of "Lanechange_multiple_stop0". hope you understood my problem :)

mander76 commented 1 year ago

ah, well use str(self._it-1) then :D think it updates the _it for the next iteration when it has been used

mander76 commented 1 year ago

@arjunsk07 can I close this issue?