Skip to content

Shooter Subsystem Rework: Add Rotor Subsystem - #114

Open
CanineSatsuma6 wants to merge 4 commits into
delete-existing-shooter-subsystemfrom
shooter-rework-rotor
Open

CanineSatsuma6 wants to merge 4 commits into
delete-existing-shooter-subsystemfrom
shooter-rework-rotor

Conversation

@CanineSatsuma6

Copy link
Copy Markdown
Contributor

Note: This PR is one of several in a series of PRs designed to rework our shooter subsystem to address issues with maintainability and readability and reintroduce some semblance of simplicity. Any PR that's merging into the shooter-subsystem-rework branch and NOT main is a part of this series.

Background

This PR adds in the "Rotor" component of the larger shooter subsystem. It also lays a foundation for how other components of the shooter subsystem will be created. Important notes include:

  • Each component will become its own true subsystem. This will eliminate the need to manually call each component's periodic function in the top-level periodic function for the shooter subsystem.
  • Each component will consist of two "layers":
    1. The "subsystem layer". This contains just the business logic for how to control the component. State machines, commands, and figuring out what the motors need to actually do should go here.
    2. The "physical layer". This contains the bare-bones logic for how to directly control the motors and how to read the sensors. It does NOT keep information about state, but rather handles only the initialization of and interaction with the physical or simulated hardware.
  • The physical layer is made up of a few sub-parts:
    1. The "IO Interface". This describes how the component can be interacted with in the "subsystem layer". It essentially describes things like "you can tell the motor to run at this voltage" or "you can tell the motor to spin at this angular velocity". The implementation is NOT defined in the interface.
    2. The "IO Implementation" classes. Generally, there will be two of these, one for real hardware, and one for simulated hardware. These are essentially responsible for tasks like "the subsystem layer wants the motor to spin at 12 volts, so I'll tell the real TalonFX motor controller to apply 12 volts" or "the subsystem layer wants to turn off the motor, so I'll tell the simulated motor its velocity is now zero".
    3. The "IO Inputs" class. This is a container for all of the inputs we can read from the physical layer. This primarily includes sensor values, including applied voltage and current draw for motors, potentiometer readings, etc. The class defines which inputs are logged, and the "IO Implementation" classes are responsible for reading the inputs once per periodic.
  • In the "subsystem layer", commands will be defined in an isolated nested class that acts as a "command factory". The intent is that rather than having a function called setVolts that sets the motor volts and a function called cmdSetVolts which returns a command to execute the setVolts function, you can instead get the command by calling _component.commands.setVolts();. Not strictly necessary, but the code looks nicer in my opinion.

Code Structure

The overall design for the rotor code looks something like this:

erDiagram
    Rotor ||--|| RotorIO : "uses"
    RotorIO ||--|| RotorIOReal : "is (real robot)"
    RotorIO ||--|| RotorIOSim : "is (simulated robot)"
    Rotor ||--|| RotorIOInputs : "uses"
    RotorIOInputs ||--|| RotorIOReal : "provides"
    RotorIOInputs ||--|| RotorIOSim : "provides"
Loading

Rotor Behavior

The idea for how the rotor will be controlled is simple: instead of supplying a voltage when turning the rotor on, we will now supply an angular velocity. This will allow us to feed fuel into the feeder more consistently and under different loads (e.g. low battery or full hopper).

The PID controller for velocity control will need some tuning. I set up simulation to get something close to make sure the logic was behaving mostly correct. When setting the desired velocity to 100 RPM, I get the below plots of applied voltage and measured velocity:

image

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.

1 participant