-
Notifications
You must be signed in to change notification settings - Fork 0
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
Abigail swrve x stance #12
base: main
Are you sure you want to change the base?
Changes from all commits
526672c
1acca00
1c818f6
5818cd1
8478e17
3518058
1e0ae18
27d0ca0
33a86ec
33638fd
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"enableCppIntellisense": false, | ||
"currentLanguage": "java", | ||
"projectYear": "2025beta", | ||
"projectYear": "2025", | ||
"teamNumber": 4829 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
package frc.robot.commands.drive; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.robot.subsystems.swerve.SwerveConstants; | ||
|
||
/* You should consider using the more terse Command factories API instead https://docs.wpilib.org/en/stable/docs/software/commandbased/organizing-command-based.html#defining-commands */ | ||
public class XSwerve extends Command { | ||
/** Creates a new XSwerve. */ | ||
public XSwerve() { | ||
SwerveConstants swerveConstants; | ||
// Use addRequirements() here to declare subsystem dependencies. | ||
} | ||
|
||
// Called when the command is initially scheduled. | ||
@Override | ||
public void initialize() { | ||
if | ||
} | ||
|
||
// Called every time the scheduler runs while the command is scheduled. | ||
@Override | ||
public void execute() {} | ||
|
||
// Called once the command ends or is interrupted. | ||
@Override | ||
public void end(boolean interrupted) {} | ||
|
||
// Returns true when the command should end. | ||
@Override | ||
public boolean isFinished() { | ||
return false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,8 @@ | |
import java.util.Optional; | ||
import org.littletonrobotics.junction.AutoLogOutput; | ||
import org.littletonrobotics.junction.Logger; | ||
import java.util.Timer; | ||
import java.util.TimerTask; | ||
|
||
public class SwerveDrive extends SubsystemBase { | ||
private final GyroInterface gyroIO; | ||
|
@@ -276,8 +278,34 @@ public Rotation2d getOdometryAllianceRelativeRotation2d() { | |
public void setModuleStates(SwerveModuleState[] desiredStates) { | ||
for (int i = 0; i < 4; i++) { | ||
swerveModules[i].runSetPoint((desiredStates[i])); | ||
} | ||
} | ||
} | ||
|
||
private boolean isMoving; // Tracks if the robot is moving | ||
private long lastMovementTime = System.currentTimeMillis(); // Time of the last movement | ||
private static final long INACTIVITY_THRESHOLD = 3000; // 3 seconds in milliseconds | ||
|
||
// Check if the robot has been inactive for 3 seconds | ||
public boolean threesecsinactive() { | ||
if (!isMoving && System.currentTimeMillis() - lastMovementTime >= INACTIVITY_THRESHOLD) { | ||
return true; // 3 seconds of inactivity | ||
} | ||
return false; // Still moving or not enough time passed | ||
} | ||
|
||
public void setXStance(SwerveModuleState[] xState) { | ||
isMoving = false; | ||
if (threesecsinactive()) { // Only lock if inactive for 3 seconds | ||
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. honestly this not rlly the best way of doing it. also the setXStance isn't used anywhere sooooooooo it wouldn't actually happen. 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. imo u could use wpilib's timer or the fpga clock and get if some amount of time has passed. 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. u might want to separate the if statement out of the method bc we want the thing that does the xStance to be usable in other contexts. In addition, we might also make it a button, so another reason to move the if statement out. If you want to do the three seconds (which we might do) you could maybe put it in something like setModuleStates or drive? |
||
Rotation2d[] swerveHeadings = new Rotation2d[swerveModules.length]; | ||
for (int i = 0; i < swerveHeadings.length; i++) { | ||
swerveHeadings[i] = swerveModules[i].getPosition().angle; | ||
} | ||
DriveConstants.DRIVE_KINEMATICS.resetHeadings(swerveHeadings); | ||
for (int i = 0; i < swerveModules.length; i++) { | ||
swerveModules[i].stopModule(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Updates the pose estimator with the pose calculated from the swerve modules. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,9 @@ public void runSetPoint(SwerveModuleState state) { | |
Logger.recordOutput("Drive/desired turn angle", state.angle.getRotations()); | ||
} | ||
|
||
public void stopModule() { | ||
io.stopModule(); | ||
} | ||
/** Returns the current turn angle of the module. */ | ||
public Rotation2d getTurnRotation() { | ||
return inputs.turnAbsolutePosition; | ||
|
@@ -77,6 +80,10 @@ public double getTurnVelocity() { | |
return inputs.turnVelocity; | ||
} | ||
|
||
public void xthing(double desiredPositionDegrees) { | ||
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. dont think u need this |
||
io.xthing(desiredPositionDegrees); | ||
} | ||
|
||
/** Returns the current drive position of the module in meters. */ | ||
public double getDrivePositionMeters() { | ||
return ModuleConstants.WHEEL_CIRCUMFERENCE_METERS * inputs.drivePosition; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,6 +187,11 @@ public double getTurnRotations() { | |
.getRotations(); | ||
} | ||
|
||
@Override | ||
public void xthing(double desiredPositionDegrees) { | ||
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. make a better name 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. actually i dont think this is used in the code so u should just delete it |
||
turnMotor.setControl(mmPositionRequest.withPosition(Degrees.of(desiredPositionDegrees))); | ||
} | ||
|
||
@Override | ||
public void stopModule() { | ||
driveMotor.stopMotor(); | ||
|
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.
If ur not gonna use this plz delete