-
Notifications
You must be signed in to change notification settings - Fork 135
Generate CARLA blueprints dynamically #401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Generate CARLA blueprints dynamically #401
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #401 +/- ##
==========================================
+ Coverage 89.85% 89.89% +0.04%
==========================================
Files 54 54
Lines 13549 13556 +7
==========================================
+ Hits 12174 12186 +12
+ Misses 1375 1370 -5 🚀 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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.
| dims = _pick(_DIMS, _CARLA_VER) | ||
| def any_in(category): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this name is confusing. How about something like blueprintsInCategory?
| from scenic.domains.driving.model import * | ||
|
|
||
| import scenic.simulators.carla.blueprints as blueprints | ||
| import scenic.simulators.carla.blueprints as bp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the old blueprints is more understandable.
| """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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to fix the docstring here, since the location of the blueprints has changed.
| class Bicycle(Vehicle): | ||
| width: 1 | ||
| length: 2 | ||
| blueprint: Uniform(*blueprints.bicycleModels) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks odd to me. I'd just use sys.exit(), which does the same thing.
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the get()s here? Aren't the files malformed if either key is missing?
| "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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
dfremont
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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