Skip to content

Commit

Permalink
use a secondary variable for velocity multipliers on arm
Browse files Browse the repository at this point in the history
  • Loading branch information
GearBoxFox committed Mar 12, 2024
1 parent fc384e1 commit 8bde48a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
26 changes: 8 additions & 18 deletions src/main/java/frc/robot/subsystems/arm/ArmIOKraken.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public class ArmIOKraken implements ArmIO {
private final HeavyDoubleProperty m_wristMaxVelDegS;
private final HeavyDoubleProperty m_accelTimeSecs;

private final MotionMagicConfigs m_armMMConfigs = new MotionMagicConfigs();
private final MotionMagicConfigs m_wristMMConfigs = new MotionMagicConfigs();
private double m_armMaxVel;
private double m_wristMaxVel;

// Control outputs
private final DynamicMotionMagicVoltage m_wristDynMMRequest;
Expand All @@ -51,8 +51,6 @@ public class ArmIOKraken implements ArmIO {
private final Follower m_wristFollowerRequest;
private final NeutralOut m_stopRequest;

private boolean m_tracking = false;

private double m_prevArmVelocityMult = 0.0;
private double m_prevWristVelocityMult = 0.0;

Expand Down Expand Up @@ -141,16 +139,16 @@ public ArmIOKraken() {
.build();

m_armMaxVelDegS = new HeavyDoubleProperty(
(double maxVel) -> m_armDynMMRequest.Velocity = Units.degreesToRotations(maxVel),
(double maxVel) -> m_armMaxVel = Units.degreesToRotations(maxVel),
new GosDoubleProperty(false, "Arm/Arm Max Vel DegsS", 120));

m_wristMaxVelDegS = new HeavyDoubleProperty(
(double maxVel) -> m_wristDynMMRequest.Velocity = Units.degreesToRotations(maxVel),
(double maxVel) -> m_wristMaxVel = Units.degreesToRotations(maxVel),
new GosDoubleProperty(false, "Arm/Wrist Max Vel DegsS", 120));

m_accelTimeSecs = new HeavyDoubleProperty((double accel) -> {
m_armDynMMRequest.Acceleration = m_armDynMMRequest.Velocity / accel;
m_wristDynMMRequest.Acceleration = m_wristDynMMRequest.Velocity / accel;
m_armDynMMRequest.Acceleration = m_armMaxVel / accel;
m_wristDynMMRequest.Acceleration = m_wristMaxVel / accel;
}, new GosDoubleProperty(false, "Arm/Acceleration Time Secs", 1));

m_armMaxVelDegS.updateIfChanged(true);
Expand Down Expand Up @@ -256,11 +254,7 @@ public void setArmVoltage(double voltage) {

@Override
public void setArmAngle(double degrees, double velocityMult) {
if (m_prevArmVelocityMult != velocityMult) {
m_armMaxVelDegS.updateIfChanged(true);
}
m_prevArmVelocityMult = velocityMult;
m_armDynMMRequest.Velocity = m_armDynMMRequest.Velocity * velocityMult;
m_armDynMMRequest.Velocity = m_armMaxVel * velocityMult;

m_armMaster.setControl(m_armDynMMRequest.withPosition(degrees / 360));
m_armFollower.setControl(m_armFollowerRequest);
Expand All @@ -274,11 +268,7 @@ public void setWristVoltage(double voltage) {

@Override
public void setWristAngle(double degrees, double velocityMult) {
if (m_prevWristVelocityMult != velocityMult) {
m_wristMaxVelDegS.updateIfChanged(true);
}
m_prevWristVelocityMult = velocityMult;
m_wristDynMMRequest.Velocity = m_wristDynMMRequest.Velocity * velocityMult;
m_wristDynMMRequest.Velocity = m_wristMaxVel * velocityMult;

m_wristMaster.setControl(m_wristDynMMRequest.withPosition(degrees / 360));
m_wristFollower.setControl(m_wristFollowerRequest);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/frc/robot/subsystems/drive/DriveSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,16 +293,16 @@ public void periodic() {
public void runVelocity(ChassisSpeeds speeds) {
// Calculate module setpoints
ChassisSpeeds discreteSpeeds = ChassisSpeeds.discretize(speeds, 0.02);
SwerveModuleState[] m_setpointStates = kinematics.toSwerveModuleStates(discreteSpeeds);
SwerveDriveKinematics.desaturateWheelSpeeds(m_setpointStates, DriveConstants.MAX_LINEAR_SPEED);
SwerveModuleState[] setpointStates = kinematics.toSwerveModuleStates(discreteSpeeds);
SwerveDriveKinematics.desaturateWheelSpeeds(setpointStates, DriveConstants.MAX_LINEAR_SPEED);

// Send setpoints to modules
for (int i = 0; i < 4; i++) {
// The module returns the optimized state, useful for logging
m_optimizedStates[i] = modules[i].runSetpoint(m_setpointStates[i]);
m_optimizedStates[i] = modules[i].runSetpoint(setpointStates[i]);
}

Logger.recordOutput("SwerveStates/Setpoints", m_setpointStates);
Logger.recordOutput("SwerveStates/Setpoints", setpointStates);
Logger.recordOutput("SwerveStates/Optimized", m_optimizedStates);
}

Expand Down

0 comments on commit 8bde48a

Please sign in to comment.