carla-driver-interface 1.0.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 (29) hide show
  1. carla_driver_interface-1.0.0/LICENSE +202 -0
  2. carla_driver_interface-1.0.0/PKG-INFO +209 -0
  3. carla_driver_interface-1.0.0/README.md +193 -0
  4. carla_driver_interface-1.0.0/pyproject.toml +58 -0
  5. carla_driver_interface-1.0.0/pyproject.toml.orig +70 -0
  6. carla_driver_interface-1.0.0/src/carla_driver_interface/__init__.py +28 -0
  7. carla_driver_interface-1.0.0/src/carla_driver_interface/_proto/__init__.py +5 -0
  8. carla_driver_interface-1.0.0/src/carla_driver_interface/_proto/carla_driver_pb2.py +61 -0
  9. carla_driver_interface-1.0.0/src/carla_driver_interface/_proto/carla_driver_pb2.pyi +203 -0
  10. carla_driver_interface-1.0.0/src/carla_driver_interface/_proto/common_pb2.py +56 -0
  11. carla_driver_interface-1.0.0/src/carla_driver_interface/_proto/common_pb2.pyi +121 -0
  12. carla_driver_interface-1.0.0/src/carla_driver_interface/_proto/egodriver_pb2.py +66 -0
  13. carla_driver_interface-1.0.0/src/carla_driver_interface/_proto/egodriver_pb2.pyi +144 -0
  14. carla_driver_interface-1.0.0/src/carla_driver_interface/_proto/egodriver_pb2_grpc.py +304 -0
  15. carla_driver_interface-1.0.0/src/carla_driver_interface/_proto/sensorsim_pb2.py +105 -0
  16. carla_driver_interface-1.0.0/src/carla_driver_interface/_proto/sensorsim_pb2.pyi +376 -0
  17. carla_driver_interface-1.0.0/src/carla_driver_interface/cli.py +79 -0
  18. carla_driver_interface-1.0.0/src/carla_driver_interface/driver.py +254 -0
  19. carla_driver_interface-1.0.0/src/carla_driver_interface/geometry.py +322 -0
  20. carla_driver_interface-1.0.0/src/carla_driver_interface/hdmap.py +189 -0
  21. carla_driver_interface-1.0.0/src/carla_driver_interface/policies/__init__.py +62 -0
  22. carla_driver_interface-1.0.0/src/carla_driver_interface/policies/constant_speed.py +48 -0
  23. carla_driver_interface-1.0.0/src/carla_driver_interface/policies/route_follower.py +197 -0
  24. carla_driver_interface-1.0.0/src/carla_driver_interface/polyline.py +120 -0
  25. carla_driver_interface-1.0.0/src/carla_driver_interface/protocol.py +201 -0
  26. carla_driver_interface-1.0.0/src/carla_driver_interface/py.typed +0 -0
  27. carla_driver_interface-1.0.0/src/carla_driver_interface/server.py +73 -0
  28. carla_driver_interface-1.0.0/src/carla_driver_interface/service.py +324 -0
  29. carla_driver_interface-1.0.0/src/carla_driver_interface/testing.py +316 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,209 @@
1
+ Metadata-Version: 2.4
2
+ Name: carla-driver-interface
3
+ Version: 1.0.0
4
+ Summary: Both ends of alpasim's egodriver gRPC contract: serve a driving policy, or drive one without CARLA
5
+ Author: Masaya Kataoka
6
+ Author-email: Masaya Kataoka <ms.kataoka@gmail.com>
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ Requires-Dist: grpcio>=1.60
10
+ Requires-Dist: protobuf>=4.25.0,<8
11
+ Requires-Dist: numpy>=1.21
12
+ Requires-Dist: scipy>=1.8
13
+ Requires-Dist: pillow>=10.0
14
+ Requires-Python: >=3.10, <3.15
15
+ Description-Content-Type: text/markdown
16
+
17
+ # carla-driver-interface
18
+
19
+ Both ends of [NVlabs/alpasim](https://github.com/NVlabs/alpasim)'s
20
+ `egodriver.EgodriverService` gRPC contract, light enough for a driving policy to depend on:
21
+
22
+ - **policy side**: implement `BaseDriver.drive()` and serve it with `run_server()` /
23
+ `serving()` (or `carla-driver-interface serve --policy route_follower`, or any
24
+ `package.module:Class` through `load_policy()`); session bookkeeping, frame retention,
25
+ ego history and the rig/local conversion are handled for you;
26
+ - **a CARLA-free runtime** for tests: `testing.FakeLoop` drives any policy server over
27
+ real gRPC on a straight road, rendering each declared pinhole camera
28
+ (`carla-driver-interface demo --driver localhost:50051`).
29
+
30
+ The CARLA runtime lives in
31
+ [autoware_carla_scenario](https://github.com/autowarefoundation/autoware_carla_scenario):
32
+ with `ego.entity=carla_driver` it drives the same policy server inside a scenario. An
33
+ upstream alpasim runtime drives it too — nothing about the alpasim wire format is changed.
34
+
35
+ ## Install
36
+
37
+ ```console
38
+ $ pip install carla-driver-interface
39
+ ```
40
+
41
+ Python 3.10–3.14. Dependencies: grpcio, protobuf (4.25+), numpy, scipy, Pillow. No CARLA,
42
+ no alpasim distribution: the wire contract is vendored ([`proto/README.md`](https://github.com/hakuturu583/carla_driver_interface/blob/main/proto/README.md))
43
+ with field numbers and service names unchanged.
44
+
45
+ ## Writing a policy
46
+
47
+ ```python
48
+ from carla_driver_interface.driver import BaseDriver, DriveContext, DriveResult
49
+ from carla_driver_interface.geometry import Pose, Trajectory
50
+ from carla_driver_interface.server import run_server
51
+
52
+
53
+ class MyPolicy(BaseDriver):
54
+ name = "my_policy"
55
+
56
+ def drive(self, ctx: DriveContext) -> DriveResult:
57
+ frame = ctx.session.latest_frame("camera_front") # .as_array() -> RGB
58
+ plan = Trajectory.empty()
59
+ for i in range(1, 41): # 4 s ahead, in the rig frame (x forward, y left)
60
+ plan.append(
61
+ ctx.time_now_us + i * 100_000, Pose.from_xyz_yaw(0.5 * i, 0.0, 0.0, 0.0)
62
+ )
63
+ return DriveResult(trajectory_in_rig=plan)
64
+
65
+
66
+ run_server(MyPolicy(), port=50051)
67
+ ```
68
+
69
+ Every sensor reaches a policy the same way: as a frame in `session.frame_history`
70
+ (`CameraFrame`, `LidarFrame`), announced through `on_frame`, each with `as_array()`.
71
+ Beyond alpasim's cameras, a policy run by autoware_carla_scenario gets LiDAR sweeps (rig
72
+ frame) that way and, with `map_dir` set to its copy of the runtime's `driver.map_dir`, the
73
+ world's map as files (`ctx.map`) and every traffic light resolved into that map's own
74
+ elements (`ctx.stop_lines()`, `carla_driver_interface.hdmap`). CARLA ground truth arrives
75
+ in `ctx.renderer_data` (`None` when an alpasim runtime drives the policy).
76
+
77
+ ## Testing a policy without CARLA
78
+
79
+ ```console
80
+ $ carla-driver-interface serve --policy route_follower --port 50051 &
81
+ $ carla-driver-interface demo --driver localhost:50051 --steps 200
82
+ ```
83
+
84
+ or, in a test, `FakeLoop("localhost:50051", [FakeCamera()])` from
85
+ `carla_driver_interface.testing` (a context manager; `.run(steps)` returns a
86
+ `LoopResult`). The ego follows the returned plan exactly, so what is tested is the policy
87
+ and the wire, not a controller.
88
+
89
+ ## Successor to carla-driver-interface 0.1.0
90
+
91
+ This package replaces the previous `carla-driver-interface` 0.1.0 of this repository,
92
+ which had two halves: a driver built on the `alpasim-grpc` distribution (Python 3.11–3.12
93
+ only), and a CARLA runtime (`CarlaRuntime`, `CarlaWorldAdapter`, `FakeWorld`,
94
+ `carla-driver-interface run`). From 1.0.0:
95
+
96
+ - the **driver half** is this package. It was developed as `autoware-carla-egodriver`, a
97
+ workspace member of autoware_carla_scenario, and moves here under the old name so
98
+ policies and scenario packages version independently;
99
+ - the **runtime half** is autoware_carla_scenario's `ego.entity=carla_driver`, which owns
100
+ the CARLA world, the ego and the traffic, and drives the policy over the same contract.
101
+ `testing.FakeLoop` replaces `FakeWorld` for CARLA-free tests.
102
+
103
+ ### Migrating from 0.1.0
104
+
105
+ Policies port by changing imports; `BaseDriver`, `DriveContext`, `DriveResult`,
106
+ `SessionState`, `CameraFrame`, `Pose` and `Trajectory` keep their names and fields.
107
+
108
+ | 0.1.0 | 1.0.0 |
109
+ | --- | --- |
110
+ | `carla_driver_interface.driver.base` (`BaseDriver`, `DriveContext`, ...) | `carla_driver_interface.driver` |
111
+ | `carla_driver_interface.driver.server` (`run_server`, `serving`, `build_server`) | `carla_driver_interface.server` |
112
+ | `carla_driver_interface.driver.service.CarlaEgodriverServicer` | `carla_driver_interface.service.EgodriverServicer` |
113
+ | `carla_driver_interface.driver.policies` | `carla_driver_interface.policies` (plus `load_policy`) |
114
+ | `carla_driver_interface.grpc_api` (messages, stubs) | `carla_driver_interface.protocol` |
115
+ | `carla_driver_interface.grpc_api.extension` (`pack_renderer_data`, `unpack_debug_info`, ...) | `carla_driver_interface.protocol` |
116
+ | `carla_driver_interface.grpc_api.API_VERSION_MESSAGE` | `carla_driver_interface.protocol.ALPASIM_API_VERSION` |
117
+ | `alpasim_grpc.v0.{common,egodriver,sensorsim}_pb2` | `carla_driver_interface.protocol.{common,egodriver,sensorsim,carla_driver}_pb2` |
118
+ | `carla_driver_interface.geometry` (`Pose`, `Trajectory`), `.polyline` | unchanged |
119
+ | `geometry.quat_mul`, `yaw_to_quat_xyzw`, `quat_to_yaw`, ... | `Pose` methods, or `scipy.spatial.transform.Rotation` |
120
+ | `BaseDriver.on_image(session, frame)` | `BaseDriver.on_frame(session, frame)` (cameras and LiDAR) |
121
+ | `carla_driver_interface.fakes.FakeWorld` | `carla_driver_interface.testing.FakeLoop` |
122
+ | `carla_driver_interface.runtime` (`CarlaRuntime`, ...), `carla-driver-interface run` | autoware_carla_scenario, `ego.entity=carla_driver` |
123
+ | `carla_driver_interface.compat`, `carla-driver-interface compat-report` | removed |
124
+
125
+ `alpasim_grpc.v0.runtime_pb2` (`RolloutSpec`, `SimulationReturn`, ...) is not vendored: it
126
+ is the runtime's own contract, not the egodriver one. Messages not re-exported by name in
127
+ `protocol` (`CarlaDriveSessionInfo`, `CarlaCompatReport`, ...) remain available from
128
+ `protocol.carla_driver_pb2`.
129
+
130
+ ## Versioning
131
+
132
+ carla-driver-interface follows [semantic versioning](https://semver.org) on its own,
133
+ independently of autoware_carla_scenario or any policy. The compatibility unit is the gRPC
134
+ wire contract (`proto/`): any 1.x policy server and any runtime built against 1.x
135
+ interoperate, so depend on it with a range (`carla-driver-interface>=1.0,<2`), not an
136
+ exact pin.
137
+
138
+ - **patch**: fixes that change neither the wire nor the Python API;
139
+ - **minor**: additions — new fields or messages in the `carla_driver` extension (old peers
140
+ ignore them), new Python API;
141
+ - **major**: anything that breaks a peer or a policy — a changed or removed field number,
142
+ a renamed service, a removed Python API.
143
+
144
+ The vendored alpasim contract is never edited; following a newer alpasim revision is a
145
+ minor release when it is wire-compatible and a major one when it is not.
146
+
147
+ ## Development
148
+
149
+ ```console
150
+ $ uv sync --group dev
151
+ $ uv run ruff check . && uv run ruff format --check .
152
+ $ uv run mypy src tests scripts
153
+ $ uv run pytest -q
154
+ ```
155
+
156
+ The generated protobuf modules in `src/carla_driver_interface/_proto` are committed;
157
+ regenerate them with `uv run python scripts/compile_protos.py` (on Python 3.10–3.12, see
158
+ [`proto/README.md`](https://github.com/hakuturu583/carla_driver_interface/blob/main/proto/README.md)). `--check`, also run by the test suite, verifies
159
+ they are current.
160
+
161
+ ## Releasing
162
+
163
+ Releases are cut by merging, and go to
164
+ [PyPI](https://pypi.org/project/carla-driver-interface/) from
165
+ [`.github/workflows/release.yml`](https://github.com/hakuturu583/carla_driver_interface/blob/main/.github/workflows/release.yml)
166
+ through Trusted Publishing — no API token is stored anywhere.
167
+
168
+ **Every PR carries exactly one of the labels `bump patch`, `bump minor` or `bump major`**
169
+ (the *Check Version Bump Label* check fails otherwise), chosen by the
170
+ [versioning](#versioning) rules above. Do not edit `version` in `pyproject.toml` by hand.
171
+ When the PR is merged to `main`, the release workflow:
172
+
173
+ 1. bumps `version` in `pyproject.toml` by the label, re-locks (`uv lock`) and pushes the
174
+ commit `chore: bump version to X.Y.Z` to `main`;
175
+ 2. tags it `vX.Y.Z` and creates the GitHub Release;
176
+ 3. builds the sdist and wheel (`uv build`), checks them with `twine check --strict`,
177
+ installs the wheel into a clean virtual environment on every supported Python
178
+ (3.10–3.14) and runs `carla-driver-interface --help`;
179
+ 4. publishes to PyPI.
180
+
181
+ A merge without a bump label releases nothing.
182
+
183
+ **Re-running a failed release.** If a step after the bump failed (the tag, the Release,
184
+ PyPI), do not re-run the push run — it would bump again. Run the workflow by hand instead
185
+ (Actions → Release → Run workflow, on `main`) with the `version` it bumped to, e.g.
186
+ `1.2.3`. It builds from that version's tag, or else from its
187
+ `chore: bump version to 1.2.3` commit, never from a later `main`, and reuses an existing
188
+ tag or Release; files already on PyPI are skipped.
189
+
190
+ The successor keeps the predecessor's version line: it starts from 0.1.0, and the PR
191
+ that introduces it is merged with `bump major`, which releases 1.0.0 like any other
192
+ release.
193
+
194
+ **Pushing to `main`.** The bump commit and the tag are pushed with `GITHUB_TOKEN`, which
195
+ works while `main` has no branch protection rules. If `main` gets a ruleset whose bypass
196
+ list does not include `github-actions[bot]`, add a `GH_PAT` repository secret (a token
197
+ that may push to `main` and create tags); the workflow uses it whenever it exists.
198
+
199
+ **One-time PyPI setup.** PyPI needs a (pending) trusted publisher for the project
200
+ `carla-driver-interface` (the distribution name in `pyproject.toml`) with owner
201
+ `hakuturu583`, repository `carla_driver_interface`, workflow `release.yml` and environment
202
+ `pypi` (PyPI → Your account → Publishing), and this repository needs a `pypi` environment
203
+ (Settings → Environments). Until then the publish job fails and the built distributions
204
+ remain available as the run's `pypi-dist` artifact.
205
+
206
+ ## License
207
+
208
+ Apache-2.0. The vendored alpasim protos are Apache-2.0 as well
209
+ ([`proto/LICENSE.alpasim`](https://github.com/hakuturu583/carla_driver_interface/blob/main/proto/LICENSE.alpasim)).
@@ -0,0 +1,193 @@
1
+ # carla-driver-interface
2
+
3
+ Both ends of [NVlabs/alpasim](https://github.com/NVlabs/alpasim)'s
4
+ `egodriver.EgodriverService` gRPC contract, light enough for a driving policy to depend on:
5
+
6
+ - **policy side**: implement `BaseDriver.drive()` and serve it with `run_server()` /
7
+ `serving()` (or `carla-driver-interface serve --policy route_follower`, or any
8
+ `package.module:Class` through `load_policy()`); session bookkeeping, frame retention,
9
+ ego history and the rig/local conversion are handled for you;
10
+ - **a CARLA-free runtime** for tests: `testing.FakeLoop` drives any policy server over
11
+ real gRPC on a straight road, rendering each declared pinhole camera
12
+ (`carla-driver-interface demo --driver localhost:50051`).
13
+
14
+ The CARLA runtime lives in
15
+ [autoware_carla_scenario](https://github.com/autowarefoundation/autoware_carla_scenario):
16
+ with `ego.entity=carla_driver` it drives the same policy server inside a scenario. An
17
+ upstream alpasim runtime drives it too — nothing about the alpasim wire format is changed.
18
+
19
+ ## Install
20
+
21
+ ```console
22
+ $ pip install carla-driver-interface
23
+ ```
24
+
25
+ Python 3.10–3.14. Dependencies: grpcio, protobuf (4.25+), numpy, scipy, Pillow. No CARLA,
26
+ no alpasim distribution: the wire contract is vendored ([`proto/README.md`](https://github.com/hakuturu583/carla_driver_interface/blob/main/proto/README.md))
27
+ with field numbers and service names unchanged.
28
+
29
+ ## Writing a policy
30
+
31
+ ```python
32
+ from carla_driver_interface.driver import BaseDriver, DriveContext, DriveResult
33
+ from carla_driver_interface.geometry import Pose, Trajectory
34
+ from carla_driver_interface.server import run_server
35
+
36
+
37
+ class MyPolicy(BaseDriver):
38
+ name = "my_policy"
39
+
40
+ def drive(self, ctx: DriveContext) -> DriveResult:
41
+ frame = ctx.session.latest_frame("camera_front") # .as_array() -> RGB
42
+ plan = Trajectory.empty()
43
+ for i in range(1, 41): # 4 s ahead, in the rig frame (x forward, y left)
44
+ plan.append(
45
+ ctx.time_now_us + i * 100_000, Pose.from_xyz_yaw(0.5 * i, 0.0, 0.0, 0.0)
46
+ )
47
+ return DriveResult(trajectory_in_rig=plan)
48
+
49
+
50
+ run_server(MyPolicy(), port=50051)
51
+ ```
52
+
53
+ Every sensor reaches a policy the same way: as a frame in `session.frame_history`
54
+ (`CameraFrame`, `LidarFrame`), announced through `on_frame`, each with `as_array()`.
55
+ Beyond alpasim's cameras, a policy run by autoware_carla_scenario gets LiDAR sweeps (rig
56
+ frame) that way and, with `map_dir` set to its copy of the runtime's `driver.map_dir`, the
57
+ world's map as files (`ctx.map`) and every traffic light resolved into that map's own
58
+ elements (`ctx.stop_lines()`, `carla_driver_interface.hdmap`). CARLA ground truth arrives
59
+ in `ctx.renderer_data` (`None` when an alpasim runtime drives the policy).
60
+
61
+ ## Testing a policy without CARLA
62
+
63
+ ```console
64
+ $ carla-driver-interface serve --policy route_follower --port 50051 &
65
+ $ carla-driver-interface demo --driver localhost:50051 --steps 200
66
+ ```
67
+
68
+ or, in a test, `FakeLoop("localhost:50051", [FakeCamera()])` from
69
+ `carla_driver_interface.testing` (a context manager; `.run(steps)` returns a
70
+ `LoopResult`). The ego follows the returned plan exactly, so what is tested is the policy
71
+ and the wire, not a controller.
72
+
73
+ ## Successor to carla-driver-interface 0.1.0
74
+
75
+ This package replaces the previous `carla-driver-interface` 0.1.0 of this repository,
76
+ which had two halves: a driver built on the `alpasim-grpc` distribution (Python 3.11–3.12
77
+ only), and a CARLA runtime (`CarlaRuntime`, `CarlaWorldAdapter`, `FakeWorld`,
78
+ `carla-driver-interface run`). From 1.0.0:
79
+
80
+ - the **driver half** is this package. It was developed as `autoware-carla-egodriver`, a
81
+ workspace member of autoware_carla_scenario, and moves here under the old name so
82
+ policies and scenario packages version independently;
83
+ - the **runtime half** is autoware_carla_scenario's `ego.entity=carla_driver`, which owns
84
+ the CARLA world, the ego and the traffic, and drives the policy over the same contract.
85
+ `testing.FakeLoop` replaces `FakeWorld` for CARLA-free tests.
86
+
87
+ ### Migrating from 0.1.0
88
+
89
+ Policies port by changing imports; `BaseDriver`, `DriveContext`, `DriveResult`,
90
+ `SessionState`, `CameraFrame`, `Pose` and `Trajectory` keep their names and fields.
91
+
92
+ | 0.1.0 | 1.0.0 |
93
+ | --- | --- |
94
+ | `carla_driver_interface.driver.base` (`BaseDriver`, `DriveContext`, ...) | `carla_driver_interface.driver` |
95
+ | `carla_driver_interface.driver.server` (`run_server`, `serving`, `build_server`) | `carla_driver_interface.server` |
96
+ | `carla_driver_interface.driver.service.CarlaEgodriverServicer` | `carla_driver_interface.service.EgodriverServicer` |
97
+ | `carla_driver_interface.driver.policies` | `carla_driver_interface.policies` (plus `load_policy`) |
98
+ | `carla_driver_interface.grpc_api` (messages, stubs) | `carla_driver_interface.protocol` |
99
+ | `carla_driver_interface.grpc_api.extension` (`pack_renderer_data`, `unpack_debug_info`, ...) | `carla_driver_interface.protocol` |
100
+ | `carla_driver_interface.grpc_api.API_VERSION_MESSAGE` | `carla_driver_interface.protocol.ALPASIM_API_VERSION` |
101
+ | `alpasim_grpc.v0.{common,egodriver,sensorsim}_pb2` | `carla_driver_interface.protocol.{common,egodriver,sensorsim,carla_driver}_pb2` |
102
+ | `carla_driver_interface.geometry` (`Pose`, `Trajectory`), `.polyline` | unchanged |
103
+ | `geometry.quat_mul`, `yaw_to_quat_xyzw`, `quat_to_yaw`, ... | `Pose` methods, or `scipy.spatial.transform.Rotation` |
104
+ | `BaseDriver.on_image(session, frame)` | `BaseDriver.on_frame(session, frame)` (cameras and LiDAR) |
105
+ | `carla_driver_interface.fakes.FakeWorld` | `carla_driver_interface.testing.FakeLoop` |
106
+ | `carla_driver_interface.runtime` (`CarlaRuntime`, ...), `carla-driver-interface run` | autoware_carla_scenario, `ego.entity=carla_driver` |
107
+ | `carla_driver_interface.compat`, `carla-driver-interface compat-report` | removed |
108
+
109
+ `alpasim_grpc.v0.runtime_pb2` (`RolloutSpec`, `SimulationReturn`, ...) is not vendored: it
110
+ is the runtime's own contract, not the egodriver one. Messages not re-exported by name in
111
+ `protocol` (`CarlaDriveSessionInfo`, `CarlaCompatReport`, ...) remain available from
112
+ `protocol.carla_driver_pb2`.
113
+
114
+ ## Versioning
115
+
116
+ carla-driver-interface follows [semantic versioning](https://semver.org) on its own,
117
+ independently of autoware_carla_scenario or any policy. The compatibility unit is the gRPC
118
+ wire contract (`proto/`): any 1.x policy server and any runtime built against 1.x
119
+ interoperate, so depend on it with a range (`carla-driver-interface>=1.0,<2`), not an
120
+ exact pin.
121
+
122
+ - **patch**: fixes that change neither the wire nor the Python API;
123
+ - **minor**: additions — new fields or messages in the `carla_driver` extension (old peers
124
+ ignore them), new Python API;
125
+ - **major**: anything that breaks a peer or a policy — a changed or removed field number,
126
+ a renamed service, a removed Python API.
127
+
128
+ The vendored alpasim contract is never edited; following a newer alpasim revision is a
129
+ minor release when it is wire-compatible and a major one when it is not.
130
+
131
+ ## Development
132
+
133
+ ```console
134
+ $ uv sync --group dev
135
+ $ uv run ruff check . && uv run ruff format --check .
136
+ $ uv run mypy src tests scripts
137
+ $ uv run pytest -q
138
+ ```
139
+
140
+ The generated protobuf modules in `src/carla_driver_interface/_proto` are committed;
141
+ regenerate them with `uv run python scripts/compile_protos.py` (on Python 3.10–3.12, see
142
+ [`proto/README.md`](https://github.com/hakuturu583/carla_driver_interface/blob/main/proto/README.md)). `--check`, also run by the test suite, verifies
143
+ they are current.
144
+
145
+ ## Releasing
146
+
147
+ Releases are cut by merging, and go to
148
+ [PyPI](https://pypi.org/project/carla-driver-interface/) from
149
+ [`.github/workflows/release.yml`](https://github.com/hakuturu583/carla_driver_interface/blob/main/.github/workflows/release.yml)
150
+ through Trusted Publishing — no API token is stored anywhere.
151
+
152
+ **Every PR carries exactly one of the labels `bump patch`, `bump minor` or `bump major`**
153
+ (the *Check Version Bump Label* check fails otherwise), chosen by the
154
+ [versioning](#versioning) rules above. Do not edit `version` in `pyproject.toml` by hand.
155
+ When the PR is merged to `main`, the release workflow:
156
+
157
+ 1. bumps `version` in `pyproject.toml` by the label, re-locks (`uv lock`) and pushes the
158
+ commit `chore: bump version to X.Y.Z` to `main`;
159
+ 2. tags it `vX.Y.Z` and creates the GitHub Release;
160
+ 3. builds the sdist and wheel (`uv build`), checks them with `twine check --strict`,
161
+ installs the wheel into a clean virtual environment on every supported Python
162
+ (3.10–3.14) and runs `carla-driver-interface --help`;
163
+ 4. publishes to PyPI.
164
+
165
+ A merge without a bump label releases nothing.
166
+
167
+ **Re-running a failed release.** If a step after the bump failed (the tag, the Release,
168
+ PyPI), do not re-run the push run — it would bump again. Run the workflow by hand instead
169
+ (Actions → Release → Run workflow, on `main`) with the `version` it bumped to, e.g.
170
+ `1.2.3`. It builds from that version's tag, or else from its
171
+ `chore: bump version to 1.2.3` commit, never from a later `main`, and reuses an existing
172
+ tag or Release; files already on PyPI are skipped.
173
+
174
+ The successor keeps the predecessor's version line: it starts from 0.1.0, and the PR
175
+ that introduces it is merged with `bump major`, which releases 1.0.0 like any other
176
+ release.
177
+
178
+ **Pushing to `main`.** The bump commit and the tag are pushed with `GITHUB_TOKEN`, which
179
+ works while `main` has no branch protection rules. If `main` gets a ruleset whose bypass
180
+ list does not include `github-actions[bot]`, add a `GH_PAT` repository secret (a token
181
+ that may push to `main` and create tags); the workflow uses it whenever it exists.
182
+
183
+ **One-time PyPI setup.** PyPI needs a (pending) trusted publisher for the project
184
+ `carla-driver-interface` (the distribution name in `pyproject.toml`) with owner
185
+ `hakuturu583`, repository `carla_driver_interface`, workflow `release.yml` and environment
186
+ `pypi` (PyPI → Your account → Publishing), and this repository needs a `pypi` environment
187
+ (Settings → Environments). Until then the publish job fails and the built distributions
188
+ remain available as the run's `pypi-dist` artifact.
189
+
190
+ ## License
191
+
192
+ Apache-2.0. The vendored alpasim protos are Apache-2.0 as well
193
+ ([`proto/LICENSE.alpasim`](https://github.com/hakuturu583/carla_driver_interface/blob/main/proto/LICENSE.alpasim)).
@@ -0,0 +1,58 @@
1
+ [project]
2
+ name = "carla-driver-interface"
3
+ version = "1.0.0"
4
+ description = "Both ends of alpasim's egodriver gRPC contract: serve a driving policy, or drive one without CARLA"
5
+ readme = "README.md"
6
+ license = "Apache-2.0"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.10,<3.15"
9
+ dependencies = [
10
+ "grpcio>=1.60",
11
+ "protobuf>=4.25.0,<8",
12
+ "numpy>=1.21",
13
+ "scipy>=1.8",
14
+ "pillow>=10.0",
15
+ ]
16
+
17
+ [[project.authors]]
18
+ name = "Masaya Kataoka"
19
+ email = "ms.kataoka@gmail.com"
20
+
21
+ [project.scripts]
22
+ carla-driver-interface = "carla_driver_interface.cli:main"
23
+
24
+ [build-system]
25
+ requires = ["uv_build>=0.9.7,<0.10.0"]
26
+ build-backend = "uv_build"
27
+
28
+ [dependency-groups]
29
+ dev = [
30
+ "grpcio-tools>=1.60,<1.63; python_version < '3.13'",
31
+ "protobuf>=5; python_version >= '3.13'",
32
+ "pytest>=8",
33
+ "ruff>=0.7",
34
+ "mypy>=1.11",
35
+ ]
36
+
37
+ [tool.ruff]
38
+ extend-exclude = ["**/_proto"]
39
+
40
+ [tool.ruff.lint]
41
+ select = [
42
+ "E4",
43
+ "E7",
44
+ "E9",
45
+ "F",
46
+ "I",
47
+ ]
48
+
49
+ [tool.mypy]
50
+ ignore_missing_imports = true
51
+ exclude = [".*/_proto/"]
52
+
53
+ [[tool.mypy.overrides]]
54
+ module = ["carla_driver_interface._proto.*"]
55
+ ignore_errors = true
56
+
57
+ [tool.pytest.ini_options]
58
+ testpaths = ["tests"]