Skip to content

Reorganize MotorSubsystem; clearly label overrides of Motor, Encoder,… - #92

Closed
vdikov wants to merge 6 commits into
mainfrom
vdikov/refactor-motor-subsystem
Closed

Reorganize MotorSubsystem; clearly label overrides of Motor, Encoder,…#92
vdikov wants to merge 6 commits into
mainfrom
vdikov/refactor-motor-subsystem

Conversation

@vdikov

@vdikov vdikov commented Oct 27, 2025

Copy link
Copy Markdown
Contributor

… and Subsystem; use 'm_' prefix for MotorSubsystem members

… and Subsystem; use 'm_' prefix for MotorSubsystem members
…lasses inheriting from MotorSubsystem directly access these fields and that PR started creating breakages
@vdikov
vdikov force-pushed the vdikov/refactor-motor-subsystem branch from a1a4b2b to 273d258 Compare October 27, 2025 22:26
… it turned out, these are used by subclasses and cannot be changed without breaking user code

private boolean isEnabled;
/** A configuration for a MotorSubsystem */
public static class MotorSubsystemConfiguration {

@kcooney kcooney Oct 28, 2025

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.

Moving this nested class to another place in the file makes it very hard to see what was changed. Could we leave it where it was and if it needs to be moved move it in a separate PR?

Alternatively have a commit in this PR that moves it but makes no other changes, and clearly state that in the commit message.

protected final Motor motor;
protected final Encoder encoder;
// Specifies if the mechanism is currently under the control of the PID controller.
private boolean isEnabled;

@kcooney kcooney Oct 28, 2025

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.

I suspect this field was listed after the others because it is not final.

If we move the fields around, it would be good to have some consistent ordering (ex: private before protected, or final vs non-final).

Having the nested class in the middle is unusual, and I'm fine with defining it after the variables, but moving that in the same PR as other changes does make it harder to review (see below)

* <p>The MotorSybsystem supports a dual operation mode:
*
* <ul>
* <li><b>PID Mode</b> - the user set a destination position (aka "setpoint") and the motor

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.

Thank you for the updates here. This is a huge improvement.

* Engages the PID Controller.
*
* <p>The motor voltage will be periodically updated to move the motor towards the current
* setupoint.

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.

Suggested change
* setupoint.
* setpoint.

@vdikov

vdikov commented Oct 30, 2025

Copy link
Copy Markdown
Contributor Author

Thanks for the thoughtful review, @kcooney ,

Thanks to your comments I'm starting to realize I'm wrecking more havoc than doing good with all this refactoring. I learned to understand Java better along the way (e.g., ordering members "private before protected, or final vs non-final" makes more sense to me now). Staying away from m_ prefixes and staying consistent across our codebase makes more sense to me now too.

I'm going to slash down this PR, and put forward a smaller one, where I'm just adding the documentation to MotorSubsystem, but otherwise keep the class organization pretty much untouched.

@vdikov vdikov closed this Oct 30, 2025
@vdikov
vdikov deleted the vdikov/refactor-motor-subsystem branch October 30, 2025 05:02
* controller. The motor system's {@link isEnabled()} returns {@code true}.
*
* <p>The <b>Direct User Input Mode</b> is activated when the user calls the {@link
* set(ControlType,double,double)} or {@link set(ControlType,double)} method, where the user

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.

Suggested change
* set(ControlType,double,double)} or {@link set(ControlType,double)} method, where the user
* set(ControlMode,double,double)} or {@link set(ControlMode,double)} method, where the user

* <p>The <b>Direct User Input Mode</b> is activated when the user calls the {@link
* set(ControlType,double,double)} or {@link set(ControlType,double)} method, where the user
* provides direct input of type ControlType (specified via {@link
* MotorSubsystemConfiguration#controlMode(ControlType)}). The PID Mode is interrupted and

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.

Suggested change
* MotorSubsystemConfiguration#controlMode(ControlType)}). The PID Mode is interrupted and
* MotorSubsystemConfiguration#controlMode(ControlMode)}). The PID Mode is interrupted and

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