Skip to content

REV Motor IO Layer#190

Draft
Spybh66 wants to merge 35 commits into
devfrom
implement-rev-motorio
Draft

REV Motor IO Layer#190
Spybh66 wants to merge 35 commits into
devfrom
implement-rev-motorio

Conversation

@Spybh66

@Spybh66 Spybh66 commented Oct 22, 2025

Copy link
Copy Markdown
Member

@garrett928 is working on the rev io implementation

Changes

  • implement a rev motorIO layer
    • For now, support a sparkmax
    • For now, support sim but not full physics sim
  • add example rotary subsytem using the REV IO layer
  • Add testing for rev rotary subsytem
  • add more tests for the rotary subsytem
  • add a default.instructions.md for copilot usage
  • default the motorio and mechanism.java to throw a notimplementedexception error.
    • because these interface methods are default you dont have to implemented them. They have a default empty {} implementation. But this means you could call it in a subsytem and not know its empty. This change should allow the flexibility of some motors to have some but not all methods and still warn the user of an obvious error of using a non implemented function.

Known issues

  • Rev spark controllers not closing properly

Bugs Found

  • waituntilgoalcommand bug
    I tried writing a test for this command and it fail for both rev and talonfx. below was the fixture
    @Test
    void testWaitUntilGoalCommand()
    {
        // Set a goal and wait for it to complete
        TestUtil.runTest(
            rotary.setSetpoint(Rotary.Setpoint.RAISED)
                .andThen(rotary.waitUntilGoalCommand(Rotary.Setpoint.RAISED.getSetpoint())),
            5,
            rotary);

        try {
            assertTrue(rotary.nearGoal(Rotary.Setpoint.RAISED.getSetpoint()));
        } catch (Exception e) {
            fail("Failed wait until goal command test: " + e.getMessage());
        }
    }
  • homeCommand
    I tried writing a test for the homecommand in the rotary.java but it also failed
    @Test
    void testHomeCommand()
    {
        // Test the homing sequence
        TestUtil.runTest(rotary.homeCommand(), 5, rotary);

        try {
            // After homing, should be near the HOME position (0 degrees)
            assertTrue(rotary.nearGoal(Rotary.Setpoint.HOME.getSetpoint()));
        } catch (Exception e) {
            fail("Failed home command test: " + e.getMessage());
        }
    }

@garrett928 garrett928 self-assigned this Nov 25, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request implements a REV motor IO layer to support REV Robotics motor controllers (SparkMax/SparkFlex) alongside the existing CTRE TalonFX implementation. The changes follow the hardware abstraction pattern established in the codebase and include an example rotary subsystem implementation with comprehensive testing.

Key Changes

  • REV Motor IO Implementation: Added MotorIORev and MotorIORevSim classes to support REV motor controllers with real hardware and simulation
  • Interface Enhancements: Modified MotorIO and Mechanism interfaces to throw NotImplementedException for unimplemented default methods and added simplified runPosition/runVelocity overloads
  • Example RevRotary Subsystem: Created a new example rotary subsystem using the REV IO layer with constants, commands, and comprehensive test coverage

Reviewed changes

Copilot reviewed 29 out of 29 changed files in this pull request and generated 15 comments.

Show a summary per file
File Description
vendordeps/REVLib.json Added REV Robotics library dependency v2025.0.3
vendordeps/photonlib.json Updated PhotonVision library from v2025.3.1 to v2025.3.2
vendordeps/libgrapplefrc2025.json Updated Grapple library from 2025.0.8 to 2025.1.3
src/main/java/frc/lib/io/motor/MotorIORev.java New real hardware implementation for REV motor controllers
src/main/java/frc/lib/io/motor/MotorIORevSim.java New simulation implementation for REV motor controllers
src/main/java/frc/lib/io/motor/MotorIO.java Added simplified position/velocity methods and NotImplementedException to defaults
src/main/java/frc/lib/io/motor/MotorIOSim.java Enhanced documentation for simulation interface methods
src/main/java/frc/lib/io/motor/MotorIOTalonFX.java Added comprehensive documentation for existing TalonFX methods
src/main/java/frc/lib/mechanisms/Mechanism.java Changed default methods to throw NotImplementedException
src/main/java/frc/lib/mechanisms/rotary/RotaryMechanism.java Added position logging in periodic method
src/main/java/frc/lib/mechanisms/rotary/RotaryMechanismReal.java Implemented new simplified position/velocity methods
src/main/java/frc/lib/mechanisms/rotary/RotaryMechanismSim.java Implemented new simplified methods and close()
src/main/java/frc/robot/subsystems/revRotary/RevRotary.java New example rotary subsystem using REV motors
src/main/java/frc/robot/subsystems/revRotary/RevRotaryConstants.java Configuration and factory methods for RevRotary subsystem
src/main/java/frc/robot/subsystems/rotary/Rotary.java Refactored enum pattern to use LoggedTunableNumber, removed close()
src/main/java/frc/robot/subsystems/rotary/RotaryConstants.java Added comprehensive documentation
src/main/java/frc/robot/RobotContainer.java Integrated RevRotary subsystem and added cleanup helper
src/main/java/frc/robot/Ports.java Added CAN ID for REV rotary subsystem motor
src/main/java/frc/lib/util/LoggedTunableNumber.java Modified initialization timing (with debug statements)
src/main/java/frc/lib/io/objectDetection/*.java Package rename from objectdetection to objectDetection (casing fix)
src/test/java/frc/robot/subsystems/revRotary/RevRotaryTest.java Comprehensive test suite for RevRotary subsystem
src/test/java/frc/robot/subsystems/rotary/RotaryTest.java Added additional test cases
src/test/java/frc/robot/RobotContainerTest.java Enhanced setup and added REV subsystem cleanup
.github/instructions/default.instructions.md New AI assistant instructions documenting library architecture

Comment thread src/main/java/frc/lib/util/LoggedTunableNumber.java Outdated
Comment thread src/main/java/frc/lib/util/LoggedTunableNumber.java Outdated
Comment thread src/main/java/frc/robot/RobotContainer.java Outdated
Comment thread src/main/java/frc/lib/io/motor/MotorIORev.java Outdated
Comment thread src/main/java/frc/lib/util/LoggedTunableNumber.java Outdated
Comment thread src/main/java/frc/robot/subsystems/revRotary/RevRotaryConstants.java Outdated
Comment thread src/main/java/frc/robot/subsystems/revRotary/RevRotaryConstants.java Outdated
Comment thread src/test/java/frc/robot/subsystems/rotary/RotaryTest.java Outdated
Comment thread src/main/java/frc/lib/io/motor/MotorIORevSim.java
Comment thread src/main/java/frc/lib/io/motor/MotorIOSim.java
garrett928 and others added 9 commits November 25, 2025 15:21
…s.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…s.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@garrett928

Copy link
Copy Markdown

@copilot open a new pull request to apply changes based on the comments in this thread. Do not implement the following though:

The simulation implementation directly sets position and velocity instead of properly controlling the motor. This bypasses the closed-loop control and physics simulation. The methods should use the controller to set references similar to MotorIORev, and let the simulation iterate to produce realistic behavior. Current implementation makes the simulation unrealistic.

Copilot AI commented Nov 25, 2025

Copy link
Copy Markdown
Contributor

@garrett928 I've opened a new pull request, #218, to work on those changes. Once the pull request is ready, I'll request review from you.

@jw00541

jw00541 commented Nov 25, 2025

Copy link
Copy Markdown
Contributor

This is my favorite PR ever

@CJendantix

Copy link
Copy Markdown
Member

Slopbot at its finest ✨

@garrett928 garrett928 enabled auto-merge November 26, 2025 01:54
Comment thread src/main/java/frc/lib/devices/ObjectDetection.java
Comment thread src/main/java/frc/lib/io/motor/MotorIORev.java
Comment thread src/main/java/frc/lib/io/objectDetection/ObjectDetectionIO.java
Comment thread src/main/java/frc/lib/io/objectDetection/ObjectDetectionIOSim.java
Comment thread src/main/java/frc/lib/mechanisms/rotary/RotaryMechanism.java
@Spybh66

Spybh66 commented Nov 26, 2025

Copy link
Copy Markdown
Member Author

I think this is good to go, I can't approve since I opened the PR

Comment on lines -100 to +101
return "";
throw new NotImplementedException("This method has not been implemented");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method needs to be removed for replay support

{}
{
throw new NotImplementedException("This method has not been implemented");
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks replay

Comment on lines -116 to +121
{}
{
throw new NotImplementedException("This method has not been implemented");
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks replay

Comment on lines -122 to +129
{}
{
throw new NotImplementedException("This method has not been implemented");
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks replay

{
throw new NotImplementedException("This method has not been implemented");
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks replay

new LoggedTunableNumber("Rotary RAISED", -90);

@RequiredArgsConstructor
@SuppressWarnings("Immutable")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why has this been removed?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't mean to. i'll add it back

RAISED(Degrees.of(RAISED_SETPOINT.get()));

private final Angle setpoint;
HOME(null),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HOME is not a setpoint, it shouldn't act as one. Also, for future reference, avoid setting anything to null unless it is a small, local variable.

Comment on lines +327 to +337

/**
* Helper method for unit testing.
*
* If we have any REV subsystems, close their resources here. IF we don't do this then we will
* get duplicate CAN ID errors when running multiple tests.
*/
public void closeREVSubsystems()
{
revRotary.close();
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make RobotContainer implement AutoClosable and close all necessary subsystems.

@BeforeEach
void setup()
{
assert HAL.initialize(500, 0); // initialize the HAL, crash if failed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong assert

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what your tests do:

public class RotaryTest implements AutoCloseable {
    Rotary rotary;

    @BeforeEach // this method will run before each test
    void setup()
    {
        assert HAL.initialize(500, 0); // initialize the HAL, crash if failed

        rotary = RotaryConstants.get();

        /* enable the robot */
        DriverStationSim.setEnabled(true);
        DriverStationSim.notifyNewData();

        /* delay ~100ms so the devices can start up and enable */
        Timer.delay(0.100);
    }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's wrong. I didn't write that. You can either
a. Change just yours
b. Change all of them
or
c. Do nothing

As to what you choose? I don't really care.

public void close()
{
rotary.close();
if (rotary != null) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would rotary == null?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was a left over from some debugging. i'll remove it

@garrett928

Copy link
Copy Markdown

@CJendantix thanks for the review. Sorry for the delay, I've been busy with work and the holidays.

I'm fine with not merging the PR until its feature parity with CTRE. I'll make the changes you suggested and add the rest of the sim support

@garrett928 garrett928 marked this pull request as draft December 11, 2025 01:58
auto-merge was automatically disabled December 11, 2025 01:58

Pull request was converted to draft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants