-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added json configs * sim settings * Refactored Manager to work with Drive * Add AutoAligner subsystem with state management and target poses * Changed to using operator controller in global constants * Made some style changes to be consistent * Weird fixes * Possibly working first attempt at IO layers * did IO for manager(hopefully) * Small changes to AlgaeCorraler * Added IO layers to AlgaeCorraler (hopefully works) * Changed AlgaeCorraler to not crash * Added the two pivot arms for AlgaeCorraler in sim * Fixed all the problems (for the most part) * Added sim PID for Algae Corraler, tolerances, and other minor changes * Apply Prettier format * Doing some of the changes requested * Apply Prettier format * spark max IDs * Can IDs * Refactor swerve module configurations and remove deprecated example file * Add Vision subsystem with IO interfaces and update dependencies * Added vision 2nd camera and sim * devious prank * Apply Prettier format --------- Co-authored-by: Aitan Martinez <[email protected]> Co-authored-by: Yuriana101 <[email protected]> Co-authored-by: GreenTomato5 <[email protected]> Co-authored-by: github-actions <[email protected]> Co-authored-by: Bailey Bonde <[email protected]>
- Loading branch information
1 parent
7427ac8
commit ac43396
Showing
49 changed files
with
1,981 additions
and
224 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import re | ||
import os | ||
import sys | ||
|
||
# List of files to excuse (constants and things we didnt make and stuff we wont use) | ||
excused_files = ["GlobalConstants.java", "Drive.java", "TunerConstants.java", "BuildConstants.java", "LocalADStarAK.java", "VisionUtil.java", "SwerveModule.java", "VisionIOSim.java", "ElevatorConstants.java", "IntakeConstants.java", | ||
"RepulsorFieldPlanner.java", "Force.java", "ManagerConstants.java", "AutoAlignConstants.java", "Manager.java", "AutoAlign.java", "AutoAlignStates.java", "CoralerConstants.java", "AlgaerConstants.java", "VisionConstants.java", | ||
"LEDStates.java", "LEDIOSim.java", "LEDIOReal.java", "AutoManager.java", "TippingCalculator.java", "WheelRadiusCharacterization.java", "ElevatorIOReal.java", "ElevatorIOSim.java"] | ||
|
||
# Not really dirs becasue the full ones didnt work | ||
excused_dirs = [ | ||
"bin", | ||
"build", | ||
"src/main/java/frc/robot/pioneersLib" | ||
] | ||
|
||
# Weird stuff that shouldn't go in constants, dont put function/var names in here theyre already checked | ||
excused_cases = ["ModuleIOSparkMax", "case", "new Module(", "new BaseStatusSignal[", "BaseStatusSignal.waitForAll(", "new ModuleIOHybrid(", "Math.pow(", "+=", "drive.getRotation()", "autoChooser.addOption(", "static final", "getRealTimestamp", "antiJitterThreshold", "trackWidth", "i < 4", "SwerveModuleState[4]", "gearRatio", "Math.PI", "private final", "/ 360", "/360", "* 360", "*360", "DCMotor.get", "/60", "/ 60", "getRawButtonPressed("] | ||
|
||
def check_for_magic_numbers(file_path): | ||
magic_numbers = [] | ||
|
||
# Number pattern makes sure number isnt in a var and detects all numbers that arent in a function/var | ||
number_pattern = r'(?<!\w)-?(?:\d*\.\d+|\d+\.?)\b(?!\w)' | ||
zero_pattern = r'^0*\.?0+$' | ||
|
||
with open(file_path, 'r') as file: | ||
lines = file.readlines() | ||
in_comment_block = False | ||
|
||
for line_number, line in enumerate(lines, 1): | ||
line = line.strip() | ||
|
||
# Skip empty lines | ||
if not line: | ||
continue | ||
|
||
# Skip big comments | ||
if '/*' in line: | ||
in_comment_block = True | ||
# If someone like put a thing after a multi-line comment end this wouldnt work but idk if you can even do that | ||
if '*/' in line: | ||
in_comment_block = False | ||
continue | ||
if in_comment_block: | ||
continue | ||
|
||
# Skip regular comments and imports | ||
if line.startswith('//') or line.startswith('import'): | ||
continue | ||
|
||
# Skips excused cases | ||
if any(case in line for case in excused_cases): | ||
continue | ||
|
||
numbers = re.findall(number_pattern, line) | ||
for number in numbers: | ||
# Skip for zeroes, they're fine as is | ||
if re.match(zero_pattern, number): | ||
continue | ||
magic_numbers.append((number, line_number)) | ||
return magic_numbers | ||
|
||
def is_file_excused(file_path, project_root): | ||
filename = os.path.basename(file_path) | ||
if filename in excused_files: | ||
return True | ||
|
||
relative_path = os.path.relpath(file_path, project_root) | ||
for excluded_dir in excused_dirs: | ||
if relative_path.startswith(excluded_dir) or excluded_dir in relative_path: | ||
return True | ||
|
||
return False | ||
|
||
def scan_directory(directory): | ||
magic_number_count = 0 | ||
for root, _, files in os.walk(directory): | ||
for file in files: | ||
if file.endswith('.java'): | ||
file_path = os.path.join(root, file) | ||
if not is_file_excused(file_path, directory): | ||
magic_numbers = check_for_magic_numbers(file_path) | ||
if magic_numbers: | ||
print(f"In {file_path}:") | ||
for number, line_number in magic_numbers: | ||
print(f" Line {line_number}: Magic number {number}") | ||
magic_number_count += 1 | ||
return magic_number_count | ||
|
||
if __name__ == "__main__": | ||
# Get scripts dir | ||
script_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
# Move up 2 dirs to get the project root | ||
project_root = os.path.dirname(os.path.dirname(script_dir)) | ||
|
||
print(f"Scanning directory: {project_root}") | ||
total_magic_numbers = scan_directory(project_root) | ||
|
||
# Fails if magic numbers are in any non excused locations | ||
if total_magic_numbers > 0: | ||
print(f"\nTotal magic numbers found: {total_magic_numbers}.\nPlease put these in Constanats.java!") | ||
sys.exit(1) | ||
else: | ||
print("\nNo Magic Number Found") | ||
sys.exit(0) |
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,24 @@ | ||
name: Find Misplaced Constants | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- reopened | ||
- opened | ||
- synchronize | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
find-misplaced-constants: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repo | ||
uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.11' | ||
- name: Run Python Script | ||
run: python .github/scripts/constants.py |
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,97 @@ | ||
{ | ||
"keyboardJoysticks": [ | ||
{ | ||
"axisConfig": [ | ||
{ | ||
"decKey": 65, | ||
"incKey": 68 | ||
}, | ||
{ | ||
"decKey": 87, | ||
"incKey": 83 | ||
}, | ||
{ | ||
"decKey": 69, | ||
"decayRate": 0.0, | ||
"incKey": 82, | ||
"keyRate": 0.009999999776482582 | ||
} | ||
], | ||
"axisCount": 3, | ||
"buttonCount": 4, | ||
"buttonKeys": [ | ||
90, | ||
88, | ||
67, | ||
86 | ||
], | ||
"povConfig": [ | ||
{ | ||
"key0": 328, | ||
"key135": 323, | ||
"key180": 322, | ||
"key225": 321, | ||
"key270": 324, | ||
"key315": 327, | ||
"key45": 329, | ||
"key90": 326 | ||
} | ||
], | ||
"povCount": 1 | ||
}, | ||
{ | ||
"axisConfig": [ | ||
{ | ||
"decKey": 74, | ||
"incKey": 76 | ||
}, | ||
{ | ||
"decKey": 73, | ||
"incKey": 75 | ||
} | ||
], | ||
"axisCount": 2, | ||
"buttonCount": 4, | ||
"buttonKeys": [ | ||
77, | ||
44, | ||
46, | ||
47 | ||
], | ||
"povCount": 0 | ||
}, | ||
{ | ||
"axisConfig": [ | ||
{ | ||
"decKey": 263, | ||
"incKey": 262 | ||
}, | ||
{ | ||
"decKey": 265, | ||
"incKey": 264 | ||
} | ||
], | ||
"axisCount": 2, | ||
"buttonCount": 6, | ||
"buttonKeys": [ | ||
260, | ||
268, | ||
266, | ||
261, | ||
269, | ||
267 | ||
], | ||
"povCount": 0 | ||
}, | ||
{ | ||
"axisCount": 0, | ||
"buttonCount": 0, | ||
"povCount": 0 | ||
} | ||
], | ||
"robotJoysticks": [ | ||
{ | ||
"guid": "Keyboard0" | ||
} | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
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,8 @@ | ||
{ | ||
"angleJoystickRadiusDeadband": 0.5, | ||
"heading": { | ||
"p": 0.4, | ||
"i": 0, | ||
"d": 0.01 | ||
} | ||
} |
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,27 @@ | ||
{ | ||
"location": { | ||
"front": 10.171, | ||
"left": -13.878 | ||
}, | ||
"absoluteEncoderOffset": 0, | ||
"drive": { | ||
"type": "sparkmax_neo", | ||
"id": 1, | ||
"canbus": null | ||
}, | ||
"angle": { | ||
"type": "sparkmax_neo", | ||
"id": 1, | ||
"canbus": null | ||
}, | ||
"encoder": { | ||
"type": "cancoder", | ||
"id": 1, | ||
"canbus": null | ||
}, | ||
"inverted": { | ||
"drive": false, | ||
"angle": false | ||
}, | ||
"absoluteEncoderInverted": false | ||
} |
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,27 @@ | ||
{ | ||
"location": { | ||
"front": -10.635, | ||
"left": -12.796 | ||
}, | ||
"absoluteEncoderOffset": 0, | ||
"drive": { | ||
"type": "sparkmax_neo", | ||
"id": 1, | ||
"canbus": null | ||
}, | ||
"angle": { | ||
"type": "sparkmax_neo", | ||
"id": 1, | ||
"canbus": null | ||
}, | ||
"encoder": { | ||
"type": "cancoder", | ||
"id": 1, | ||
"canbus": null | ||
}, | ||
"inverted": { | ||
"drive": false, | ||
"angle": false | ||
}, | ||
"absoluteEncoderInverted": false | ||
} |
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,27 @@ | ||
{ | ||
"location": { | ||
"front": null, | ||
"left": 11.331 | ||
}, | ||
"absoluteEncoderOffset": 13.543, | ||
"drive": { | ||
"type": "sparkmax_neo", | ||
"id": 0, | ||
"canbus": null | ||
}, | ||
"angle": { | ||
"type": "sparkmax_neo", | ||
"id": 0, | ||
"canbus": null | ||
}, | ||
"encoder": { | ||
"type": "cancoder", | ||
"id": 0, | ||
"canbus": null | ||
}, | ||
"inverted": { | ||
"drive": false, | ||
"angle": false | ||
}, | ||
"absoluteEncoderInverted": false | ||
} |
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,27 @@ | ||
{ | ||
"location": { | ||
"front": -10.822, | ||
"left": 13.793 | ||
}, | ||
"absoluteEncoderOffset": 0, | ||
"drive": { | ||
"type": "sparkmax_neo", | ||
"id": 1, | ||
"canbus": null | ||
}, | ||
"angle": { | ||
"type": "sparkmax_neo", | ||
"id": 1, | ||
"canbus": null | ||
}, | ||
"encoder": { | ||
"type": "cancoder", | ||
"id": 1, | ||
"canbus": null | ||
}, | ||
"inverted": { | ||
"drive": false, | ||
"angle": false | ||
}, | ||
"absoluteEncoderInverted": false | ||
} |
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,24 @@ | ||
{ | ||
"optimalVoltage": 12, | ||
"robotMass": 79, | ||
"wheelGripCoefficientOfFriction": 1.542, | ||
"currentLimit": { | ||
"drive": 40, | ||
"angle": 20 | ||
}, | ||
"conversionFactors": { | ||
"angle": { | ||
"gearRatio": 21.4286, | ||
"factor": 0 | ||
}, | ||
"drive": { | ||
"diameter": 3.5, | ||
"gearRatio": 6.75, | ||
"factor": 0 | ||
} | ||
}, | ||
"rampRate": { | ||
"drive": 0.12, | ||
"angle": 0.05 | ||
} | ||
} |
Oops, something went wrong.