Generate CARLA blueprints dynamically#401
Generate CARLA blueprints dynamically#401lola831 wants to merge 7 commits intoBerkeleyLearnVerify:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #401 +/- ##
==========================================
- Coverage 89.70% 89.65% -0.06%
==========================================
Files 48 48
Lines 13190 13190
==========================================
- Hits 11832 11825 -7
- Misses 1358 1365 +7 🚀 New features to boost your workflow:
|
get dimensions for all blueprints fallback for 0.9.14 0.0 dims bug hard-code blueprint vehs with no base_type
| defaultWidth (float): Default width to use if Scenic has no recorded dimensions for this blueprint. | ||
| defaultLength (float): Default length to use if Scenic has no recorded dimensions for this blueprint. | ||
| defaultHeight (float): Default height to use if Scenic has no recorded dimensions for this blueprint. | ||
| width (float): Width for this blueprint; uses Scenic's recorded dimensions when available, otherwise ``defaultWidth``. |
There was a problem hiding this comment.
| width (float): Width for this blueprint; uses Scenic's recorded dimensions when available, otherwise ``defaultWidth``. | |
| width (float): Width for this object; uses the value from ``blueprint`` when available, otherwise ``defaultWidth``. |
Ditto for length and height.
There was a problem hiding this comment.
Updated docstrings for width/length/height as suggested.
tools/carla/make_blueprints.py
Outdated
| dims = _pick(_DIMS, _CARLA_VER) | ||
|
|
||
|
|
||
| def any_in(category): |
There was a problem hiding this comment.
I think this name is confusing. How about something like blueprintsInCategory?
There was a problem hiding this comment.
Renamed to blueprintsInCategory
| """A pedestrian. | ||
|
|
||
| The default ``blueprint`` (see `CarlaActor`) is a uniform distribution over the | ||
| blueprints listed in :obj:`scenic.simulators.carla.blueprints.walkerModels`. |
There was a problem hiding this comment.
Need to fix the docstring here, since the location of the blueprints has changed.
There was a problem hiding this comment.
Updated the Car and Pedestrian docstrings to reflect the new blueprintsInCategory
| class Bicycle(Vehicle): | ||
| width: 1 | ||
| length: 2 | ||
| blueprint: Uniform(*blueprints.bicycleModels) |
There was a problem hiding this comment.
For backwards compatibility, can we continue to define bicycleModels, etc. in the blueprints module? People might be using them, and they are documented. I think keeping those and also providing the new function to look up by the name of the category would make sense.
There was a problem hiding this comment.
Re-added the category lists (bicycleModels, etc.) to the blueprints module for backwards compatibility, and kept the new lookup helper.
tools/carla/make_blueprints.py
Outdated
| def load_versions(): | ||
| files = list(SNAPSHOT_DIR.glob(SNAPSHOT_PATTERN)) | ||
| if not files: | ||
| raise SystemExit("No input JSONs found.") |
There was a problem hiding this comment.
This looks odd to me. I'd just use sys.exit(), which does the same thing.
There was a problem hiding this comment.
Changed this to use sys.exit().
tools/carla/make_blueprints.py
Outdated
| for jf in files: | ||
| obj = json.loads(jf.read_text(encoding="utf-8")) | ||
| ver = str(obj["server_version"]) | ||
| entries.append((ver, {"ids": obj.get("ids", {}), "dims": obj.get("dims", {})})) |
There was a problem hiding this comment.
Why the get()s here? Aren't the files malformed if either key is missing?
There was a problem hiding this comment.
Good point. These snapshot files should always include both "ids" and "dims" so I switched to direct indexing instead of get().
tools/carla/snapshot_blueprints.py
Outdated
| "dims": dims, | ||
| } | ||
| out_path = SNAPSHOT_DIR / f"blueprints_{server_version}.json" | ||
| with open(out_path, "w", encoding="utf-8") as f: |
There was a problem hiding this comment.
Since these will sit around every time someone clones the repo, let's compress them (if we need to inspect the files for debugging, it's easy enough to double-click on them). You can just use gzip.open here and in make_blueprints.py.
There was a problem hiding this comment.
Snapshots are now written and read via gzip.open (blueprints_*.json.gz).
dfremont
left a comment
There was a problem hiding this comment.
Looks good in general. Besides some minor comments above, my only suggestion is that since blueprints.py is now very long and difficult to read, let's try splitting it into two files. The non-autogenerated part can stay in blueprints.py, but let's move the giant _IDS and _DIMS dictionaries into a separate _blueprintData.py module and then do from _blueprintData import _IDS, _DIMS. The make_blueprints.py script can then just generate _blueprintData.py.
|
@dfremont Thanks for the review. I split out |
Description
This PR generates CARLA blueprints dynamically (per CARLA version).
-
snapshot_blueprints.py: connects to CARLA, collects blueprint IDs and bounding-box dimensions for the running server version, categorizes them for Scenic, and writestools/carla/snapshots/blueprints_<VERSION>.json.-
make_blueprints.py: reads all snapshot JSONs, sorts/normalizes them, and regeneratessrc/scenic/simulators/carla/blueprints.py.-Generated
blueprints.py: selects the best-matching snapshot for the installed CARLA version and exposes ids, dims, and helper functions.-Handles versions that lack certain categories (e.g., CARLA 0.10.0 has no bicycles).
-Uses measured dimensions when available; otherwise falls back to defaults.
-Adds
vanModelsandbusModelscategories based on CARLA’sbase_type.Issue Link
N/A
Checklist
pytestand/or other meansAdditional Notes
N/A