Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions choreolib/py/choreo/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
from enum import Enum
from typing import *

from choreo.util.field_dimensions import FIELD_LENGTH, FIELD_WIDTH
from wpimath.geometry import Pose2d

FIELD_LENGTH = 16.5811
FIELD_WIDTH = 8.19912


class FlipperType(Enum):
MIRRORED = 0
Expand Down
3 changes: 3 additions & 0 deletions choreolib/py/choreo/util/field_dimensions.py
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
9 changes: 9 additions & 0 deletions choreolib/src/main/java/choreo/util/FieldDimensions.java
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
#include <units/angle.h>
#include <units/length.h>

#include "choreo/util/FieldDimensions.h"
#include "choreo/util/Map.h"

namespace choreo::util {

static constexpr units::meter_t fieldLength = 16.5811_m;
static constexpr units::meter_t fieldWidth = 8.19912_m;

enum class FlipperType { Mirrored, RotateAround };

/**
Expand Down
10 changes: 10 additions & 0 deletions choreolib/src/main/native/include/choreo/util/FieldDimensions.h
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
3 changes: 3 additions & 0 deletions src/components/field/svg/fields/FieldDimensions.tsx
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;
Copy link
Collaborator

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

Copy link
Collaborator Author

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.

export const FIELD_WIDTH = 8.19912;
85 changes: 85 additions & 0 deletions update_field_dimensions.py
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)
Loading