Skip to content
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

Phoenix 6 drivetrain #7

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open

Phoenix 6 drivetrain #7

wants to merge 31 commits into from

Conversation

sleepyghost-zzz
Copy link
Contributor

@sleepyghost-zzz sleepyghost-zzz commented Nov 27, 2024

Purpose
The purpose of this addition is to create a phoenix 6 swerve drivetrain.

Project Scope

  • Add CommandSwerveDrive
  • Sim it
  • Implement CI formatting changes

@sleepyghost-zzz sleepyghost-zzz self-assigned this Nov 27, 2024
Copy link
Member

@jkleiber jkleiber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A first high level pass.

I think we will need to show this working in simulation (both auto and teleop) before merging

src/main/java/frc/robot/RobotContainer.java Outdated Show resolved Hide resolved
src/main/java/frc/robot/generated/TunerConstants.java Outdated Show resolved Hide resolved
src/main/java/frc/robot/RobotContainer.java Outdated Show resolved Hide resolved
src/main/java/frc/robot/RobotContainer.java Outdated Show resolved Hide resolved
src/main/java/frc/robot/RobotContainer.java Outdated Show resolved Hide resolved
src/main/java/frc/robot/RobotContainer.java Outdated Show resolved Hide resolved
src/main/java/frc/robot/RobotContainer.java Outdated Show resolved Hide resolved
@aidnem
Copy link
Contributor

aidnem commented Dec 1, 2024

@jkleiber Format is failing because of an incorrect Java version (I think).
Do you think adding this line to the format task (it's from the build task) would resolve this issue?

    # This grabs the WPILib docker container
    container: wpilib/roborio-cross-ubuntu:2024-22.04

@jkleiber
Copy link
Member

jkleiber commented Dec 1, 2024

@aidnem I haven't checked the docs so take my input with a grain of salt. But I would expect wpilib to update to require 2024 ubuntu. If we have been building against 2022 then a version promotion probably would work fine

@linglejack06
Copy link
Member

@sleepyghost-zzz fyi the drive with joysticks command in copper core is on latest version of beta, so you can try integrating that as well. Otherwise, I can do it when I go to add vision

@sleepyghost-zzz
Copy link
Contributor Author

@linglejack06 Epic, I tried to use the DriveWithJoysticks.java and it didn't quite do what I wanted with the AK project. I'll give it another try, when you start implementing vision if you could walk me through it that would be great.

@linglejack06
Copy link
Member

@sleepyghost-zzz Yeah I'll show you, it's just a matter of creating a method in the Ak drive

@linglejack06
Copy link
Member

@jkleiber @sleepyghost-zzz check out the new template for talon fx swerve on advantage kit release, several changes due to 2025 release differences from beta. heres a link to release: https://github.com/Mechanical-Advantage/AdvantageKit/releases

Copy link
Member

@jkleiber jkleiber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some review comments. I think we should push to get this merged without worrying about photonvision release. We can get auto testing going with just dead reckoning and also figure out how to get TorqueCurrentFOC working while we wait for vision

cc: @aidnem and @linglejack06

.gitignore Show resolved Hide resolved
.wpilib/wpilib_preferences.json Outdated Show resolved Hide resolved
AdvantageKit-License.md Outdated Show resolved Hide resolved
build.gradle Outdated Show resolved Hide resolved
settings.gradle Outdated Show resolved Hide resolved
src/main/java/frc/robot/subsystems/drive/Drive.java Outdated Show resolved Hide resolved
src/main/java/frc/robot/subsystems/drive/Drive.java Outdated Show resolved Hide resolved
vendordeps/NavX.json Outdated Show resolved Hide resolved
@sleepyghost-zzz sleepyghost-zzz linked an issue Jan 11, 2025 that may be closed by this pull request
? getRotation().plus(new Rotation2d(Math.PI)) // Flip orientation for Red Alliance
: getRotation();

ChassisSpeeds fieldRelativeSpeeds =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkleiber @sleepyghost-zzz does this assume that run velocity is being given a field centric speed already? if so, how would this work with auto?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the auto builder is given setGoalSpeeds which is robot-centric rather than runVelocity which is field-centric.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense - @linglejack as long as we are commanding the field centric function in coppercore then I'm fine. I am not sure that is the case though, we may need to use runVelocity with drive with joysticks

@sleepyghost-zzz if there's any way we can comment / docstring these two functions to make it obvious that one is field centric and the other is robot centric, that would be good. It may already be commented as such and I just missed it (I'm on my phone)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the auto builder is given set goal speeds, it still runs through run velocity, which is converting to field centric?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so wouldn't that mess up with path planner @jkleiber @aidnem

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense - @linglejack as long as we are commanding the field centric function in coppercore then I'm fine. I am not sure that is the case though, we may need to use runVelocity with drive with joysticks

@sleepyghost-zzz if there's any way we can comment / docstring these two functions to make it obvious that one is field centric and the other is robot centric, that would be good. It may already be commented as such and I just missed it (I'm on my phone)

@jkleiber coppercore just calls the set goal speeds function from drive. Everything else currently handled by the drive subsystem

@linglejack06
Copy link
Member

@jkleiber it looks like on josh's most recent commit, the run velocity command was updated to work with the existing drive with josysticks command in coppercore, do i still need to adjust anything for coppercore command @sleepyghost-zzz ?

@sleepyghost-zzz
Copy link
Contributor Author

Hi there guys,

TLDR: Setgoalspeeds = robot-centric. Runvelocity = field-centric.

So:

  1. Autobuilder is just using the setgoalspeeds method:
    AutoBuilder:
AutoBuilder.configure(
        this::getPose,
        this::setPose,
        this::getChassisSpeeds,
        this::setGoalSpeeds,
        new PPHolonomicDriveController(
            new PIDConstants(5.0, 0.0, 0.0), new PIDConstants(5.0, 0.0, 0.0)),
        PP_CONFIG,
        () -> DriverStation.getAlliance().orElse(Alliance.Blue) == Alliance.Red,
        this);

SetGoalSpeeds

public void setGoalSpeeds(ChassisSpeeds speeds) {
    this.goalSpeeds = speeds;
  }

to get the speeds we want.
The runVelocity method calls the setgoalspeeds method but also does a conversion to turn those values into field centric control. We moved this to runVelocity so that we could use the DriveWithJoysticks command in coppercore, and be able to actually use it right.
Conversion of robot relative to field relative:

boolean isFlipped =
        DriverStation.getAlliance().isPresent()
            && DriverStation.getAlliance().get() == Alliance.Red;

    Rotation2d robotRotation =
        isFlipped
            ? getRotation().plus(new Rotation2d(Math.PI)) // Flip orientation for Red Alliance
            : getRotation();

    ChassisSpeeds fieldRelativeSpeeds =
        ChassisSpeeds.fromFieldRelativeSpeeds(speeds, robotRotation);

Doing all that means that auto uses setgoalspeeds and teleop uses runvelocity to actually control. Hope this all makes sense, its kind of a long explanation I just wanted to try and make it as clear as possible.

@linglejack06
Copy link
Member

linglejack06 commented Jan 13, 2025 via email

@sleepyghost-zzz
Copy link
Contributor Author

jack, now that you say that I think you are correct. This is my fault for not actually knowing how to sim autos, but right now it probably wont do anything because I am using setgoalspeeds which doesn't move motors. I will have to create either a boolean or another method that doesn't do those translations, Thanks for making me see this.

@linglejack06
Copy link
Member

linglejack06 commented Jan 13, 2025 via email

@linglejack06
Copy link
Member

@sleepyghost-zzz @jkleiber it looks like the field relative speed conversion will have to be done in set goal speeds like last year. We could move it to the command but that would require a supplier for robot rotation. I feel it would be easier to just implement set goal speeds with boolean and conditional to convert to field relative. Are you good with that justin and @aidnem?

basically it would either be

setGoalSpeeds(ChassisSpeeds speeds, boolean fieldCentric) {
this.speeds = ChassisSpeeds.fromFieldRelative(speeds, robotRotation);
}

or

public void execute() {
// get speeds from joystick before ... 
speeds = ChassisSpeeds.fromFieldRelative(joystickSpeeds, this.rotationSupplier.get());
drive.setGoalSpeeds(speeds);
}

@jkleiber
Copy link
Member

@linglejack06 let's do the boolean approach we've done in the past. I agree that it's weird to supply rotation to the command.

@linglejack06
Copy link
Member

@jkleiber got it, i can help josh do that tonight or go ahead and do it now. either way, i think we need to get this pr merged by the end of today so we can move on to integrating vision

@jkleiber
Copy link
Member

If you can do it now, I'd recommend going ahead and doing it. I'd like to see the robot moving in shop today if possible

@linglejack06
Copy link
Member

ok ill add that now

@linglejack06
Copy link
Member

@jkleiber setGoalSpeeds adjusted in coppercore + 2025-robot-code here. Build will fail though until we get the pull request merged in coppercore and release updated (had to add back boolean to the DriveTemplate class in coppercore)

@jkleiber
Copy link
Member

@aidnem when you get the chance, please make sure this PR isn't blowing away your work in #10 to get RobotContainer in ideal condition.

Once we confirm that, I'm good with this PR. So if/when @aidnem approves we can merge

@linglejack06
Copy link
Member

@jkleiber it might be best if we get @aidnem to resolve the merge conflicts to avoid blowing away the changes to robot container?

@jkleiber
Copy link
Member

@linglejack06 I agree

@linglejack06
Copy link
Member

@jkleiber it looks like pathplanner has changed the parameters of their AutoBuilder.config method a bit, i think that might be why build is failing

@sleepyghost-zzz
Copy link
Contributor Author

@linglejack06 sorry i cant do anything at school, whats been happening? is there a problem rn?

@linglejack06
Copy link
Member

linglejack06 commented Jan 13, 2025 via email

@sleepyghost-zzz
Copy link
Contributor Author

Did we ever make Highkey move?

@linglejack06
Copy link
Member

@sleepyghost-zzz no, we had to leave at 8. Im going to try to get it moving tonight while im there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants