Skip to content

Conversation

@qykr
Copy link

@qykr qykr commented Nov 8, 2025

Note: Callbacks and AbsoluteAnalogEncoder are untested, but IncrementalEncoder is tested

What kind of change does this PR introduce?

  • Feature: introduction of Encoder, EncoderBase, and IncrementalEncoder. AbsoluteAnalogEncoder now extends EncoderBase. A cool consequence is that IncrementalEncoder now has angle related methods.
  • Feature: CallbackCommand to easily add custom callbacks to commands. Also added default method uninterruptible() to Command to conveniently wrap in UninterruptibleCommand. If more convenience methods are welcome, let me know.
  • Feature: CRServoEx now supports AbsoluteAnalogEncoder, IncrementalEncoder, and anything that is an Encoder. This does require adding a generic, though.
  • Deprecated the old CRServoEx constructor specifically made for AbsoluteAnalogEncoder due to dependency injection principles.

I tried, but I can't add default methods when and whenSelf in Command. It requires knowledge of the self type, which is impossible unless you include it as a generic. However, doing that would break literally everything. However, the two most basic ones, when(BooleanSupplier condition, Runnable runnable) and when(BooleanSupplier condition, Command command) are still included in Command by default.

new CallbackCommand<>(new DriveWildly(follower))
    .when(() -> shooter.getRPM() > 3000, new WhatIsThisCommand())
    .whenSelf(DriveWildly::isHalfway, () -> shooter.setRPM(1000)
    .whenSelf(DriveWildly::isAlmostThere, DriveWildly::dance)
    .uninterruptible();

Did this PR introduce a breaking change?

  • Instead of Motor.Encoder, everything is now extracted into IncrementalEncoder. Old methods kept. I can revert this change easily if it's considered too breaking. You could, of course, put the IncrementalEncoder implementation as a revised Motor.Encoder and remove IncrementalEncoder entirely.
  • I kept all AbsoluteAnalogEncoder methods and constructors the same, but deprecated some in favor of better names. It won't break old code. AbsoluteAnalogEncoder is new anyways so it doesn't even matter that much.
  • Motor.Direction is extracted into RotationDirection, since it's very common. Don't know if this is a good idea, can revert.
  • CRMotorEx now takes a generic argument.

qykr and others added 26 commits October 27, 2025 22:57
# Conflicts:
#	core/src/main/java/com/seattlesolvers/solverslib/command/CallbackCommand.java
refactor: renamed zero to reset method in Encoder
refactor: renamed zero to reset method in Encoder
# Conflicts:
#	core/src/main/java/com/seattlesolvers/solverslib/hardware/IncrementalEncoder.java
#	core/src/main/java/com/seattlesolvers/solverslib/hardware/motors/Motor.java
#	core/src/main/java/com/seattlesolvers/solverslib/kinematics/wpilibkinematics/DifferentialDriveOdometry.java
…soluteAnalogEncoder due to dependency injection
@qykr qykr changed the title Feat callbacks encoders feat: callbacks encoders Nov 8, 2025
@ArushYadlapati
Copy link
Collaborator

This is a pretty large change, so I'm going to only merge in CallbackCommand for SolversLib 0.3.4 since it isn't breaking.

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.

2 participants