-
Notifications
You must be signed in to change notification settings - Fork 1
Update swerve module code to work with TalonFX #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,9 +7,10 @@ | |
|
|
||
| package frc.robot; | ||
|
|
||
| import com.ctre.phoenix.motorcontrol.TalonFXControlMode; | ||
| import com.ctre.phoenix.motorcontrol.can.TalonFX; | ||
|
|
||
| import edu.wpi.first.wpilibj.Encoder; | ||
| import edu.wpi.first.wpilibj.PWMVictorSPX; | ||
| import edu.wpi.first.wpilibj.SpeedController; | ||
| import edu.wpi.first.wpilibj.controller.PIDController; | ||
| import edu.wpi.first.wpilibj.controller.ProfiledPIDController; | ||
| import edu.wpi.first.wpilibj.geometry.Rotation2d; | ||
|
|
@@ -24,8 +25,8 @@ public class SwerveModule { | |
| private static final double kModuleMaxAngularAcceleration | ||
| = 2 * Math.PI; // radians per second squared | ||
|
|
||
| private final SpeedController m_driveMotor; | ||
| private final SpeedController m_turningMotor; | ||
| private final TalonFX m_driveMotor; | ||
| private final TalonFX m_turningMotor; | ||
|
|
||
| private final Encoder m_driveEncoder = new Encoder(0, 1); | ||
| private final Encoder m_turningEncoder = new Encoder(2, 3); | ||
|
|
@@ -43,8 +44,8 @@ public class SwerveModule { | |
| * @param turningMotorChannel ID for the turning motor. | ||
| */ | ||
| public SwerveModule(int driveMotorChannel, int turningMotorChannel) { | ||
| m_driveMotor = new PWMVictorSPX(driveMotorChannel); | ||
| m_turningMotor = new PWMVictorSPX(turningMotorChannel); | ||
| m_driveMotor = new TalonFX(driveMotorChannel); | ||
| m_turningMotor = new TalonFX(turningMotorChannel); | ||
|
|
||
| // Set the distance per pulse for the drive encoder. We can simply use the | ||
| // distance traveled for one rotation of the wheel divided by the encoder | ||
|
|
@@ -86,7 +87,7 @@ public void setDesiredState(SwerveModuleState state) { | |
| ); | ||
|
|
||
| // Calculate the turning motor output from the turning PID controller. | ||
| m_driveMotor.set(driveOutput); | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the sample code using PWM VictorSPX motor controller (looks like this), this was previously expecting values of For TalonFX we need to create the same behavior. How can we do this? We can do a hover over ctrl + click (same content different format) This is how we can get information on how to use the libraries provided by wpi and external vendors. |
||
| m_turningMotor.set(turnOutput); | ||
| m_driveMotor.set(TalonFXControlMode.PercentOutput, driveOutput); | ||
| m_turningMotor.set(TalonFXControlMode.PercentOutput, turnOutput); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,234 @@ | ||
| { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We needed to add this external vendor library or the code will not compile. Basically looked on google for "phoenix talon fx java frc" There's a lot of subjects but the one we needed was this: https://docs.ctre-phoenix.com/en/latest/ch05a_CppJava.html#frc-c-java-add-phoenix So I followed the steps and visited https://maven.ctr-electronics.com/release/com/ctre/phoenix/Phoenix-latest.json and just copy pasted the content to Phoenix.json like we do for FalconRecharged2021 code. We can do similar thought process for other libraries: look at documentation. There might even be FRC friendly docs like for there was for Phoenix. |
||
| "fileName": "Phoenix.json", | ||
| "name": "CTRE-Phoenix", | ||
| "version": "5.20.0-beta-1", | ||
| "uuid": "ab676553-b602-441f-a38d-f1296eff6537", | ||
| "mavenUrls": [ | ||
| "https://maven.ctr-electronics.com/release/" | ||
| ], | ||
| "jsonUrl": "https://maven.ctr-electronics.com/release/com/ctre/phoenix/Phoenix-latest.json", | ||
| "javaDependencies": [ | ||
| { | ||
| "groupId": "com.ctre.phoenix", | ||
| "artifactId": "api-java", | ||
| "version": "5.20.0" | ||
| }, | ||
| { | ||
| "groupId": "com.ctre.phoenix", | ||
| "artifactId": "wpiapi-java", | ||
| "version": "5.20.0" | ||
| } | ||
| ], | ||
| "jniDependencies": [ | ||
| { | ||
| "groupId": "com.ctre.phoenix", | ||
| "artifactId": "cci", | ||
| "version": "5.20.0", | ||
| "isJar": false, | ||
| "skipInvalidPlatforms": true, | ||
| "validPlatforms": [ | ||
| "linuxathena" | ||
| ] | ||
| }, | ||
| { | ||
| "groupId": "com.ctre.phoenix.sim", | ||
| "artifactId": "cci-sim", | ||
| "version": "5.20.0", | ||
| "isJar": false, | ||
| "skipInvalidPlatforms": true, | ||
| "validPlatforms": [ | ||
| "windowsx86-64", | ||
| "linuxx86-64", | ||
| "osxx86-64" | ||
| ] | ||
| }, | ||
| { | ||
| "groupId": "com.ctre.phoenix.sim", | ||
| "artifactId": "simTalonSRX", | ||
| "version": "5.20.0", | ||
| "isJar": false, | ||
| "skipInvalidPlatforms": true, | ||
| "validPlatforms": [ | ||
| "windowsx86-64", | ||
| "linuxx86-64", | ||
| "osxx86-64" | ||
| ] | ||
| }, | ||
| { | ||
| "groupId": "com.ctre.phoenix.sim", | ||
| "artifactId": "simTalonFX", | ||
| "version": "5.20.0", | ||
| "isJar": false, | ||
| "skipInvalidPlatforms": true, | ||
| "validPlatforms": [ | ||
| "windowsx86-64", | ||
| "linuxx86-64", | ||
| "osxx86-64" | ||
| ] | ||
| }, | ||
| { | ||
| "groupId": "com.ctre.phoenix.sim", | ||
| "artifactId": "simVictorSPX", | ||
| "version": "5.20.0", | ||
| "isJar": false, | ||
| "skipInvalidPlatforms": true, | ||
| "validPlatforms": [ | ||
| "windowsx86-64", | ||
| "linuxx86-64", | ||
| "osxx86-64" | ||
| ] | ||
| }, | ||
| { | ||
| "groupId": "com.ctre.phoenix.sim", | ||
| "artifactId": "simPigeonIMU", | ||
| "version": "5.20.0", | ||
| "isJar": false, | ||
| "skipInvalidPlatforms": true, | ||
| "validPlatforms": [ | ||
| "windowsx86-64", | ||
| "linuxx86-64", | ||
| "osxx86-64" | ||
| ] | ||
| }, | ||
| { | ||
| "groupId": "com.ctre.phoenix.sim", | ||
| "artifactId": "simCANCoder", | ||
| "version": "5.20.0", | ||
| "isJar": false, | ||
| "skipInvalidPlatforms": true, | ||
| "validPlatforms": [ | ||
| "windowsx86-64", | ||
| "linuxx86-64", | ||
| "osxx86-64" | ||
| ] | ||
| } | ||
| ], | ||
| "cppDependencies": [ | ||
| { | ||
| "groupId": "com.ctre.phoenix", | ||
| "artifactId": "wpiapi-cpp", | ||
| "version": "5.20.0", | ||
| "libName": "CTRE_Phoenix_WPI", | ||
| "headerClassifier": "headers", | ||
| "sharedLibrary": true, | ||
| "skipInvalidPlatforms": true, | ||
| "binaryPlatforms": [ | ||
| "linuxathena", | ||
| "windowsx86-64", | ||
| "linuxx86-64", | ||
| "osxx86-64" | ||
| ] | ||
| }, | ||
| { | ||
| "groupId": "com.ctre.phoenix", | ||
| "artifactId": "api-cpp", | ||
| "version": "5.20.0", | ||
| "libName": "CTRE_Phoenix", | ||
| "headerClassifier": "headers", | ||
| "sharedLibrary": true, | ||
| "skipInvalidPlatforms": true, | ||
| "binaryPlatforms": [ | ||
| "linuxathena", | ||
| "windowsx86-64", | ||
| "linuxx86-64", | ||
| "osxx86-64" | ||
| ] | ||
| }, | ||
| { | ||
| "groupId": "com.ctre.phoenix", | ||
| "artifactId": "cci", | ||
| "version": "5.20.0", | ||
| "libName": "CTRE_PhoenixCCI", | ||
| "headerClassifier": "headers", | ||
| "sharedLibrary": true, | ||
| "skipInvalidPlatforms": true, | ||
| "binaryPlatforms": [ | ||
| "linuxathena" | ||
| ] | ||
| }, | ||
| { | ||
| "groupId": "com.ctre.phoenix.sim", | ||
| "artifactId": "cci-sim", | ||
| "version": "5.20.0", | ||
| "libName": "CTRE_PhoenixCCISim", | ||
| "headerClassifier": "headers", | ||
| "sharedLibrary": true, | ||
| "skipInvalidPlatforms": true, | ||
| "binaryPlatforms": [ | ||
| "windowsx86-64", | ||
| "linuxx86-64", | ||
| "osxx86-64" | ||
| ] | ||
| }, | ||
| { | ||
| "groupId": "com.ctre.phoenix.sim", | ||
| "artifactId": "simTalonSRX", | ||
| "version": "5.20.0", | ||
| "libName": "CTRE_SimTalonSRX", | ||
| "headerClassifier": "headers", | ||
| "sharedLibrary": true, | ||
| "skipInvalidPlatforms": true, | ||
| "binaryPlatforms": [ | ||
| "windowsx86-64", | ||
| "linuxx86-64", | ||
| "osxx86-64" | ||
| ] | ||
| }, | ||
| { | ||
| "groupId": "com.ctre.phoenix.sim", | ||
| "artifactId": "simTalonFX", | ||
| "version": "5.20.0", | ||
| "libName": "CTRE_SimTalonFX", | ||
| "headerClassifier": "headers", | ||
| "sharedLibrary": true, | ||
| "skipInvalidPlatforms": true, | ||
| "binaryPlatforms": [ | ||
| "windowsx86-64", | ||
| "linuxx86-64", | ||
| "osxx86-64" | ||
| ] | ||
| }, | ||
| { | ||
| "groupId": "com.ctre.phoenix.sim", | ||
| "artifactId": "simVictorSPX", | ||
| "version": "5.20.0", | ||
| "libName": "CTRE_SimVictorSPX", | ||
| "headerClassifier": "headers", | ||
| "sharedLibrary": true, | ||
| "skipInvalidPlatforms": true, | ||
| "binaryPlatforms": [ | ||
| "windowsx86-64", | ||
| "linuxx86-64", | ||
| "osxx86-64" | ||
| ] | ||
| }, | ||
| { | ||
| "groupId": "com.ctre.phoenix.sim", | ||
| "artifactId": "simPigeonIMU", | ||
| "version": "5.20.0", | ||
| "libName": "CTRE_SimPigeonIMU", | ||
| "headerClassifier": "headers", | ||
| "sharedLibrary": true, | ||
| "skipInvalidPlatforms": true, | ||
| "binaryPlatforms": [ | ||
| "windowsx86-64", | ||
| "linuxx86-64", | ||
| "osxx86-64" | ||
| ] | ||
| }, | ||
| { | ||
| "groupId": "com.ctre.phoenix.sim", | ||
| "artifactId": "simCANCoder", | ||
| "version": "5.20.0", | ||
| "libName": "CTRE_SimCANCoder", | ||
| "headerClassifier": "headers", | ||
| "sharedLibrary": true, | ||
| "skipInvalidPlatforms": true, | ||
| "binaryPlatforms": [ | ||
| "windowsx86-64", | ||
| "linuxx86-64", | ||
| "osxx86-64" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||



There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to address these todos before deploying the code.
Please remove after it is done.