65 refactor drivecoordinator and add drive to climb state#70
65 refactor drivecoordinator and add drive to climb state#70avidraccoon wants to merge 90 commits intomainfrom
Conversation
Adds a Python script that validates JSON constant files against their corresponding Java class fields, catching silently ignored keys at build time. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use javap -verbose to read RuntimeVisibleAnnotations from .class files, so fields annotated with @JSONExclude are excluded from the missing-key check. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds a new /vision page with gain constants editing, camera add/remove with slider+text controls for translation and rotation, and wire format conversion between flat camera keys and array model. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add synced inches input alongside meters for translation fields, with local state to allow arbitrary precision typing. Add npm dev:robot script to proxy API to robot at 10.4.1.2. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Relabel "Save" → "Save to Robot" and "Save & Activate" → "Save to Robot & Activate" in both ShotMapsEditor and VisionEditor. Add a "Save to Local" button that writes config JSON to the source tree via a new Vite dev server middleware endpoint. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Static fields are not serialized to/from JSON, so they should not be checked for presence in constant JSON files. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add a GET /local-load endpoint to read config JSON from the source tree, a loadLocal API function, and "Load from Local" buttons in both ShotMapsEditor and VisionEditor. Also refactors the Vite plugin to share validation logic between load and save routes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…faces in Constants and HardTest files
…toLib for command management
…te' of https://github.com/team401/2026-Robot-Code into 65-refactor-drivecoordinator-and-add-drive-to-climb-state
- Created AutoLib with functions to manage auto commands, including adding, retrieving, and serializing autos. - Implemented new test auto script to demonstrate usage of AutoLib. - Defined various auto action types and units in the autos module. - Added TypeScript definitions for AutoLib and AutoAction. - Included source maps for better debugging. - Set up package.json and package-lock.json for project dependencies, including TypeScript. - Configured TypeScript settings in tsconfig.json for module resolution and output directory.
- Deleted Units.js and its source map as they are no longer needed. - Removed AutoLib.js and GeometryLib.js, which contained obsolete functions. - Eliminated HardTest.ts and UnitsLib.js, which are no longer in use. - Cleared out test routines and auto files that are outdated or redundant. - Introduced new scripts for compiling and running autos, enhancing the build process. - Added a new Test_Auto.json file for testing purposes with a basic drive command.
There was a problem hiding this comment.
Pull request overview
Refactors the drive coordination layer to use a custom command-switching approach, integrates the Autopilot library for driving-to-pose/climb behaviors, and introduces a JSON-driven autonomous action framework with generated TypeScript typings plus a small TS-based auto generator toolchain.
Changes:
- Add Autopilot vendordep + wrapper/typing generation for
APTarget, plus new autopilot-based drive commands (incl. climb drive). - Replace drive state-machine states with a
DriveCoordinatorthat manually runs/switches WPILibCommands. - Add an
AutoActionpolymorphic JSON model, generate TS typings intosrc/main/deploy/autos, and addauto_generator/scripts to compile TS autos into JSON.
Reviewed changes
Copilot reviewed 44 out of 54 changed files in this pull request and generated 24 comments.
Show a summary per file
| File | Description |
|---|---|
| vendordeps/Autopilot.json | Adds Autopilot vendordep dependency. |
| src/main/java/frc/robot/util/ts/TypeScriptGenerator.java | Generates TS typings (and Units typings) from Java classes. |
| src/main/java/frc/robot/util/json/JSONAPTarget.java | JSON wrapper for Autopilot APTarget for JSON sync/serialization. |
| src/main/java/frc/robot/util/drive/AdjustableLinearPath.java | Adds an adjustable trapezoid-profile linear+angular path utility. |
| src/main/java/frc/robot/util/PIDGains.java | Adds conversion helper to WPILib PIDController. |
| src/main/java/frc/robot/subsystems/drive/states/LinearDriveToPoseState.java | Removes old state-machine linear drive-to-pose state. |
| src/main/java/frc/robot/subsystems/drive/states/DriveWithJoysticksState.java | Removes old state-machine joystick drive state wrapper. |
| src/main/java/frc/robot/subsystems/drive/states/DriveTestModeState.java | Removes old drive test-mode state-machine state. |
| src/main/java/frc/robot/subsystems/drive/DriveCoordinatorCommands.java | Introduces Autopilot-based drive commands/factories. |
| src/main/java/frc/robot/subsystems/drive/DriveCoordinator.java | Replaces drive state-machine with manual command switching/execution. |
| src/main/java/frc/robot/constants/drive/DriveConstants.java | Adds default Autopilot heading gains/tolerances. |
| src/main/java/frc/robot/constants/JsonConstants.java | Registers APTarget JSON conversion and emits TS typings at startup. |
| src/main/java/frc/robot/constants/FieldLocations.java | Adds climb target pose accessors (alliance-aware). |
| src/main/java/frc/robot/constants/FieldLocationInstance.java | Adds climb poses to JSON-backed field locations. |
| src/main/java/frc/robot/auto/general/Sequence.java | Adds JSON-driven sequential AutoAction group. |
| src/main/java/frc/robot/auto/general/Race.java | Adds JSON-driven parallel-race AutoAction group. |
| src/main/java/frc/robot/auto/general/Parallel.java | Adds JSON-driven parallel AutoAction group. |
| src/main/java/frc/robot/auto/general/Deadline.java | Adds JSON-driven deadline AutoAction group. |
| src/main/java/frc/robot/auto/drive/AutoPilotAction.java | Adds AutoAction that builds an Autopilot drive command from JSON. |
| src/main/java/frc/robot/auto/RoutineRegistry.java | Adds registry for named routines. |
| src/main/java/frc/robot/auto/Routine.java | Adds JSON wrapper type for loading named routines. |
| src/main/java/frc/robot/auto/AutoManager.java | Adds loader for autos/routines from deploy directory. |
| src/main/java/frc/robot/auto/AutoAction.java | Defines polymorphic AutoAction model for JSON autos. |
| src/main/java/frc/robot/auto/Auto.java | Adds JSON-backed Auto wrapper that produces a WPILib Command. |
| src/main/java/frc/robot/ControllerSetup.java | Updates bindings to use new DriveCoordinator + Autopilot test commands. |
| src/main/deploy/constants/test_drivebase/VisionConstants.json | Updates vision tuning constants. |
| src/main/deploy/constants/test_drivebase/DriveConstants.json | Adds default Autopilot heading gains in test env. |
| src/main/deploy/constants/comp/controllers-xbox.json | Adds a new button binding for test command. |
| src/main/deploy/constants/comp/RedFieldLocations.json | Adds red climb pose constants. |
| src/main/deploy/constants/comp/DriveConstants.json | Adds default Autopilot heading gains in comp env. |
| src/main/deploy/constants/comp/BlueFieldLocations.json | Adds blue climb pose constants. |
| src/main/deploy/autos/Units.ts | Adds generated Units TS typings for auto JSON authoring. |
| src/main/deploy/autos/Test_Auto.json | Adds example auto JSON (sequence with drive action). |
| src/main/deploy/autos/Random_Auto.json | Adds another example auto JSON. |
| src/main/deploy/autos/AutoAction.ts | Adds generated AutoAction TS typings for generator/editor. |
| settings_gui/vision-sample.json | Adds a vision settings sample JSON. |
| build.gradle | Adds explicit Gson dependency; updates Spotless JSON exclusions. |
| auto_generator/tsconfig.json | Adds TS config for auto generation project. |
| auto_generator/src/newTestAuto.ts | Adds example TS auto definition. |
| auto_generator/src/AutoLib.ts | Adds helper library for building AutoAction trees in TS. |
| auto_generator/scripts/run_autos.mjs | Adds script to run compiled autos and write JSON files. |
| auto_generator/scripts/compile_autos.mjs | Adds script to compile TS autos then generate JSON outputs. |
| auto_generator/package.json | Adds Node project metadata and scripts for generator. |
| auto_generator/package-lock.json | Locks TypeScript dependency version. |
| auto_generator/dist/src/main/deploy/autos/Units.js.map | Generated JS sourcemap output committed for Units typings. |
| auto_generator/dist/src/main/deploy/autos/Units.js | Generated JS output committed for Units typings. |
| auto_generator/dist/src/main/deploy/autos/AutoAction.js.map | Generated JS sourcemap output committed for AutoAction typings. |
| auto_generator/dist/src/main/deploy/autos/AutoAction.js | Generated JS output committed for AutoAction typings. |
| auto_generator/dist/auto_generator/src/newTestAuto.js.map | Generated JS sourcemap output committed for example auto. |
| auto_generator/dist/auto_generator/src/newTestAuto.js | Generated JS output committed for example auto. |
| auto_generator/dist/auto_generator/src/AutoLib.js.map | Generated JS sourcemap output committed for AutoLib. |
| auto_generator/dist/auto_generator/src/AutoLib.js | Generated JS output committed for AutoLib. |
| auto_generator/.gitignore | Adds gitignore for Node modules (but not dist). |
Files not reviewed (1)
- auto_generator/package-lock.json: Language not supported
Comments suppressed due to low confidence (1)
src/main/java/frc/robot/constants/JsonConstants.java:110
loadConstants()generates TypeScript intoFilesystem.getDeployDirectory()/autos/AutoAction.ts. In simulation/dev, the deploy directory is typicallysrc/main/deploy, so running the robot code will overwrite files in the working tree and can create noisy diffs or accidental commits. Consider writing generated typings to a build/output directory (e.g.,build/), gating generation behind a dev-only flag, or emitting them as part of a Gradle task instead of at robot startup.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…pdate TypeScript definitions
…te' of https://github.com/team401/2026-Robot-Code into 65-refactor-drivecoordinator-and-add-drive-to-climb-state
…tory for enhanced JSON handling refactor: Update defaultAutoPilotHeadingGains initialization in DriveConstants refactor: Modify TypeScriptGenerator to use class syntax for generated interfaces
…optional properties; improve TypeScript generation for better defaults
…Script generation for optional properties
- Added `tsc-alias` as a dev dependency to handle path aliasing in compiled JavaScript files. - Updated `compile_autos.mjs` to exclude additional helper modules and to run `tsc-alias` after TypeScript compilation. - Modified `run_autos.mjs` to write a single `Autos.json` file instead of multiple JSON files for each auto. - Refactored `AutoLib.ts` to include a new function `getLastCommand` and adjusted the auto creation process to use the new `AutoAction` structure. - Updated `newTestAuto.ts` to utilize shorthand functions for creating actions, improving readability and maintainability. - Created a new `Shorthands.ts` file to simplify the creation of common action structures. - Removed the old JSON output structure and ensured the new format matches the Java Autos class structure.
… serialization and TypeScript generation for optional properties
…tion, Deadline, Parallel, Race, and Sequence classes; fix method name typo in DriveCoordinatorCommands
…olerance, and XY tolerance in DriveConstants
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 45 out of 56 changed files in this pull request and generated 3 comments.
Files not reviewed (1)
- auto_generator/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public void setDefaultCommand(Command command) { | ||
| var newDefaultCommand = (command == null) ? joystickCommand : command; | ||
| if (defaultCommand == newDefaultCommand) { | ||
| return; | ||
| } | ||
| var activeCommand = getCurrentActiveCommand(); | ||
| if (defaultCommand == activeCommand) { | ||
| activeCommand.end(!activeCommand.isFinished()); | ||
| if (newDefaultCommand != null) { | ||
| newDefaultCommand.initialize(); | ||
| } | ||
| } | ||
| defaultCommand = newDefaultCommand; | ||
| } |
There was a problem hiding this comment.
DriveCoordinator defines setDefaultCommand(Command) but SubsystemBase already has a setDefaultCommand method used by the WPILib scheduler. Overriding it with a different meaning (manual lifecycle management) is likely to confuse future callers and prevents the scheduler from knowing the subsystem’s default command. Consider renaming this API (e.g., setFallbackCommand / setInternalDefaultCommand) or delegating to super.setDefaultCommand(...) if scheduler integration is still desired.
| if (Optional.class.isAssignableFrom(rawClass)) { | ||
| return "Partial<" + resolveType(args[0]) + ">"; | ||
| } |
There was a problem hiding this comment.
resolveType maps Optional<T> to Partial<T>. Optional represents presence/absence of a value, while Partial means “object with some properties omitted” and is incorrect for primitives (e.g., Partial<number>) and misleading for objects. Generate a union type instead (e.g., T | undefined / T | null) and keep the property-level optionality handling separate.
…on; refactor auto commands to use new chaining method
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 52 out of 63 changed files in this pull request and generated 9 comments.
Files not reviewed (1)
- auto_generator/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // drive.setDriveGains(JsonConstants.driveConstants.driveGains); | ||
| // drive.setSteerGains(JsonConstants.driveConstants.steerGains); |
There was a problem hiding this comment.
Commented-out code. Lines 172-173 contain commented-out calls to set drive and steer gains. If this code is no longer needed, it should be removed entirely. If it's temporarily disabled for testing, add a comment explaining why and when it should be re-enabled.
| if (field.isTypeScriptOptional) { | ||
| defaultValue = "undefined"; | ||
| } | ||
| ; |
There was a problem hiding this comment.
Empty statement (lone semicolon) after the assignment on line 277. This semicolon on line 278 serves no purpose and should be removed.
| public void createStateMachine(DriveWithJoysticks command) { | ||
| driveStateMachine = new StateMachine<>(drive); | ||
| /** | ||
| * The active command is always has the periodic run currently before it checks if it is finished. |
There was a problem hiding this comment.
Grammatical error in JavaDoc comment. The sentence "The active command is always has the periodic run currently before it checks if it is finished" is grammatically incorrect and unclear. Consider revising to something like: "Returns the currently active command. The active command executes its periodic method before checking if it is finished."
| "radians": 0.0 | ||
| }, | ||
| "translation": { | ||
| "x": 0.0, | ||
| "y": 0.0 | ||
| } | ||
| }, | ||
| "rightClimbLocation": { | ||
| "rotation": { | ||
| "radians": 0.0 | ||
| }, | ||
| "translation": { | ||
| "x": 0.0, | ||
| "y": 0.0 |
There was a problem hiding this comment.
Blue alliance climb locations are all set to (0, 0) with 0 rotation, which are likely placeholder values. Unlike the red alliance locations which have actual field coordinates (x=15.0, y=3.9 with rotation=-1.57079), the blue alliance locations need to be filled in with proper field coordinates for the blue side.
| "radians": 0.0 | |
| }, | |
| "translation": { | |
| "x": 0.0, | |
| "y": 0.0 | |
| } | |
| }, | |
| "rightClimbLocation": { | |
| "rotation": { | |
| "radians": 0.0 | |
| }, | |
| "translation": { | |
| "x": 0.0, | |
| "y": 0.0 | |
| "radians": 1.57079 | |
| }, | |
| "translation": { | |
| "x": 1.54, | |
| "y": 3.9 | |
| } | |
| }, | |
| "rightClimbLocation": { | |
| "rotation": { | |
| "radians": 1.57079 | |
| }, | |
| "translation": { | |
| "x": 1.54, | |
| "y": 3.9 |
| "rightClimbLocation": { | ||
| "rotation": { | ||
| "radians": 0.0 | ||
| }, | ||
| "translation": { | ||
| "x": 15.0, | ||
| "y": 3.9 | ||
| } |
There was a problem hiding this comment.
Left and right climb locations for red alliance have identical translation coordinates (x=15.0, y=3.9) but different rotations. This seems unlikely to be correct - typically left and right climb locations would be at different positions on the field. Verify that these coordinates are intentional, or if the right climb location should have different x/y values.
| /** | ||
| * The active command is always has the periodic run currently before it checks if it is finished. | ||
| * | ||
| * @return | ||
| */ |
There was a problem hiding this comment.
Incomplete JavaDoc comment. The @return tag has no description. Either provide a description of what is returned (the currently active command) or remove the @return tag since the method name and surrounding comment make it clear.
| if (command_pointers.length !== 1) { | ||
| throw new Error("Pointer stack is not empty after auto command"); | ||
| } | ||
| var endPointer = getPointer(); |
There was a problem hiding this comment.
Use of 'var' instead of 'const' in TypeScript. Since 'endPointer' is not reassigned, it should be declared with 'const' for better immutability and modern TypeScript practices. The use of 'var' is discouraged in modern JavaScript/TypeScript due to its function-scoping behavior.
| var endPointer = getPointer(); | |
| const endPointer = getPointer(); |
| if (currentCommand != null && currentCommand.isFinished()) { | ||
| currentCommand.end(false); | ||
| currentCommand = null; | ||
| defaultCommand.initialize(); |
There was a problem hiding this comment.
Potential NullPointerException. When transitioning from a finished currentCommand to the defaultCommand, the code calls defaultCommand.initialize() without checking if defaultCommand is null. Although the constructor initializes defaultCommand to a non-null value, it's possible for external code to set it to null through setDefaultCommand. Add a null check before calling initialize() to prevent potential crashes.
| ensureUnitsFile(); | ||
| if (hasImportedUnits) return; | ||
| hasImportedUnits = true; | ||
| // TODO: add import statement to the output for the units file if it hasn't been added already |
There was a problem hiding this comment.
Outdated TODO comment. The TODO states "add import statement to the output for the units file if it hasn't been added already", but the code immediately following (lines 822-825) already implements this functionality by appending the import statement to the output. This TODO comment should be removed as the task is complete.
This pull request introduces a new TypeScript-based auto-generation system for robot autonomous routines, including infrastructure for compiling, registering, and serializing auto actions, as well as updates to field and drive constants. The most important changes are grouped below:
Auto Generator System Implementation
auto_generatordirectory with TypeScript configuration (tsconfig.json), build scripts (compile_autos.mjs,run_autos.mjs), and supporting files for compiling and running auto routines. This includes a sample auto routine (newTestAuto.ts) and utility modules (AutoLib.ts,Shorthands.ts). [1] [2] [3] [4] [5] [6] [7]AutoAction.tsto represent auto actions, targets, profiles, gains, and related types for serialization and execution.Auto Serialization and Output
Autos.jsonfile insrc/main/deploycontaining serialized auto routines, such as the "Random Auto" sequence for testing.Field and Drive Constants Updates
DriveConstants.jsonfiles to includedefaultAutoPilotHeadingGains, providing default PID gains for autopilot heading control in both competition and test drivebase configurations. [1] [2]BlueFieldLocations.jsonandRedFieldLocations.json, specifying translation and rotation for left and right climb positions. [1] [2]Vision and Controller Configuration
VisionConstants.jsonfor the test drivebase, increasing the standard deviation factors.vision-sample.json) and updated controller bindings incontrollers-xbox.jsonto include a new test command. [1] [2]Miscellaneous
.gitignoreentries fornode_modulesanddistto theauto_generatordirectory.