Skip to content
This repository has been archived by the owner on May 19, 2024. It is now read-only.

Commit

Permalink
WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenheroux committed Jan 18, 2024
1 parent c6de123 commit c11044e
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 12 deletions.
29 changes: 29 additions & 0 deletions .Glass/glass.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"NetworkTables": {
"transitory": {
"Shuffleboard": {
"Swerve": {
"Module 0": {
"open": true
},
"open": true
},
"open": true
},
"steerMotorIOTalonFX": {
"open": true
}
},
"types": {
"/FMSInfo": "FMSInfo",
"/Shuffleboard/Auto/Auto Chooser": "String Chooser"
}
},
"NetworkTables Info": {
"visible": true
},
"NetworkTables Settings": {
"mode": "Client (NT4)",
"serverTeam": "5112"
}
}
6 changes: 4 additions & 2 deletions simgui.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
}
},
"NetworkTables": {
"Retained Values": {
"open": false
},
"transitory": {
"Shuffleboard": {
"Swerve": {
Expand All @@ -30,8 +33,7 @@
},
"North East Module": {
"open": true
},
"open": true
}
},
"open": true
},
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/frc/robot/odometry/GyroscopeIOPigeon2.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public void update(GyroscopeIOValues values) {
pitch.refresh();
yaw.refresh();

values.rollRotations = roll.getValue();
values.pitchRotations = pitch.getValue();
values.yawRotations = yaw.getValue();
values.rollRotations = Units.degreesToRotations(roll.getValue());
values.pitchRotations = Units.degreesToRotations(pitch.getValue());
values.yawRotations = Units.degreesToRotations(yaw.getValue());
}

@Override
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/frc/robot/swerve/SteerMotorIOTalonFX.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import com.ctre.phoenix6.BaseStatusSignal;
import com.ctre.phoenix6.StatusSignal;
import com.ctre.phoenix6.hardware.TalonFX;

import edu.wpi.first.networktables.BooleanEntry;
import edu.wpi.first.networktables.DoubleEntry;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableInstance;
import frc.lib.CAN;

/** TalonFX steer motor. */
Expand All @@ -17,6 +22,10 @@ public abstract class SteerMotorIOTalonFX implements SteerMotorIO {
/** CAN identifier for the steer motor's corresponding azimuth encoder. */
protected final CAN azimuthEncoderCAN;

/** NetworkTable entry for setting voltage. */
protected final DoubleEntry setVoltageEntry;
protected final BooleanEntry setVoltageEnableEntry;

/**
* Creates a new TalonFX steer motor.
*
Expand All @@ -31,6 +40,20 @@ public SteerMotorIOTalonFX(CAN steerMotorCAN, CAN azimuthEncoderCAN) {
velocityRotationsPerSecond = talonFX.getVelocity();

this.azimuthEncoderCAN = azimuthEncoderCAN;

NetworkTable table = NetworkTableInstance.getDefault().getTable("steerMotorIOTalonFX");

setVoltageEntry =
table.getDoubleTopic("setVoltage")
.getEntry(0);

setVoltageEntry.set(0);

setVoltageEnableEntry =
table.getBooleanTopic("setVoltageEnable")
.getEntry(false);

setVoltageEnableEntry.set(false);
}

@Override
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/frc/robot/swerve/SteerMotorIOTalonFXPID.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ public void configure() {

@Override
public void setSetpoint(double positionRotations) {
positionFeedback.setSetpoint(positionRotations);

if (positionFeedback.atSetpoint()) {
talonFX.setControl(new CoastOut());
if (setVoltageEnableEntry.get()) {
talonFX.setControl(new VoltageOut(setVoltageEntry.get()));
} else {
talonFX.setControl(calculatePositionVoltage());
positionFeedback.setSetpoint(positionRotations);

if (positionFeedback.atSetpoint()) {
talonFX.setControl(new CoastOut());
} else {
talonFX.setControl(calculatePositionVoltage());
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/frc/robot/swerve/Swerve.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public void addToShuffleboard(ShuffleboardTab tab) {
swerveModuleColumn.addDouble("Angle (deg)", () -> swerveModule.getState().angle.getDegrees());
swerveModuleColumn.addDouble(
"Velocity (mps)", () -> swerveModule.getState().speedMetersPerSecond);
swerveModuleColumn.addDouble("Setpoint Angle (deg)", () -> swerveModule.getSetpoint().angle.getDegrees());
swerveModuleColumn.addDouble(
"Setpoint Velocity (mps)", () -> swerveModule.getSetpoint().speedMetersPerSecond);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/swerve/SwerveConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static class MK4iConstants {
/** Constants for steer feedback controllers. */
public static class SteerMotorConstants {
/** Feedback tolerance. */
public static final Rotation2d TOLERANCE = Rotation2d.fromDegrees(1.0);
public static final Rotation2d TOLERANCE = Rotation2d.fromDegrees(3);

/** Feedback proportional gain in volts per rotation. */
public static final double FEEDBACK_KP = 32.0;
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/frc/robot/swerve/SwerveModuleIOCustom.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,16 @@ public void setSetpoint(SwerveModuleState setpoint, boolean lazy) {
* @return the optimized setpoint.
*/
private SwerveModuleState optimize(SwerveModuleState setpoint, SwerveModuleState state) {
return SwerveModuleState.optimize(setpoint, state.angle);
setpoint = SwerveModuleState.optimize(setpoint, state.angle);

final double kDejitterThreshold = 0.01;

if (Math.abs(setpoint.speedMetersPerSecond) < kDejitterThreshold) {
setpoint.angle = state.angle;
setpoint.speedMetersPerSecond = 0.0;
}

return setpoint;
}

@Override
Expand Down

0 comments on commit c11044e

Please sign in to comment.