Base class for user-defined scenario
| 24 | |
| 25 | |
| 26 | class BasicScenario(object): |
| 27 | |
| 28 | """ |
| 29 | Base class for user-defined scenario |
| 30 | """ |
| 31 | |
| 32 | def __init__(self, name, ego_vehicles, config, world, |
| 33 | debug_mode=False, terminate_on_failure=False, criteria_enable=False): |
| 34 | """ |
| 35 | Setup all relevant parameters and create scenario |
| 36 | and instantiate scenario manager |
| 37 | """ |
| 38 | self.other_actors = [] |
| 39 | if not self.timeout: # pylint: disable=access-member-before-definition |
| 40 | self.timeout = 60 # If no timeout was provided, set it to 60 seconds |
| 41 | |
| 42 | self.criteria_list = [] # List of evaluation criteria |
| 43 | self.scenario = None |
| 44 | |
| 45 | self.ego_vehicles = ego_vehicles |
| 46 | self.name = name |
| 47 | self.config = config |
| 48 | self.terminate_on_failure = terminate_on_failure |
| 49 | |
| 50 | self._initialize_environment(world) |
| 51 | |
| 52 | # Initializing adversarial actors |
| 53 | self._initialize_actors(config) |
| 54 | if CarlaDataProvider.is_sync_mode(): |
| 55 | world.tick() |
| 56 | else: |
| 57 | world.wait_for_tick() |
| 58 | |
| 59 | # Setup scenario |
| 60 | if debug_mode: |
| 61 | py_trees.logging.level = py_trees.logging.Level.DEBUG |
| 62 | |
| 63 | behavior = self._create_behavior() |
| 64 | |
| 65 | criteria = None |
| 66 | if criteria_enable: |
| 67 | criteria = self._create_test_criteria() |
| 68 | |
| 69 | # Add a trigger condition for the behavior to ensure the behavior is only activated, when it is relevant |
| 70 | behavior_seq = py_trees.composites.Sequence() |
| 71 | trigger_behavior = self._setup_scenario_trigger(config) |
| 72 | if trigger_behavior: |
| 73 | behavior_seq.add_child(trigger_behavior) |
| 74 | |
| 75 | if behavior is not None: |
| 76 | behavior_seq.add_child(behavior) |
| 77 | behavior_seq.name = behavior.name |
| 78 | |
| 79 | end_behavior = self._setup_scenario_end(config) |
| 80 | if end_behavior: |
| 81 | behavior_seq.add_child(end_behavior) |
| 82 | |
| 83 | self.scenario = Scenario(behavior_seq, criteria, self.name, self.timeout, self.terminate_on_failure) |
nothing calls this directly
no outgoing calls
no test coverage detected