FRC1732 / 2020-Competition

Main robot code project for FIRST Infinite Recharge
0 stars 0 forks source link

[Post Season] Thought Experiment - Robot Factory #78

Open borkae opened 4 years ago

borkae commented 4 years ago
borkae commented 4 years ago

Factory Design Pattern

The idea here is if we can define motors as limited set of methods that are all we use after create of the object, then we can extract those details into the definition of the "robot". That becomes an external dependency and be something that stays with the hardware (the Rio and controllers themselves). Then we can stub out missing hardware and and still code again a "complete" robot even when it is still being built.

Example of a Motor interface:

public interface Motor {
  void setPercent(double percent);
  void setVoltage(double voltage);
  int getSensor();
}

We would have TalonSRX Motor implementation, a CANSparkMax Motor implementation and Dummy Motor implementation; The robot configuration file defines the components installed so the various subsytems will reach out to the factory to get their motor by its configuration name such as "ShooterMotor". The configuration file defines the motor controller and set up parameters. The factory uses that to instantiate the correct implementation and returns the interface of Motor.