carla-driver-interface 2.3.0__tar.gz → 2.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/PKG-INFO +1 -1
  2. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/pyproject.toml +1 -1
  3. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/pyproject.toml.orig +1 -1
  4. carla_driver_interface-2.4.0/src/carla_driver_interface/_proto/carla_driver_pb2.py +69 -0
  5. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/_proto/carla_driver_pb2.pyi +4 -2
  6. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/hdmap.py +15 -1
  7. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/service.py +23 -2
  8. carla_driver_interface-2.4.0/src/carla_driver_interface/t4_scene.py +176 -0
  9. carla_driver_interface-2.3.0/src/carla_driver_interface/_proto/carla_driver_pb2.py +0 -69
  10. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/LICENSE +0 -0
  11. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/README.md +0 -0
  12. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/__init__.py +0 -0
  13. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/_proto/__init__.py +0 -0
  14. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/_proto/carla_driver_pb2_grpc.py +0 -0
  15. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/_proto/common_pb2.py +0 -0
  16. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/_proto/common_pb2.pyi +0 -0
  17. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/_proto/egodriver_pb2.py +0 -0
  18. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/_proto/egodriver_pb2.pyi +0 -0
  19. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/_proto/egodriver_pb2_grpc.py +0 -0
  20. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/_proto/sensorsim_pb2.py +0 -0
  21. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/_proto/sensorsim_pb2.pyi +0 -0
  22. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/alpasim.py +0 -0
  23. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/cli.py +0 -0
  24. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/contract.py +0 -0
  25. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/driver.py +0 -0
  26. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/geometry.py +0 -0
  27. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/inprocess.py +0 -0
  28. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/policies/__init__.py +0 -0
  29. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/policies/constant_speed.py +0 -0
  30. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/policies/route_follower.py +0 -0
  31. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/polyline.py +0 -0
  32. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/protocol.py +0 -0
  33. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/py.typed +0 -0
  34. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/server.py +0 -0
  35. {carla_driver_interface-2.3.0 → carla_driver_interface-2.4.0}/src/carla_driver_interface/testing.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: carla-driver-interface
3
- Version: 2.3.0
3
+ Version: 2.4.0
4
4
  Summary: Both ends of alpasim's egodriver gRPC contract: serve a driving policy, or drive one without CARLA
5
5
  Author: Masaya Kataoka
6
6
  Author-email: Masaya Kataoka <ms.kataoka@gmail.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "carla-driver-interface"
3
- version = "2.3.0"
3
+ version = "2.4.0"
4
4
  description = "Both ends of alpasim's egodriver gRPC contract: serve a driving policy, or drive one without CARLA"
5
5
  readme = "README.md"
6
6
  license = "Apache-2.0"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "carla-driver-interface"
3
- version = "2.3.0"
3
+ version = "2.4.0"
4
4
  description = "Both ends of alpasim's egodriver gRPC contract: serve a driving policy, or drive one without CARLA"
5
5
  readme = "README.md"
6
6
  license = "Apache-2.0"
@@ -0,0 +1,69 @@
1
+ # Generated by scripts/compile_protos.py -- do not edit.
2
+ #
3
+ # Sources: NVlabs/alpasim@6870924 and
4
+ # hakuturu583/carla_driver_interface@af1dcd3 (both Apache-2.0)
5
+ # Regenerate with: uv run python scripts/compile_protos.py
6
+
7
+ # -*- coding: utf-8 -*-
8
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
9
+ # source: carla_driver/v0/carla_driver.proto
10
+ # Protobuf Python Version: 4.25.1
11
+ """Generated protocol buffer code."""
12
+ from google.protobuf import descriptor as _descriptor
13
+ from google.protobuf import descriptor_pool as _descriptor_pool
14
+ from google.protobuf import symbol_database as _symbol_database
15
+ from google.protobuf.internal import builder as _builder
16
+ # @@protoc_insertion_point(imports)
17
+
18
+ _sym_db = _symbol_database.Default()
19
+
20
+
21
+ from . import common_pb2 as alpasim__grpc_dot_v0_dot_common__pb2
22
+ from . import egodriver_pb2 as alpasim__grpc_dot_v0_dot_egodriver__pb2
23
+ from . import sensorsim_pb2 as alpasim__grpc_dot_v0_dot_sensorsim__pb2
24
+
25
+
26
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\"carla_driver/v0/carla_driver.proto\x12\x0f\x63\x61rla_driver.v0\x1a\x1c\x61lpasim_grpc/v0/common.proto\x1a\x1f\x61lpasim_grpc/v0/egodriver.proto\x1a\x1f\x61lpasim_grpc/v0/sensorsim.proto\"\xce\x01\n\x0c\x43\x61rlaWeather\x12\x12\n\ncloudiness\x18\x01 \x01(\x02\x12\x15\n\rprecipitation\x18\x02 \x01(\x02\x12\x1e\n\x16precipitation_deposits\x18\x03 \x01(\x02\x12\x16\n\x0ewind_intensity\x18\x04 \x01(\x02\x12\x19\n\x11sun_azimuth_angle\x18\x05 \x01(\x02\x12\x1a\n\x12sun_altitude_angle\x18\x06 \x01(\x02\x12\x13\n\x0b\x66og_density\x18\x07 \x01(\x02\x12\x0f\n\x07wetness\x18\x08 \x01(\x02\"\xa7\x01\n\x0f\x43\x61rlaActorState\x12\x10\n\x08track_id\x18\x01 \x01(\t\x12\x0f\n\x07type_id\x18\x02 \x01(\t\x12(\n\x12pose_local_to_aabb\x18\x03 \x01(\x0b\x32\x0c.common.Pose\x12\x1a\n\x04\x61\x61\x62\x62\x18\x04 \x01(\x0b\x32\x0c.common.AABB\x12+\n\rdynamic_state\x18\x05 \x01(\x0b\x32\x14.common.DynamicState\"\xc8\x03\n\x11\x43\x61rlaRendererData\x12\x1d\n\x15snapshot_timestamp_us\x18\x01 \x01(\x06\x12\x10\n\x08\x66rame_id\x18\x02 \x01(\x04\x12\x10\n\x08map_name\x18\x03 \x01(\t\x12.\n\x07weather\x18\x04 \x01(\x0b\x32\x1d.carla_driver.v0.CarlaWeather\x12=\n\x11\x65go_traffic_light\x18\x05 \x01(\x0e\x32\".carla_driver.v0.TrafficLightState\x12$\n\x1c\x65go_traffic_light_distance_m\x18\x06 \x01(\x02\x12\x17\n\x0fspeed_limit_mps\x18\x07 \x01(\x02\x12\x30\n\x06\x61\x63tors\x18\x08 \x03(\x0b\x32 .carla_driver.v0.CarlaActorState\x12*\n\x05lidar\x18\n \x03(\x0b\x32\x1b.carla_driver.v0.LidarSweep\x12\x0e\n\x06map_id\x18\x0b \x01(\t\x12\x35\n\x0etraffic_lights\x18\x0c \x03(\x0b\x32\x1d.carla_driver.v0.TrafficLight\x12\x10\n\x08t4_scene\x18\r \x01(\x0cJ\x04\x08\t\x10\nR\x05lanes\"\x88\x01\n\x0cTrafficLight\x12\x14\n\x0copendrive_id\x18\x01 \x01(\t\x12\x31\n\x05state\x18\x02 \x01(\x0e\x32\".carla_driver.v0.TrafficLightState\x12/\n\x0bstop_points\x18\x03 \x03(\x0b\x32\x1a.carla_driver.v0.StopPoint\"g\n\tStopPoint\x12\x0f\n\x07road_id\x18\x01 \x01(\x05\x12\x12\n\nsection_id\x18\x02 \x01(\x05\x12\x0f\n\x07lane_id\x18\x03 \x01(\x05\x12$\n\x0eposition_local\x18\x04 \x01(\x0b\x32\x0c.common.Vec3\"\x83\x01\n\nLidarSweep\x12\x12\n\nlogical_id\x18\x01 \x01(\t\x12\x14\n\x0ctimestamp_us\x18\x02 \x01(\x06\x12\"\n\x0crig_to_lidar\x18\x03 \x01(\x0b\x32\x0c.common.Pose\x12\x12\n\nnum_points\x18\x04 \x01(\r\x12\x13\n\x0bpoints_xyzi\x18\x05 \x01(\x0c\"\xb9\x01\n\x13\x43\x61rlaDriveDebugInfo\x12\x13\n\x0bpolicy_name\x18\x01 \x01(\t\x12\x19\n\x11inference_seconds\x18\x02 \x01(\x02\x12\x42\n\x07scalars\x18\x03 \x03(\x0b\x32\x31.carla_driver.v0.CarlaDriveDebugInfo.ScalarsEntry\x1a.\n\x0cScalarsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\x01:\x02\x38\x01\"]\n\x0eVehicleCommand\x12\x13\n\x0btime_now_us\x18\x01 \x01(\x06\x12\x36\n\x0eturn_indicator\x18\x02 \x01(\x0e\x32\x1e.carla_driver.v0.TurnIndicator\"-\n\x15VehicleCommandRequest\x12\x14\n\x0csession_uuid\x18\x01 \x01(\t\"\x92\x02\n\x15\x43\x61rlaDriveSessionInfo\x12,\n\x04\x62\x61se\x18\x01 \x01(\x0b\x32\x1e.egodriver.DriveSessionRequest\x12\x10\n\x08map_name\x18\x02 \x01(\t\x12\x15\n\rscenario_name\x18\x03 \x01(\t\x12\x16\n\x0e\x66ixed_delta_us\x18\x04 \x01(\x06\x12\x1a\n\x12policy_timestep_us\x18\x05 \x01(\x06\x12\x1a\n\x12rear_axle_offset_m\x18\x06 \x01(\x02\x12R\n\x07\x63\x61meras\x18\x07 \x03(\x0b\x32\x41.nre.grpc.protos.sensorsim.AvailableCamerasReturn.AvailableCamera\"\x8d\x01\n\x0b\x43ompatEntry\x12\x0c\n\x04\x61rea\x18\x01 \x01(\t\x12\x19\n\x11\x61lpasim_behaviour\x18\x02 \x01(\t\x12\x17\n\x0f\x63\x61rla_behaviour\x18\x03 \x01(\t\x12+\n\x05level\x18\x04 \x01(\x0e\x32\x1c.carla_driver.v0.CompatLevel\x12\x0f\n\x07symbols\x18\x05 \x03(\t\"\xc4\x01\n\x11\x43\x61rlaCompatReport\x12&\n\x1e\x63\x61rla_driver_interface_version\x18\x01 \x01(\t\x12\x18\n\x10\x61lpasim_grpc_rev\x18\x02 \x01(\t\x12>\n\x18\x61lpasim_grpc_api_version\x18\x03 \x01(\x0b\x32\x1c.common.VersionId.APIVersion\x12-\n\x07\x65ntries\x18\x04 \x03(\x0b\x32\x1c.carla_driver.v0.CompatEntry*\xcb\x01\n\x11TrafficLightState\x12\x1f\n\x1bTRAFFIC_LIGHT_STATE_UNKNOWN\x10\x00\x12\x1c\n\x18TRAFFIC_LIGHT_STATE_NONE\x10\x01\x12\x1b\n\x17TRAFFIC_LIGHT_STATE_RED\x10\x02\x12\x1e\n\x1aTRAFFIC_LIGHT_STATE_YELLOW\x10\x03\x12\x1d\n\x19TRAFFIC_LIGHT_STATE_GREEN\x10\x04\x12\x1b\n\x17TRAFFIC_LIGHT_STATE_OFF\x10\x05*\x8b\x01\n\rTurnIndicator\x12\x1d\n\x19TURN_INDICATOR_NO_COMMAND\x10\x00\x12\x1a\n\x16TURN_INDICATOR_DISABLE\x10\x01\x12\x1e\n\x1aTURN_INDICATOR_ENABLE_LEFT\x10\x02\x12\x1f\n\x1bTURN_INDICATOR_ENABLE_RIGHT\x10\x03*\xb6\x01\n\x0b\x43ompatLevel\x12\x1c\n\x18\x43OMPAT_LEVEL_UNSPECIFIED\x10\x00\x12\x16\n\x12\x43OMPAT_LEVEL_EXACT\x10\x01\x12\x18\n\x14\x43OMPAT_LEVEL_PARTIAL\x10\x02\x12\x1b\n\x17\x43OMPAT_LEVEL_STRUCTURAL\x10\x03\x12\x1e\n\x1a\x43OMPAT_LEVEL_UNIMPLEMENTED\x10\x04\x12\x1a\n\x16\x43OMPAT_LEVEL_EXTENSION\x10\x05\x32u\n\x13\x43\x61rlaVehicleService\x12^\n\x13get_vehicle_command\x12&.carla_driver.v0.VehicleCommandRequest\x1a\x1f.carla_driver.v0.VehicleCommandb\x06proto3')
27
+
28
+ _globals = globals()
29
+ _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
30
+ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'carla_driver.v0.carla_driver_pb2', _globals)
31
+ if _descriptor._USE_C_DESCRIPTORS == False:
32
+ DESCRIPTOR._options = None
33
+ _globals['_CARLADRIVEDEBUGINFO_SCALARSENTRY']._options = None
34
+ _globals['_CARLADRIVEDEBUGINFO_SCALARSENTRY']._serialized_options = b'8\001'
35
+ _globals['_TRAFFICLIGHTSTATE']._serialized_start=2318
36
+ _globals['_TRAFFICLIGHTSTATE']._serialized_end=2521
37
+ _globals['_TURNINDICATOR']._serialized_start=2524
38
+ _globals['_TURNINDICATOR']._serialized_end=2663
39
+ _globals['_COMPATLEVEL']._serialized_start=2666
40
+ _globals['_COMPATLEVEL']._serialized_end=2848
41
+ _globals['_CARLAWEATHER']._serialized_start=152
42
+ _globals['_CARLAWEATHER']._serialized_end=358
43
+ _globals['_CARLAACTORSTATE']._serialized_start=361
44
+ _globals['_CARLAACTORSTATE']._serialized_end=528
45
+ _globals['_CARLARENDERERDATA']._serialized_start=531
46
+ _globals['_CARLARENDERERDATA']._serialized_end=987
47
+ _globals['_TRAFFICLIGHT']._serialized_start=990
48
+ _globals['_TRAFFICLIGHT']._serialized_end=1126
49
+ _globals['_STOPPOINT']._serialized_start=1128
50
+ _globals['_STOPPOINT']._serialized_end=1231
51
+ _globals['_LIDARSWEEP']._serialized_start=1234
52
+ _globals['_LIDARSWEEP']._serialized_end=1365
53
+ _globals['_CARLADRIVEDEBUGINFO']._serialized_start=1368
54
+ _globals['_CARLADRIVEDEBUGINFO']._serialized_end=1553
55
+ _globals['_CARLADRIVEDEBUGINFO_SCALARSENTRY']._serialized_start=1507
56
+ _globals['_CARLADRIVEDEBUGINFO_SCALARSENTRY']._serialized_end=1553
57
+ _globals['_VEHICLECOMMAND']._serialized_start=1555
58
+ _globals['_VEHICLECOMMAND']._serialized_end=1648
59
+ _globals['_VEHICLECOMMANDREQUEST']._serialized_start=1650
60
+ _globals['_VEHICLECOMMANDREQUEST']._serialized_end=1695
61
+ _globals['_CARLADRIVESESSIONINFO']._serialized_start=1698
62
+ _globals['_CARLADRIVESESSIONINFO']._serialized_end=1972
63
+ _globals['_COMPATENTRY']._serialized_start=1975
64
+ _globals['_COMPATENTRY']._serialized_end=2116
65
+ _globals['_CARLACOMPATREPORT']._serialized_start=2119
66
+ _globals['_CARLACOMPATREPORT']._serialized_end=2315
67
+ _globals['_CARLAVEHICLESERVICE']._serialized_start=2850
68
+ _globals['_CARLAVEHICLESERVICE']._serialized_end=2967
69
+ # @@protoc_insertion_point(module_scope)
@@ -91,7 +91,7 @@ class CarlaActorState(_message.Message):
91
91
  def __init__(self, track_id: _Optional[str] = ..., type_id: _Optional[str] = ..., pose_local_to_aabb: _Optional[_Union[_common_pb2.Pose, _Mapping]] = ..., aabb: _Optional[_Union[_common_pb2.AABB, _Mapping]] = ..., dynamic_state: _Optional[_Union[_common_pb2.DynamicState, _Mapping]] = ...) -> None: ...
92
92
 
93
93
  class CarlaRendererData(_message.Message):
94
- __slots__ = ("snapshot_timestamp_us", "frame_id", "map_name", "weather", "ego_traffic_light", "ego_traffic_light_distance_m", "speed_limit_mps", "actors", "lidar", "map_id", "traffic_lights")
94
+ __slots__ = ("snapshot_timestamp_us", "frame_id", "map_name", "weather", "ego_traffic_light", "ego_traffic_light_distance_m", "speed_limit_mps", "actors", "lidar", "map_id", "traffic_lights", "t4_scene")
95
95
  SNAPSHOT_TIMESTAMP_US_FIELD_NUMBER: _ClassVar[int]
96
96
  FRAME_ID_FIELD_NUMBER: _ClassVar[int]
97
97
  MAP_NAME_FIELD_NUMBER: _ClassVar[int]
@@ -103,6 +103,7 @@ class CarlaRendererData(_message.Message):
103
103
  LIDAR_FIELD_NUMBER: _ClassVar[int]
104
104
  MAP_ID_FIELD_NUMBER: _ClassVar[int]
105
105
  TRAFFIC_LIGHTS_FIELD_NUMBER: _ClassVar[int]
106
+ T4_SCENE_FIELD_NUMBER: _ClassVar[int]
106
107
  snapshot_timestamp_us: int
107
108
  frame_id: int
108
109
  map_name: str
@@ -114,7 +115,8 @@ class CarlaRendererData(_message.Message):
114
115
  lidar: _containers.RepeatedCompositeFieldContainer[LidarSweep]
115
116
  map_id: str
116
117
  traffic_lights: _containers.RepeatedCompositeFieldContainer[TrafficLight]
117
- def __init__(self, snapshot_timestamp_us: _Optional[int] = ..., frame_id: _Optional[int] = ..., map_name: _Optional[str] = ..., weather: _Optional[_Union[CarlaWeather, _Mapping]] = ..., ego_traffic_light: _Optional[_Union[TrafficLightState, str]] = ..., ego_traffic_light_distance_m: _Optional[float] = ..., speed_limit_mps: _Optional[float] = ..., actors: _Optional[_Iterable[_Union[CarlaActorState, _Mapping]]] = ..., lidar: _Optional[_Iterable[_Union[LidarSweep, _Mapping]]] = ..., map_id: _Optional[str] = ..., traffic_lights: _Optional[_Iterable[_Union[TrafficLight, _Mapping]]] = ...) -> None: ...
118
+ t4_scene: bytes
119
+ def __init__(self, snapshot_timestamp_us: _Optional[int] = ..., frame_id: _Optional[int] = ..., map_name: _Optional[str] = ..., weather: _Optional[_Union[CarlaWeather, _Mapping]] = ..., ego_traffic_light: _Optional[_Union[TrafficLightState, str]] = ..., ego_traffic_light_distance_m: _Optional[float] = ..., speed_limit_mps: _Optional[float] = ..., actors: _Optional[_Iterable[_Union[CarlaActorState, _Mapping]]] = ..., lidar: _Optional[_Iterable[_Union[LidarSweep, _Mapping]]] = ..., map_id: _Optional[str] = ..., traffic_lights: _Optional[_Iterable[_Union[TrafficLight, _Mapping]]] = ..., t4_scene: _Optional[bytes] = ...) -> None: ...
118
120
 
119
121
  class TrafficLight(_message.Message):
120
122
  __slots__ = ("opendrive_id", "state", "stop_points")
@@ -259,13 +259,21 @@ class _GivenLanelet2:
259
259
  right = np.array([xy[n] for n in ways[members["right"]]])
260
260
  except KeyError:
261
261
  continue # a lanelet without both bounds, or off the local frame
262
- # The left bound gives the direction; the right runs with it.
262
+ # The right bound runs with the left.
263
263
  if np.linalg.norm(left[0] - right[-1]) + np.linalg.norm(
264
264
  left[-1] - right[0]
265
265
  ) < np.linalg.norm(left[0] - right[0]) + np.linalg.norm(
266
266
  left[-1] - right[-1]
267
267
  ):
268
268
  right = right[::-1]
269
+ # And the lanelet runs the way Lanelet2 reads it: with its left bound
270
+ # on the left, whichever order the ways are written in. A writer that
271
+ # shares one way between lanes running opposite ways -- roadgen does --
272
+ # writes a backward lane's bounds against its travel. Left bound on,
273
+ # right bound back, the outline turns clockwise when the left bound is
274
+ # on the left.
275
+ if _signed_area(np.vstack([left, right[::-1]])) > 0:
276
+ left, right = left[::-1], right[::-1]
269
277
  lanelet = rel.get("id", "")
270
278
  rules = tuple(
271
279
  m.get("ref", "")
@@ -395,6 +403,12 @@ def _length(points: np.ndarray) -> float:
395
403
  return float(np.linalg.norm(np.diff(points, axis=0), axis=1).sum())
396
404
 
397
405
 
406
+ def _signed_area(polygon: np.ndarray) -> float:
407
+ """The shoelace area of a closed ``(N, 2)`` outline: positive anticlockwise."""
408
+ x, y = polygon[:, 0], polygon[:, 1]
409
+ return 0.5 * float(np.dot(x, np.roll(y, -1)) - np.dot(np.roll(x, -1), y))
410
+
411
+
398
412
  def _cell(point: np.ndarray) -> tuple[int, int]:
399
413
  return (math.floor(point[0]), math.floor(point[1]))
400
414
 
@@ -31,7 +31,7 @@ import logging
31
31
  import pickle
32
32
  import threading
33
33
  import time
34
- from typing import Dict, Literal, Optional, get_args
34
+ from typing import Any, Dict, Literal, Optional, get_args
35
35
 
36
36
  import grpc
37
37
  import numpy as np
@@ -332,7 +332,7 @@ class EgodriverServicer(EgodriverServiceServicer, CarlaVehicleServiceServicer):
332
332
  trajectory=trajectory,
333
333
  debug_info=DriveResponse.DebugInfo(
334
334
  unstructured_debug_info=self._debug_payload(
335
- elapsed, result.debug_scalars
335
+ elapsed, _debug_scalars(result.debug_scalars, self._driver.name)
336
336
  ),
337
337
  sampled_trajectories=sampled,
338
338
  ),
@@ -411,6 +411,27 @@ class EgodriverServicer(EgodriverServiceServicer, CarlaVehicleServiceServicer):
411
411
  return session
412
412
 
413
413
 
414
+ def _debug_scalars(values: Dict[str, Any], policy_name: str) -> Dict[str, float]:
415
+ """The numbers among a policy's debug scalars.
416
+
417
+ Like a bad indicator, a debug value that is not a number must not cost the
418
+ policy its plan: it is logged and left out.
419
+ """
420
+ scalars: Dict[str, float] = {}
421
+ for key, value in (values or {}).items():
422
+ try:
423
+ scalars[str(key)] = float(value)
424
+ except (TypeError, ValueError):
425
+ logger.warning(
426
+ "policy %r returned debug scalar %r=%r, which is not a number; "
427
+ "leaving it out",
428
+ policy_name,
429
+ key,
430
+ value,
431
+ )
432
+ return scalars
433
+
434
+
414
435
  def _turn_indicator(value: int, policy_name: str) -> TurnIndicator:
415
436
  """*value* as a :class:`TurnIndicator`; ``NO_COMMAND`` when it is none.
416
437
 
@@ -0,0 +1,176 @@
1
+ """A policy fed T4Scenes: :class:`T4SceneDriver`, a :class:`BaseDriver` like any other.
2
+
3
+ tier4/e2e-devkit wraps a trained model as a *T4 driver*
4
+ (``t4_e2e_devkit.driver.AbstractT4Driver``): a ``T4Scene`` goes in, an
5
+ ego-frame plan comes out, and the model is fed exactly the window it was
6
+ trained on. :class:`T4SceneDriver` puts one behind the egodriver contract.
7
+ The runtime sends the rollout so far as a scene with every drive
8
+ (``CarlaRendererData.t4_scene``, ``driver.t4_scene``), and the map it
9
+ references once, as the map set's ``t4`` format; this class decodes both, hands
10
+ the scene to the T4 driver under the session's id, and returns its plan as a
11
+ :class:`DriveResult` like any other policy's.
12
+
13
+ Nothing else changes: the session still records every observation, so a
14
+ subclass can read ``ctx.session`` beside the scene, and a policy that does not
15
+ read scenes keeps subclassing :class:`BaseDriver` itself.
16
+
17
+ Needs the devkit (``t4-e2e-devkit``), imported when the first scene is decoded:
18
+ this package does not depend on it.
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import logging
24
+ import threading
25
+ from pathlib import Path
26
+ from typing import TYPE_CHECKING, Any, Dict, Optional
27
+
28
+ import numpy as np
29
+
30
+ from .driver import BaseDriver, DriveContext, DriveResult, SessionState, TurnIndicator
31
+ from .geometry import Pose, Trajectory
32
+
33
+ if TYPE_CHECKING:
34
+ from .hdmap import MapFiles
35
+
36
+ __all__ = ["T4_MAP_FORMAT", "T4SceneDriver"]
37
+
38
+ logger = logging.getLogger(__name__)
39
+
40
+ #: The map set format holding the scene's map resource: a serialized
41
+ #: ``t4_e2e_devkit`` ``MapResource`` (Lanelet2 OSM in Autoware's ``map`` frame).
42
+ T4_MAP_FORMAT = "t4"
43
+
44
+
45
+ class T4SceneDriver(BaseDriver):
46
+ """Drives with a devkit T4 driver over the scene the runtime sends.
47
+
48
+ Args:
49
+ scene_driver: The model, as a ``t4_e2e_devkit.driver.AbstractT4Driver``.
50
+ map_dir: Your copy of the runtime's ``driver.map_dir``, where the scene's
51
+ map resource is (the ``t4`` format); ``None`` for a model that reads
52
+ no map.
53
+ name: Reported as the policy's name; the T4 driver's own by default.
54
+
55
+ The plan the T4 driver returns is in the ego frame of the scene's current
56
+ row, the rig at ``time_now_us``; pose ``i`` is ``(i + 1)`` sampling
57
+ intervals later. Its ``extras`` may carry ``turn_indicator`` (an
58
+ :class:`TurnIndicator` value) and ``debug_scalars`` (a ``str -> float``
59
+ mapping), which the result passes on; the servicer drops a value of
60
+ either it cannot send, keeping the plan.
61
+
62
+ One drive at a time: a T4 driver holds a model and per-session state that
63
+ concurrent drives would share.
64
+ """
65
+
66
+ map_format: str = T4_MAP_FORMAT
67
+
68
+ def __init__(
69
+ self,
70
+ scene_driver: Any,
71
+ *,
72
+ map_dir: Optional[str] = None,
73
+ name: Optional[str] = None,
74
+ ) -> None:
75
+ self.scene_driver = scene_driver
76
+ self.map_dir = map_dir
77
+ self.name = name if name is not None else str(scene_driver.name())
78
+ #: The map resources registered, one store for every map.
79
+ self._store: Any = None
80
+ #: Each map set's resource, read once, by map id.
81
+ self._read: Dict[str, Any] = {}
82
+ self._lock = threading.Lock()
83
+
84
+ # -- sessions -------------------------------------------------------------
85
+
86
+ def on_session_start(self, session: SessionState) -> None:
87
+ self.scene_driver.start_session(session.uuid)
88
+
89
+ def on_session_close(self, session: SessionState) -> None:
90
+ self.scene_driver.close_session(session.uuid)
91
+
92
+ # -- the decision -----------------------------------------------------------
93
+
94
+ def drive(self, ctx: DriveContext) -> DriveResult:
95
+ with self._lock:
96
+ output = self.scene_driver.drive(
97
+ self.scene(ctx), session_id=ctx.session.uuid
98
+ )
99
+ return self.result(output, ctx)
100
+
101
+ def scene(self, ctx: DriveContext) -> Any:
102
+ """The step's ``T4Scene``, its map resolved.
103
+
104
+ Raises:
105
+ RuntimeError: when the runtime sent no scene; it sends one only when
106
+ asked to (``driver.t4_scene``).
107
+ """
108
+ payload = None if ctx.renderer_data is None else ctx.renderer_data.t4_scene
109
+ if not payload:
110
+ raise RuntimeError(
111
+ f"{self.name} plans from T4Scenes, and this drive carries none: run the "
112
+ "runtime with driver.t4_scene on"
113
+ )
114
+ from t4_e2e_devkit.serialization.protobuf import from_proto, t4_scene_pb2
115
+
116
+ message = t4_scene_pb2.T4Scene.FromString(payload)
117
+ store = self._map_store(ctx.map)
118
+ try:
119
+ return from_proto(message, map_resources=store)
120
+ except KeyError as error:
121
+ # The store keeps the most recent maps; one it let go is
122
+ # registered again from the copy read.
123
+ if ctx.map is None or "not registered" not in str(error):
124
+ raise
125
+ store.register(self._read[ctx.map.map_id])
126
+ return from_proto(message, map_resources=store)
127
+
128
+ def result(self, output: Any, ctx: DriveContext) -> DriveResult:
129
+ """A T4 driver's ``DriverOutput`` as the egodriver's result, in the rig frame."""
130
+ trajectory = output.trajectory
131
+ poses = np.asarray(trajectory.poses, dtype=np.float64)
132
+ if poses.ndim != 2 or poses.shape[1] != 3:
133
+ raise ValueError(
134
+ f"{self.name} returned poses of shape {poses.shape}, not (N, 3) x, y, heading"
135
+ )
136
+ step_us = int(
137
+ round(float(trajectory.trajectory_sampling.interval_length) * 1e6)
138
+ )
139
+ if step_us <= 0:
140
+ raise ValueError(
141
+ f"{self.name} returned a plan sampled every {step_us} us; "
142
+ "its poses would all be at the anchor"
143
+ )
144
+ plan = Trajectory.empty()
145
+ for index, (x, y, yaw) in enumerate(poses, start=1):
146
+ plan.append(
147
+ ctx.time_now_us + index * step_us, Pose.from_xyz_yaw(x, y, 0.0, yaw)
148
+ )
149
+ extras = output.extras or {}
150
+ return DriveResult(
151
+ trajectory_in_rig=plan,
152
+ turn_indicator=extras.get("turn_indicator", TurnIndicator.NO_COMMAND),
153
+ debug_scalars=dict(extras.get("debug_scalars") or {}),
154
+ )
155
+
156
+ def _map_store(self, map_files: Optional["MapFiles"]) -> Any:
157
+ """The store holding the step's map resource; ``None`` without a map set.
158
+
159
+ Each set's resource is read and registered once: it does not change
160
+ under its id.
161
+ """
162
+ if map_files is None:
163
+ return None
164
+ from t4_e2e_devkit.serialization.protobuf import MapResourceStore, t4_scene_pb2
165
+
166
+ if self._store is None:
167
+ # Room for every map a server is likely to meet.
168
+ self._store = MapResourceStore(max_maps=64)
169
+ if map_files.map_id not in self._read:
170
+ resource = t4_scene_pb2.MapResource.FromString(
171
+ Path(map_files.path).read_bytes()
172
+ )
173
+ self._store.register(resource)
174
+ self._read[map_files.map_id] = resource
175
+ logger.info("registered the T4 map of %s", map_files.map_id)
176
+ return self._store
@@ -1,69 +0,0 @@
1
- # Generated by scripts/compile_protos.py -- do not edit.
2
- #
3
- # Sources: NVlabs/alpasim@6870924 and
4
- # hakuturu583/carla_driver_interface@af1dcd3 (both Apache-2.0)
5
- # Regenerate with: uv run python scripts/compile_protos.py
6
-
7
- # -*- coding: utf-8 -*-
8
- # Generated by the protocol buffer compiler. DO NOT EDIT!
9
- # source: carla_driver/v0/carla_driver.proto
10
- # Protobuf Python Version: 4.25.1
11
- """Generated protocol buffer code."""
12
- from google.protobuf import descriptor as _descriptor
13
- from google.protobuf import descriptor_pool as _descriptor_pool
14
- from google.protobuf import symbol_database as _symbol_database
15
- from google.protobuf.internal import builder as _builder
16
- # @@protoc_insertion_point(imports)
17
-
18
- _sym_db = _symbol_database.Default()
19
-
20
-
21
- from . import common_pb2 as alpasim__grpc_dot_v0_dot_common__pb2
22
- from . import egodriver_pb2 as alpasim__grpc_dot_v0_dot_egodriver__pb2
23
- from . import sensorsim_pb2 as alpasim__grpc_dot_v0_dot_sensorsim__pb2
24
-
25
-
26
- DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\"carla_driver/v0/carla_driver.proto\x12\x0f\x63\x61rla_driver.v0\x1a\x1c\x61lpasim_grpc/v0/common.proto\x1a\x1f\x61lpasim_grpc/v0/egodriver.proto\x1a\x1f\x61lpasim_grpc/v0/sensorsim.proto\"\xce\x01\n\x0c\x43\x61rlaWeather\x12\x12\n\ncloudiness\x18\x01 \x01(\x02\x12\x15\n\rprecipitation\x18\x02 \x01(\x02\x12\x1e\n\x16precipitation_deposits\x18\x03 \x01(\x02\x12\x16\n\x0ewind_intensity\x18\x04 \x01(\x02\x12\x19\n\x11sun_azimuth_angle\x18\x05 \x01(\x02\x12\x1a\n\x12sun_altitude_angle\x18\x06 \x01(\x02\x12\x13\n\x0b\x66og_density\x18\x07 \x01(\x02\x12\x0f\n\x07wetness\x18\x08 \x01(\x02\"\xa7\x01\n\x0f\x43\x61rlaActorState\x12\x10\n\x08track_id\x18\x01 \x01(\t\x12\x0f\n\x07type_id\x18\x02 \x01(\t\x12(\n\x12pose_local_to_aabb\x18\x03 \x01(\x0b\x32\x0c.common.Pose\x12\x1a\n\x04\x61\x61\x62\x62\x18\x04 \x01(\x0b\x32\x0c.common.AABB\x12+\n\rdynamic_state\x18\x05 \x01(\x0b\x32\x14.common.DynamicState\"\xb6\x03\n\x11\x43\x61rlaRendererData\x12\x1d\n\x15snapshot_timestamp_us\x18\x01 \x01(\x06\x12\x10\n\x08\x66rame_id\x18\x02 \x01(\x04\x12\x10\n\x08map_name\x18\x03 \x01(\t\x12.\n\x07weather\x18\x04 \x01(\x0b\x32\x1d.carla_driver.v0.CarlaWeather\x12=\n\x11\x65go_traffic_light\x18\x05 \x01(\x0e\x32\".carla_driver.v0.TrafficLightState\x12$\n\x1c\x65go_traffic_light_distance_m\x18\x06 \x01(\x02\x12\x17\n\x0fspeed_limit_mps\x18\x07 \x01(\x02\x12\x30\n\x06\x61\x63tors\x18\x08 \x03(\x0b\x32 .carla_driver.v0.CarlaActorState\x12*\n\x05lidar\x18\n \x03(\x0b\x32\x1b.carla_driver.v0.LidarSweep\x12\x0e\n\x06map_id\x18\x0b \x01(\t\x12\x35\n\x0etraffic_lights\x18\x0c \x03(\x0b\x32\x1d.carla_driver.v0.TrafficLightJ\x04\x08\t\x10\nR\x05lanes\"\x88\x01\n\x0cTrafficLight\x12\x14\n\x0copendrive_id\x18\x01 \x01(\t\x12\x31\n\x05state\x18\x02 \x01(\x0e\x32\".carla_driver.v0.TrafficLightState\x12/\n\x0bstop_points\x18\x03 \x03(\x0b\x32\x1a.carla_driver.v0.StopPoint\"g\n\tStopPoint\x12\x0f\n\x07road_id\x18\x01 \x01(\x05\x12\x12\n\nsection_id\x18\x02 \x01(\x05\x12\x0f\n\x07lane_id\x18\x03 \x01(\x05\x12$\n\x0eposition_local\x18\x04 \x01(\x0b\x32\x0c.common.Vec3\"\x83\x01\n\nLidarSweep\x12\x12\n\nlogical_id\x18\x01 \x01(\t\x12\x14\n\x0ctimestamp_us\x18\x02 \x01(\x06\x12\"\n\x0crig_to_lidar\x18\x03 \x01(\x0b\x32\x0c.common.Pose\x12\x12\n\nnum_points\x18\x04 \x01(\r\x12\x13\n\x0bpoints_xyzi\x18\x05 \x01(\x0c\"\xb9\x01\n\x13\x43\x61rlaDriveDebugInfo\x12\x13\n\x0bpolicy_name\x18\x01 \x01(\t\x12\x19\n\x11inference_seconds\x18\x02 \x01(\x02\x12\x42\n\x07scalars\x18\x03 \x03(\x0b\x32\x31.carla_driver.v0.CarlaDriveDebugInfo.ScalarsEntry\x1a.\n\x0cScalarsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\x01:\x02\x38\x01\"]\n\x0eVehicleCommand\x12\x13\n\x0btime_now_us\x18\x01 \x01(\x06\x12\x36\n\x0eturn_indicator\x18\x02 \x01(\x0e\x32\x1e.carla_driver.v0.TurnIndicator\"-\n\x15VehicleCommandRequest\x12\x14\n\x0csession_uuid\x18\x01 \x01(\t\"\x92\x02\n\x15\x43\x61rlaDriveSessionInfo\x12,\n\x04\x62\x61se\x18\x01 \x01(\x0b\x32\x1e.egodriver.DriveSessionRequest\x12\x10\n\x08map_name\x18\x02 \x01(\t\x12\x15\n\rscenario_name\x18\x03 \x01(\t\x12\x16\n\x0e\x66ixed_delta_us\x18\x04 \x01(\x06\x12\x1a\n\x12policy_timestep_us\x18\x05 \x01(\x06\x12\x1a\n\x12rear_axle_offset_m\x18\x06 \x01(\x02\x12R\n\x07\x63\x61meras\x18\x07 \x03(\x0b\x32\x41.nre.grpc.protos.sensorsim.AvailableCamerasReturn.AvailableCamera\"\x8d\x01\n\x0b\x43ompatEntry\x12\x0c\n\x04\x61rea\x18\x01 \x01(\t\x12\x19\n\x11\x61lpasim_behaviour\x18\x02 \x01(\t\x12\x17\n\x0f\x63\x61rla_behaviour\x18\x03 \x01(\t\x12+\n\x05level\x18\x04 \x01(\x0e\x32\x1c.carla_driver.v0.CompatLevel\x12\x0f\n\x07symbols\x18\x05 \x03(\t\"\xc4\x01\n\x11\x43\x61rlaCompatReport\x12&\n\x1e\x63\x61rla_driver_interface_version\x18\x01 \x01(\t\x12\x18\n\x10\x61lpasim_grpc_rev\x18\x02 \x01(\t\x12>\n\x18\x61lpasim_grpc_api_version\x18\x03 \x01(\x0b\x32\x1c.common.VersionId.APIVersion\x12-\n\x07\x65ntries\x18\x04 \x03(\x0b\x32\x1c.carla_driver.v0.CompatEntry*\xcb\x01\n\x11TrafficLightState\x12\x1f\n\x1bTRAFFIC_LIGHT_STATE_UNKNOWN\x10\x00\x12\x1c\n\x18TRAFFIC_LIGHT_STATE_NONE\x10\x01\x12\x1b\n\x17TRAFFIC_LIGHT_STATE_RED\x10\x02\x12\x1e\n\x1aTRAFFIC_LIGHT_STATE_YELLOW\x10\x03\x12\x1d\n\x19TRAFFIC_LIGHT_STATE_GREEN\x10\x04\x12\x1b\n\x17TRAFFIC_LIGHT_STATE_OFF\x10\x05*\x8b\x01\n\rTurnIndicator\x12\x1d\n\x19TURN_INDICATOR_NO_COMMAND\x10\x00\x12\x1a\n\x16TURN_INDICATOR_DISABLE\x10\x01\x12\x1e\n\x1aTURN_INDICATOR_ENABLE_LEFT\x10\x02\x12\x1f\n\x1bTURN_INDICATOR_ENABLE_RIGHT\x10\x03*\xb6\x01\n\x0b\x43ompatLevel\x12\x1c\n\x18\x43OMPAT_LEVEL_UNSPECIFIED\x10\x00\x12\x16\n\x12\x43OMPAT_LEVEL_EXACT\x10\x01\x12\x18\n\x14\x43OMPAT_LEVEL_PARTIAL\x10\x02\x12\x1b\n\x17\x43OMPAT_LEVEL_STRUCTURAL\x10\x03\x12\x1e\n\x1a\x43OMPAT_LEVEL_UNIMPLEMENTED\x10\x04\x12\x1a\n\x16\x43OMPAT_LEVEL_EXTENSION\x10\x05\x32u\n\x13\x43\x61rlaVehicleService\x12^\n\x13get_vehicle_command\x12&.carla_driver.v0.VehicleCommandRequest\x1a\x1f.carla_driver.v0.VehicleCommandb\x06proto3')
27
-
28
- _globals = globals()
29
- _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
30
- _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'carla_driver.v0.carla_driver_pb2', _globals)
31
- if _descriptor._USE_C_DESCRIPTORS == False:
32
- DESCRIPTOR._options = None
33
- _globals['_CARLADRIVEDEBUGINFO_SCALARSENTRY']._options = None
34
- _globals['_CARLADRIVEDEBUGINFO_SCALARSENTRY']._serialized_options = b'8\001'
35
- _globals['_TRAFFICLIGHTSTATE']._serialized_start=2300
36
- _globals['_TRAFFICLIGHTSTATE']._serialized_end=2503
37
- _globals['_TURNINDICATOR']._serialized_start=2506
38
- _globals['_TURNINDICATOR']._serialized_end=2645
39
- _globals['_COMPATLEVEL']._serialized_start=2648
40
- _globals['_COMPATLEVEL']._serialized_end=2830
41
- _globals['_CARLAWEATHER']._serialized_start=152
42
- _globals['_CARLAWEATHER']._serialized_end=358
43
- _globals['_CARLAACTORSTATE']._serialized_start=361
44
- _globals['_CARLAACTORSTATE']._serialized_end=528
45
- _globals['_CARLARENDERERDATA']._serialized_start=531
46
- _globals['_CARLARENDERERDATA']._serialized_end=969
47
- _globals['_TRAFFICLIGHT']._serialized_start=972
48
- _globals['_TRAFFICLIGHT']._serialized_end=1108
49
- _globals['_STOPPOINT']._serialized_start=1110
50
- _globals['_STOPPOINT']._serialized_end=1213
51
- _globals['_LIDARSWEEP']._serialized_start=1216
52
- _globals['_LIDARSWEEP']._serialized_end=1347
53
- _globals['_CARLADRIVEDEBUGINFO']._serialized_start=1350
54
- _globals['_CARLADRIVEDEBUGINFO']._serialized_end=1535
55
- _globals['_CARLADRIVEDEBUGINFO_SCALARSENTRY']._serialized_start=1489
56
- _globals['_CARLADRIVEDEBUGINFO_SCALARSENTRY']._serialized_end=1535
57
- _globals['_VEHICLECOMMAND']._serialized_start=1537
58
- _globals['_VEHICLECOMMAND']._serialized_end=1630
59
- _globals['_VEHICLECOMMANDREQUEST']._serialized_start=1632
60
- _globals['_VEHICLECOMMANDREQUEST']._serialized_end=1677
61
- _globals['_CARLADRIVESESSIONINFO']._serialized_start=1680
62
- _globals['_CARLADRIVESESSIONINFO']._serialized_end=1954
63
- _globals['_COMPATENTRY']._serialized_start=1957
64
- _globals['_COMPATENTRY']._serialized_end=2098
65
- _globals['_CARLACOMPATREPORT']._serialized_start=2101
66
- _globals['_CARLACOMPATREPORT']._serialized_end=2297
67
- _globals['_CARLAVEHICLESERVICE']._serialized_start=2832
68
- _globals['_CARLAVEHICLESERVICE']._serialized_end=2949
69
- # @@protoc_insertion_point(module_scope)