Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
WispySparks committed Oct 24, 2024
1 parent bfd8812 commit 6c9134b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import edu.wpi.first.math.MathUtil;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.shuffleboard.BuiltInWidgets;
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
Expand Down Expand Up @@ -33,10 +35,11 @@ public Robot() {
// xboxController.getHID()::getBButton
// );

var slider = Shuffleboard.getTab("testing").add("Speed", 0).withWidget(BuiltInWidgets.kNumberSlider).getEntry();
// Fill in parameter info
Command driveFieldOrientedAngularVelocity = swerve.driveCommand(
() -> MathUtil.applyDeadband(-xboxController.getLeftY(), DriveK.leftJoystickDeadband),
() -> MathUtil.applyDeadband(-xboxController.getLeftX(), DriveK.leftJoystickDeadband),
() -> slider.getDouble(0),
() -> MathUtil.applyDeadband(-xboxController.getRightX(), DriveK.rightJoystickDeadband)
);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/frc/robot/subsystems/Swerve.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class Swerve extends SubsystemBase {
* @param directory Directory of swerve drive config files.
*/
public Swerve() {
double angleConversionFactor = SwerveMath.calculateDegreesPerSteeringRotation(SwerveK.steerGearRatio);
double angleConversionFactor = SwerveMath.calculateDegreesPerSteeringRotation(SwerveK.steerGearRatio, 4096);
double driveConversionFactor = SwerveMath.calculateMetersPerRotation(SwerveK.driveGearRatio, SwerveK.wheelDiameter.in(Inches));

SwerveDriveTelemetry.verbosity = TelemetryVerbosity.HIGH;
Expand Down Expand Up @@ -95,7 +95,7 @@ public Command driveCommand(DoubleSupplier TranslationX, DoubleSupplier Translat
return runOnce(() -> drive(
new Translation2d(TranslationX.getAsDouble() * swerveDrive.getMaximumVelocity(), TranslationY.getAsDouble() * swerveDrive.getMaximumVelocity()),
angularVelocity.getAsDouble() * swerveDrive.getMaximumAngularVelocity(),
true, true));
false, true));
}

public Command turnCommand(Measure<Angle> targetAngle, Measure<Angle> currentAngle, boolean fieldRelative) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/swervelib/SwerveModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.revrobotics.CANSparkMax;
import com.revrobotics.MotorFeedbackSensor;

import edu.wpi.first.math.controller.SimpleMotorFeedforward;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.kinematics.SwerveModulePosition;
Expand Down Expand Up @@ -386,13 +387,15 @@ public void setDesiredState(SwerveModuleState desiredState, boolean isOpenLoop,
if (absoluteEncoder != null && synchronizeEncoderQueued && synchronizeEncoderEnabled)
{
double absoluteEncoderPosition = getAbsolutePosition();
// System.out.println(absoluteEncoderPosition);
if(Math.abs(angleMotor.getPosition() - absoluteEncoderPosition) >= synchronizeEncoderDeadband) {
angleMotor.setPosition(absoluteEncoderPosition);
}
angleMotor.setReference(desiredState.angle.getDegrees(), 0, absoluteEncoderPosition);
synchronizeEncoderQueued = false;
} else
{
// System.out.println("set reference + " + desiredState.angle.getDegrees());
angleMotor.setReference(desiredState.angle.getDegrees(), 0);
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/swervelib/motors/TalonSRXSwerve.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.ctre.phoenix.motorcontrol.StatusFrameEnhanced;
import com.ctre.phoenix.motorcontrol.can.TalonSRXConfiguration;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;

import swervelib.encoders.SwerveAbsoluteEncoder;
import swervelib.math.SwerveMath;
import swervelib.parser.PIDFConfig;
Expand Down Expand Up @@ -265,6 +266,7 @@ public double convertToNativeSensorUnits(double setpoint, double position)
{
setpoint =
isDriveMotor ? setpoint * .1 : SwerveMath.placeInAppropriate0To360Scope(position, setpoint);
System.out.println(motor.getDeviceID() + ": Setpoint: " + setpoint);
return setpoint / positionConversionFactor;
}

Expand Down Expand Up @@ -292,7 +294,7 @@ public void setReference(double setpoint, double feedforward, double position)
{

burnFlash();

// System.out.println(motor.getDeviceID() + ": Setpoint: " + setpoint + " Position: " + position + " Native Setpoint: " + convertToNativeSensorUnits(setpoint, position));
motor.set(
isDriveMotor ? ControlMode.Velocity : ControlMode.Position,
convertToNativeSensorUnits(setpoint, position),
Expand Down Expand Up @@ -363,6 +365,7 @@ public double getPosition()
{
pos += 360;
}
// System.out.println(pos + " " + pos % 360);
return pos;
}
}
Expand Down

0 comments on commit 6c9134b

Please sign in to comment.