Skip to content

Commit

Permalink
remove subsystem parameter - can't use this in super()
Browse files Browse the repository at this point in the history
  • Loading branch information
ariscript committed Apr 1, 2023
1 parent 2d6cbd2 commit 8e1a9a4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ public class DualLimitedController implements SendableMotorController {

public DualLimitedController(SendableMotorController controller, DigitalInput forwardLimit, DigitalInput reverseLimit, DoublePreference forwardSpeed, DoublePreference reverseSpeed, Subsystem subsystem) {
this.controller = controller;
this.forwardController = new ForwardLimitedController(controller, forwardLimit, forwardSpeed, subsystem);
this.reverseController = new ReverseLimitedController(controller, reverseLimit, reverseSpeed, subsystem);
this.forwardController = new ForwardLimitedController(controller, forwardLimit, forwardSpeed);
this.reverseController = new ReverseLimitedController(controller, reverseLimit, reverseSpeed);
}

public void setSubsystem(Subsystem subsystem) {
forwardController.setSubsystem(subsystem);
reverseController.setSubsystem(subsystem);
}

public boolean canMove(double speed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,23 @@ public class ForwardLimitedController implements SendableMotorController {
/**
* The subsystem the controller is being attached to
*/
private final Subsystem subsystem;
private Subsystem subsystem;


/**
* Construct a new {@link ForwardLimitedController} from the given information.
* @param controller the controller to limit
* @param limit the forward limit switch
* @param forwardSpeed the speed preference to move at
* @param subsystem the subsystem the controller belongs to (to set requirement for commands)
*/
public ForwardLimitedController(SendableMotorController controller, DigitalInput limit, DoublePreference forwardSpeed, Subsystem subsystem) {
public ForwardLimitedController(SendableMotorController controller, DigitalInput limit, DoublePreference forwardSpeed) {
this.controller = controller;
this.limit = limit;
this.forwardSpeed = forwardSpeed;
}

public void setSubsystem(Subsystem subsystem) {
if (this.subsystem != null) throw new UnsupportedOperationException("Cannot replace already set subsystem.");
this.subsystem = subsystem;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ public class ReverseLimitedController implements SendableMotorController {
private final SendableMotorController controller;
private final DigitalInput limit;
private final DoublePreference reverseSpeed;
private final Subsystem subsystem;
private Subsystem subsystem;

public ReverseLimitedController(SendableMotorController controller, DigitalInput limit, DoublePreference forwardSpeed, Subsystem subsystem) {
public ReverseLimitedController(SendableMotorController controller, DigitalInput limit, DoublePreference forwardSpeed) {
this.controller = controller;
this.limit = limit;
this.reverseSpeed = forwardSpeed;
}

public void setSubsystem(Subsystem subsystem) {
if (this.subsystem != null) throw new UnsupportedOperationException("Cannot replace already set subsystem.");
this.subsystem = subsystem;
}

Expand Down

1 comment on commit 8e1a9a4

@ariscript
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: make methods requiring subsystem throw a more readable error than NPE

Please sign in to comment.