scenario_configuration.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/env python
  2. # Copyright (c) 2019 Intel Corporation
  3. #
  4. # This work is licensed under the terms of the MIT license.
  5. # For a copy, see <https://opensource.org/licenses/MIT>.
  6. """
  7. This module provides the key configuration parameters for an XML-based scenario
  8. """
  9. import carla
  10. class ActorConfigurationData(object):
  11. """
  12. This is a configuration base class to hold model and transform attributes
  13. """
  14. def __init__(self, model, transform, rolename='other', speed=0, autopilot=False,
  15. random=False, color=None, category="car", args=None):
  16. self.model = model
  17. self.rolename = rolename
  18. self.transform = transform
  19. self.speed = speed
  20. self.autopilot = autopilot
  21. self.random_location = random
  22. self.color = color
  23. self.category = category
  24. self.args = args
  25. @staticmethod
  26. def parse_from_node(node, rolename):
  27. """
  28. static method to initialize an ActorConfigurationData from a given ET tree
  29. """
  30. model = node.attrib.get('model', 'vehicle.*')
  31. pos_x = float(node.attrib.get('x', 0))
  32. pos_y = float(node.attrib.get('y', 0))
  33. pos_z = float(node.attrib.get('z', 0))
  34. yaw = float(node.attrib.get('yaw', 0))
  35. transform = carla.Transform(carla.Location(x=pos_x, y=pos_y, z=pos_z), carla.Rotation(yaw=yaw))
  36. rolename = node.attrib.get('rolename', rolename)
  37. speed = node.attrib.get('speed', 0)
  38. autopilot = False
  39. if 'autopilot' in node.keys():
  40. autopilot = True
  41. random_location = False
  42. if 'random_location' in node.keys():
  43. print("21321323234234")
  44. random_location = True
  45. color = node.attrib.get('color', None)
  46. return ActorConfigurationData(model, transform, rolename, speed, autopilot, random_location, color)
  47. class ScenarioConfiguration(object):
  48. """
  49. This class provides a basic scenario configuration incl.:
  50. - configurations for all actors
  51. - town, where the scenario should be executed
  52. - name of the scenario (e.g. ControlLoss_1)
  53. - type is the class of scenario (e.g. ControlLoss)
  54. """
  55. trigger_points = []
  56. ego_vehicles = []
  57. other_actors = []
  58. town = None
  59. name = None
  60. type = None
  61. route = None
  62. agent = None
  63. weather = carla.WeatherParameters()
  64. friction = None
  65. subtype = None
  66. route_var_name = None