forked from wpilibsuite/allwpilib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into remove-prefix-suffix
- Loading branch information
Showing
835 changed files
with
25,381 additions
and
10,260 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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,28 @@ | ||
# AprilTag | ||
|
||
## Adding new field to AprilTagFields | ||
|
||
### Adding field JSON | ||
|
||
1. Add a field layout CSV file to `src/main/native/resources/edu/wpi/first/apriltag` | ||
1. See docstring in `convert_apriltag_layouts.py` for more | ||
2. Run `convert_apriltag_layouts.py` in the same directory as this readme to generate the JSON | ||
3. That script overwrites all generated JSONs, so undo undesired changes if necessary | ||
4. Update the field dimensions at the bottom of the JSON | ||
1. Length should be in meters from alliance wall to alliance wall | ||
2. Width should be in meters from inside guardrail plastic to plastic | ||
|
||
### Java updates | ||
|
||
1. Update `src/main/java/edu/wpi/first/apriltag/AprilTagFields.java` | ||
1. Add enum value for new field to `AprilTagFields` | ||
2. Update `AprilTagFields.kDefaultField` if necessary | ||
|
||
### C++ updates | ||
|
||
1. Update `src/main/native/include/frc/apriltag/AprilTagFields.h` | ||
1. Add enum value for new field to `AprilTagFields` | ||
2. Update `AprilTagFields::kDefaultField` if necessary | ||
2. Update `src/main/native/cpp/AprilTagFields.cpp` | ||
1. Add resource getter prototype like `std::string_view GetResource_2024_crescendo_json()` | ||
2. Add case for new field to switch in `LoadAprilTagLayoutField()` |
This file contains 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,88 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
This script converts all AprilTag field layout CSV files in | ||
src/main/native/resources/edu/wpi/first/apriltag to the JSON format | ||
AprilTagFields expects. | ||
The input CSV has the following format: | ||
* Columns: ID, X, Y, Z, Rotation | ||
* ID is a positive integer | ||
* X, Y, and Z are decimal inches | ||
* Rotation is yaw in degrees | ||
The values come from a table in the layout marking diagram (e.g., | ||
https://firstfrc.blob.core.windows.net/frc2024/FieldAssets/2024LayoutMarkingDiagram.pdf). | ||
""" | ||
|
||
import csv | ||
import json | ||
import os | ||
|
||
from wpimath import geometry, units | ||
import numpy as np | ||
|
||
|
||
def main(): | ||
# Find AprilTag field layout CSVs | ||
filenames = [ | ||
os.path.join(dp, f) | ||
for dp, dn, fn in os.walk("src/main/native/resources/edu/wpi/first/apriltag") | ||
for f in fn | ||
if f.endswith(".csv") | ||
] | ||
|
||
for filename in filenames: | ||
json_data = {"tags": [], "field": {"length": 0.0, "width": 0.0}} | ||
|
||
# Read CSV and fill in JSON data | ||
with open(filename, newline="") as csvfile: | ||
reader = csv.reader(csvfile, delimiter=",") | ||
|
||
# Skip header | ||
next(reader) | ||
|
||
for row in reader: | ||
# Unpack row elements | ||
id = int(row[0]) | ||
x = float(row[1]) | ||
y = float(row[2]) | ||
z = float(row[3]) | ||
rotation = float(row[4]) | ||
|
||
# Turn yaw into quaternion | ||
q = geometry.Rotation3d( | ||
units.radians(0.0), | ||
units.radians(0.0), | ||
units.degreesToRadians(rotation), | ||
).getQuaternion() | ||
|
||
json_data["tags"].append( | ||
{ | ||
"ID": id, | ||
"pose": { | ||
"translation": { | ||
"x": units.inchesToMeters(x), | ||
"y": units.inchesToMeters(y), | ||
"z": units.inchesToMeters(z), | ||
}, | ||
"rotation": { | ||
"quaternion": { | ||
"W": q.W(), | ||
"X": q.X(), | ||
"Y": q.Y(), | ||
"Z": q.Z(), | ||
} | ||
}, | ||
}, | ||
} | ||
) | ||
|
||
# Write JSON | ||
with open(filename.replace(".csv", ".json"), "w") as f: | ||
json.dump(json_data, f, indent=2) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.