Skip to content

Commit 47cdc54

Browse files
committed
trying to get drive to work it's skewing a lot idk why
1 parent 89352ba commit 47cdc54

File tree

6 files changed

+57
-16
lines changed

6 files changed

+57
-16
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@ A base project for future robots that has CTRE generated swerve drive code and P
77
- Swerve drive code using CTRE's swerve code generator.
88
- Device logging with SignalLogger and data logging with Epilogue and DogLog.
99

10+
# Todo
11+
- Add the working stuff from other SwerveBase (fault logger, photon vision code).
12+
- Add WPILib testing?
13+
1014
## 2025 Beta Known Issues
1115
- To run sim, do `./gradlew simulateJava` instead of using the WPILib extension.

simgui-ds.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121
"incKey": 83
2222
},
2323
{
24-
"decKey": 69,
25-
"incKey": 82,
2624
"keyRate": 0.009999999776482582
25+
},
26+
{},
27+
{
28+
"decKey": 263,
29+
"incKey": 262
2730
}
2831
],
29-
"axisCount": 3,
32+
"axisCount": 5,
3033
"buttonCount": 4,
3134
"buttonKeys": [
3235
90,
@@ -71,10 +74,7 @@
7174
},
7275
{
7376
"axisConfig": [
74-
{
75-
"decKey": 263,
76-
"incKey": 262
77-
},
77+
{},
7878
{
7979
"decKey": 265,
8080
"incKey": 264

src/main/java/frc/robot/Constants.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ public static class Ports {
2929
public static class SwerveConstants {
3030
public static final Frequency odometryFrequency = Hertz.of(100);
3131

32-
public static final LinearVelocity translationalDeadband = MetersPerSecond.of(0.1);
33-
public static final AngularVelocity rotationalDeadband = RadiansPerSecond.of(Math.PI * 0.1);
32+
public static final LinearVelocity translationalDeadband = MetersPerSecond.of(0);
33+
public static final AngularVelocity rotationalDeadband = RadiansPerSecond.of(0);
3434

35-
public static final LinearVelocity maxTranslationSpeed = TunerConstants.kSpeedAt12Volts;
35+
public static final LinearVelocity maxTranslationalSpeed = TunerConstants.kSpeedAt12Volts;
3636
public static final AngularVelocity maxAngularSpeed = RadiansPerSecond.of(Math.PI);
3737
}
3838
}

src/main/java/frc/robot/Robot.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import dev.doglog.DogLogOptions;
1212
import edu.wpi.first.epilogue.Epilogue;
1313
import edu.wpi.first.epilogue.Logged;
14-
import edu.wpi.first.epilogue.NotLogged;
14+
import edu.wpi.first.epilogue.Logged.Strategy;
1515
import edu.wpi.first.wpilibj.DriverStation;
1616
import edu.wpi.first.wpilibj.RobotBase;
1717
import edu.wpi.first.wpilibj.TimedRobot;
@@ -30,7 +30,7 @@
3030
* the TimedRobot documentation. If you change the name of this class or the package after creating
3131
* this project, you must also update the Main.java file in the project.
3232
*/
33-
@Logged
33+
@Logged(strategy = Strategy.OPT_IN)
3434
public class Robot extends TimedRobot {
3535
// controllers
3636
private final CommandXboxController _driverController =
@@ -40,7 +40,7 @@ public class Robot extends TimedRobot {
4040
@Logged(name = "Swerve")
4141
private CommandSwerveDrivetrain _swerve = TunerConstants.createDrivetrain();
4242

43-
@NotLogged private Command _autonomousCommand = Autos.none();
43+
private Command _autonomousCommand = Autos.none();
4444

4545
/**
4646
* This function is run when the robot is first started up and should be used for any
@@ -58,10 +58,10 @@ public Robot() {
5858
_swerve.drive(
5959
InputStream.of(_driverController::getLeftY)
6060
.negate()
61-
.scale(SwerveConstants.maxTranslationSpeed.in(MetersPerSecond)),
61+
.scale(SwerveConstants.maxTranslationalSpeed.in(MetersPerSecond)),
6262
InputStream.of(_driverController::getLeftX)
6363
.negate()
64-
.scale(SwerveConstants.maxTranslationSpeed.in(MetersPerSecond)),
64+
.scale(SwerveConstants.maxTranslationalSpeed.in(MetersPerSecond)),
6565
InputStream.of(_driverController::getRightX)
6666
.negate()
6767
.scale(SwerveConstants.maxAngularSpeed.in(RadiansPerSecond))));

src/main/java/frc/robot/generated/TunerConstants.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) FIRST and other WPILib contributors.
22
// Open Source Software; you can modify and/or share it under the terms of
33
// the WPILib BSD license file in the root directory of this project.
4-
54
package frc.robot.generated;
65

76
import static edu.wpi.first.units.Units.*;

src/main/java/frc/robot/subsystems/CommandSwerveDrivetrain.java

+38
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
import dev.doglog.DogLog;
1616
import edu.wpi.first.epilogue.Logged;
1717
import edu.wpi.first.epilogue.Logged.Strategy;
18+
import edu.wpi.first.math.geometry.Pose2d;
19+
import edu.wpi.first.math.geometry.Rotation2d;
1820
import edu.wpi.first.math.kinematics.ChassisSpeeds;
21+
import edu.wpi.first.math.kinematics.SwerveDriveKinematics;
22+
import edu.wpi.first.math.kinematics.SwerveModuleState;
1923
import edu.wpi.first.wpilibj.Notifier;
2024
import edu.wpi.first.wpilibj.RobotBase;
2125
import edu.wpi.first.wpilibj.RobotController;
@@ -83,6 +87,7 @@ public CommandSwerveDrivetrain(
8387
totalDaqs = totalDaqs == 0 ? 1 : totalDaqs;
8488

8589
DogLog.log("Swerve/Odometry Success %", state.SuccessfulDaqs / totalDaqs * 100);
90+
DogLog.log("Swerve/Odometry Period", state.OdometryPeriod);
8691
});
8792

8893
if (RobotBase.isSimulation()) startSimThread();
@@ -129,6 +134,24 @@ public void drive(double velX, double velY, double velOmega) {
129134
_driverChassisSpeeds.vyMetersPerSecond = velY;
130135
_driverChassisSpeeds.omegaRadiansPerSecond = velOmega;
131136

137+
// go through a couple of steps to ensure that input speeds are actually achievable
138+
ChassisSpeeds tempSpeeds = _driverChassisSpeeds;
139+
SwerveModuleState[] tempStates;
140+
141+
if (_isFieldOriented)
142+
tempSpeeds = ChassisSpeeds.fromFieldRelativeSpeeds(tempSpeeds, getHeading());
143+
144+
tempStates = getKinematics().toSwerveModuleStates(tempSpeeds);
145+
SwerveDriveKinematics.desaturateWheelSpeeds(tempStates, SwerveConstants.maxTranslationalSpeed);
146+
tempSpeeds = getKinematics().toChassisSpeeds(tempStates);
147+
148+
if (_isFieldOriented)
149+
tempSpeeds = ChassisSpeeds.fromRobotRelativeSpeeds(tempSpeeds, getHeading());
150+
151+
velX = tempSpeeds.vxMetersPerSecond;
152+
velY = tempSpeeds.vyMetersPerSecond;
153+
velOmega = tempSpeeds.omegaRadiansPerSecond;
154+
132155
if (_isFieldOriented) {
133156
setControl(
134157
_fieldCentricRequest
@@ -170,6 +193,21 @@ public void drive(
170193
.withWheelForceFeedforwardsY(wheelForceFeedforwardsY));
171194
}
172195

196+
/** Wrapper for getting estimated pose. */
197+
public Pose2d getPose() {
198+
return getState().Pose;
199+
}
200+
201+
/** Wrapper for getting estimated heading. */
202+
public Rotation2d getHeading() {
203+
return getPose().getRotation();
204+
}
205+
206+
/** Wrapper for getting current robot-relative chassis speeds. */
207+
public ChassisSpeeds getChassisSpeeds() {
208+
return getState().Speeds;
209+
}
210+
173211
@Override
174212
public void periodic() {
175213
// This method will be called once per scheduler run

0 commit comments

Comments
 (0)