This repository has been archived by the owner on May 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae9d860
commit 5815b70
Showing
3 changed files
with
57 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package frc.robot.intake; | ||
|
||
import edu.wpi.first.math.controller.SimpleMotorFeedforward; | ||
import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
import com.ctre.phoenix6.hardware.TalonFX; | ||
import com.ctre.phoenix6.signals.NeutralModeValue; | ||
import frc.lib.Configurator; | ||
|
||
/** Roller motor using a TalonFX. */ | ||
public class RollerMotorIOTalonFX implements RollerMotorIO { | ||
|
||
private final TalonFX topTalonFX, bottomTalonFX; | ||
|
||
private final SimpleMotorFeedforward topFeedforward, bottomFeedforward; | ||
|
||
public RollerMotorIOTalonFX() { | ||
topTalonFX = new TalonFX(0); // TODO | ||
bottomTalonFX = new TalonFX(0); // TODO | ||
|
||
topFeedforward = new SimpleMotorFeedforward(0, 0); // TODO | ||
bottomFeedforward = new SimpleMotorFeedforward(0, 0); // TODO | ||
} | ||
|
||
@Override | ||
public void configure() { | ||
final TalonFXConfiguration config = new TalonFXConfiguration(); | ||
|
||
config.Feedback.SensorToMechanismRatio = 1.0; // TODO | ||
|
||
config.MotorOutput.NeutralMode = NeutralModeValue.Coast; | ||
|
||
Configurator.configureTalonFX(topTalonFX.getConfigurator(), config); | ||
Configurator.configureTalonFX(bottomTalonFX.getConfigurator(), config); | ||
} | ||
|
||
@Override | ||
public void update(RollerMotorIOValues values) { | ||
values.velocityRotationsPerSecond = getVelocity(); | ||
values.currentAmps = topTalonFX.getStatorCurrent().refresh().getValue(); | ||
} | ||
|
||
@Override | ||
public void setSetpoint(double velocityRotationsPerSecond) { | ||
double topVolts = topFeedforward.calculate(velocityRotationsPerSecond); | ||
|
||
topTalonFX.setVoltage(topVolts); | ||
|
||
double bottomVolts = bottomFeedforward.calculate(velocityRotationsPerSecond); | ||
|
||
bottomTalonFX.setVoltage(bottomVolts); | ||
} | ||
|
||
public double getVelocity() { | ||
return topTalonFX.getVelocity().refresh().getValue(); | ||
} | ||
} |