Skip to content

MotorSubsystem should not implement Motor or Encoder #76

@kcooney

Description

@kcooney

I've been thinking for a while that MotorSubsystem (soon to be named PositionalMotorSubsystem) should not implement Motor or Encoder, for a few reasons:

  1. It makes the surface area of the API quite large
  2. It allows code outside of the subsystem to directly interact with the motor (vs having the core robot code use public APIs provided by the subsystem subclass).

Instead, we could add a private static nested class to this class implementing Motor, and Encoder, and put the logic there. MotorSubsystem could have protected methods that allow the subclasses to have direct control. Perhaps:

private final MotorEncoder motorEncoder;

protected final Motor getMotor() {
  return motorEncoder;
}

protected final Encoder getEncoder() {
  return motorEncoder;
}

private static class MotorEncoder implements Motor, Encoder {
  // More code here...
}

It would probably still be helpful to have a public method for disabling the motor:

public final Command disableMotorCommand() {
  return new InstantCommand(this::disableMotor, this);
}

// Not final, to allow subclasses to do additional things when the subsystem is disabled
protected void disableMotor() {
  motorEncoder.disableMotor();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions