-
Notifications
You must be signed in to change notification settings - Fork 63
Add Python script for updating field dimensions across the project #1079
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
Merged
shueja
merged 3 commits into
SleipnirGroup:main
from
shueja:auto-update-field-dimensions
Dec 31, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Auto-generated by update_field_dimensions.py | ||
| FIELD_LENGTH = 16.5811 | ||
| FIELD_WIDTH = 8.19912 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // Copyright (c) Choreo contributors | ||
|
|
||
| // Auto-generated by update_field_dimensions.py | ||
| package choreo.util; | ||
|
|
||
| class FieldDimensions { | ||
| static final double FIELD_LENGTH = 16.5811; | ||
| static final double FIELD_WIDTH = 8.19912; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
choreolib/src/main/native/include/choreo/util/FieldDimensions.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Copyright (c) Choreo contributors | ||
|
|
||
| // Auto-generated by update_field_dimensions.py | ||
| #pragma once | ||
| #include <units/length.h> | ||
|
|
||
| namespace choreo::util { | ||
| static constexpr units::meter_t fieldLength = 16.5811_m; | ||
| static constexpr units::meter_t fieldWidth = 8.19912_m; | ||
| } // namespace choreo::util |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| // Auto-generated by update_field_dimensions.py | ||
| export const FIELD_LENGTH = 16.5811; | ||
| export const FIELD_WIDTH = 8.19912; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| """ | ||
| A utility script to update the field dimensions in multiple files. | ||
|
|
||
| simply run `python update_field_dimensions.py <length_meters> <width_meters>` to update the dimensions in the files. | ||
| """ | ||
|
|
||
| from dataclasses import dataclass | ||
| from pathlib import Path | ||
| from typing import Callable | ||
|
|
||
|
|
||
| @dataclass(frozen=True, slots=True) | ||
| class Location: | ||
| relative_path: Path | ||
| # length, width | ||
| template: Callable[[float, float], str] | ||
|
|
||
|
|
||
| LOCATIONS: list[Location] = [ | ||
| # Choreo GUI | ||
| Location( | ||
| relative_path=Path("src/components/field/svg/fields/FieldDimensions.tsx"), | ||
| template=lambda length, width: f"""// Auto-generated by update_field_dimensions.py | ||
| export const FIELD_LENGTH = {length}; | ||
| export const FIELD_WIDTH = {width};""", | ||
| ), | ||
| # Java ChoreoLib | ||
| Location( | ||
| relative_path=Path("choreolib/src/main/java/choreo/util/FieldDimensions.java"), | ||
| template=lambda length, width: f"""// Copyright (c) Choreo contributors | ||
|
|
||
| // Auto-generated by update_field_dimensions.py | ||
| package choreo.util; | ||
|
|
||
| class FieldDimensions {{ | ||
| static final double FIELD_LENGTH = {length}; | ||
| static final double FIELD_WIDTH = {width}; | ||
| }}""", | ||
| ), | ||
| # Python ChoreoLib | ||
| Location( | ||
| relative_path=Path("choreolib/py/choreo/util/field_dimensions.py"), | ||
| template=lambda length, width: f"""# Auto-generated by update_field_dimensions.py | ||
| FIELD_LENGTH = {length} | ||
| FIELD_WIDTH = {width}""", | ||
| ), | ||
| # C++ ChoreoLib | ||
| Location( | ||
| relative_path=Path( | ||
| "choreolib/src/main/native/include/choreo/util/FieldDimensions.h" | ||
| ), | ||
| template=lambda length, width: f"""// Copyright (c) Choreo contributors | ||
|
|
||
| // Auto-generated by update_field_dimensions.py | ||
| #pragma once | ||
| #include <units/length.h> | ||
|
|
||
| namespace choreo::util {{ | ||
| static constexpr units::meter_t fieldLength = {length}_m; | ||
| static constexpr units::meter_t fieldWidth = {width}_m; | ||
| }} // namespace choreo::util""", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| def update_version(length: float, width: float) -> None: | ||
|
|
||
| for location in LOCATIONS: | ||
| file_path = Path(__file__).parent / location.relative_path | ||
|
|
||
| with open(file_path, "w") as f: | ||
| f.write(location.template(length, width)) | ||
| f.write("\n") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| import argparse | ||
|
|
||
| parser = argparse.ArgumentParser(description="Update version in files") | ||
| parser.add_argument("length_m", type=float, help="Field length in meters") | ||
| parser.add_argument("width_m", type=float, help="Field width in meters") | ||
| args = parser.parse_args() | ||
| update_version(args.length_m, args.width_m) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
These should be used for the field keep in constraint
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.
The keep-in constraint will derive its values from this file. That's part of the near-future PR mentioned above.