Skip to content

Commit

Permalink
Adds alliance color detection, and uses dev-build for sysid
Browse files Browse the repository at this point in the history
  • Loading branch information
CoryNessCTR committed Jan 25, 2024
1 parent 6b473f7 commit b3e0b38
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
import edu.wpi.first.wpilibj2.command.Subsystem;
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine;
import frc.robot.generated.TunerConstants;
import frc.robot.sysid.SysIdSwerveRotation;
import frc.robot.sysid.SysIdSwerveSteerGains;
import frc.robot.sysid.SysIdSwerveTranslation;

/**
* Class that extends the Phoenix SwerveDrivetrain class and implements subsystem
Expand All @@ -37,9 +34,11 @@ public class CommandSwerveDrivetrain extends SwerveDrivetrain implements Subsyst
private double m_lastSimTime;

private final SwerveRequest.ApplyChassisSpeeds autoRequest = new SwerveRequest.ApplyChassisSpeeds();
private final SysIdSwerveTranslation translationCharacterization = new SysIdSwerveTranslation();
private final SysIdSwerveRotation rotationCharacterization = new SysIdSwerveRotation();
private final SysIdSwerveSteerGains steerCharacterization = new SysIdSwerveSteerGains();
private final SwerveRequest.SysIdSwerveTranslation translationCharacterization = new SwerveRequest.SysIdSwerveTranslation();
private final SwerveRequest.SysIdSwerveRotation rotationCharacterization = new SwerveRequest.SysIdSwerveRotation();
private final SwerveRequest.SysIdSwerveSteerGains steerCharacterization = new SwerveRequest.SysIdSwerveSteerGains();

/* Use one of these sysidroutines for your particular test */
private SysIdRoutine m_SysIdRoutineTranslation =
new SysIdRoutine(
new SysIdRoutine.Config(
Expand Down Expand Up @@ -121,6 +120,7 @@ public Command getAutoPath(String pathName) {
return new PathPlannerAuto(pathName);
}

/* Both the sysid commands are specific to one particular sysid routine, change which one you're trying to characterize */
public Command sysIdQuasistatic(SysIdRoutine.Direction direction) {
return m_SysIdRoutineSteer.quasistatic(direction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
import com.ctre.phoenix6.mechanisms.swerve.SwerveModule.DriveRequestType;

import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.DriverStation.Alliance;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.RunCommand;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import edu.wpi.first.wpilibj2.command.button.Trigger;
import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction;
import frc.robot.generated.TunerConstants;

Expand All @@ -29,6 +33,11 @@ public class RobotContainer {
private final SwerveRequest.RobotCentric forwardStraight = new SwerveRequest.RobotCentric().withDriveRequestType(DriveRequestType.OpenLoopVoltage);
private final SwerveRequest.PointWheelsAt point = new SwerveRequest.PointWheelsAt();

/* Blue alliance sees forward as 0 degrees (toward red alliance wall) */
private final Rotation2d blueAlliancePerspectiveRotation = Rotation2d.fromDegrees(0);
/* Red alliance sees forward as 180 degrees (toward blue alliance wall) */
private final Rotation2d redAlliancePerspectiveRotation = Rotation2d.fromDegrees(180);

/* Path follower */
private Command runAuto = drivetrain.getAutoPath("Tests");

Expand Down Expand Up @@ -64,6 +73,12 @@ private void configureBindings() {
joystick.back().and(joystick.x()).whileTrue(drivetrain.sysIdDynamic(Direction.kReverse));
joystick.start().and(joystick.y()).whileTrue(drivetrain.sysIdQuasistatic(Direction.kForward));
joystick.start().and(joystick.x()).whileTrue(drivetrain.sysIdQuasistatic(Direction.kReverse));

/* When we get alliance data from Driver Station, forward it to the drivetrain so it knows what perspective is forward for operator control */
new Trigger(() -> DriverStation.getAlliance().isPresent())
.whileTrue(new RunCommand(() -> drivetrain.setOperatorPerspectiveForward(
DriverStation.getAlliance().get() == Alliance.Red ? redAlliancePerspectiveRotation
: blueAlliancePerspectiveRotation)));
}

public RobotContainer() {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

52 changes: 26 additions & 26 deletions java/SwerveWithPathPlanner/vendordeps/Phoenix6.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"fileName": "Phoenix6.json",
"name": "CTRE-Phoenix (v6)",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"frcYear": 2024,
"uuid": "e995de00-2c64-4df5-8831-c1441420ff19",
"mavenUrls": [
"https://maven.ctr-electronics.com/release/"
"https://maven.ctr-electronics.com/development/"
],
"jsonUrl": "https://maven.ctr-electronics.com/release/com/ctre/phoenix6/latest/Phoenix6-frc2024-latest.json",
"jsonUrl": "https://maven.ctr-electronics.com/development/com/ctre/phoenix6/latest/Phoenix6-frc2024-latest.json",
"conflictsWith": [
{
"uuid": "3fcf3402-e646-4fa6-971e-18afe8173b1a",
Expand All @@ -19,14 +19,14 @@
{
"groupId": "com.ctre.phoenix6",
"artifactId": "wpiapi-java",
"version": "24.1.0"
"version": "24.1.0-45-g0e8c329"
}
],
"jniDependencies": [
{
"groupId": "com.ctre.phoenix6",
"artifactId": "tools",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"isJar": false,
"skipInvalidPlatforms": true,
"validPlatforms": [
Expand All @@ -39,7 +39,7 @@
{
"groupId": "com.ctre.phoenix6.sim",
"artifactId": "tools-sim",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"isJar": false,
"skipInvalidPlatforms": true,
"validPlatforms": [
Expand All @@ -52,7 +52,7 @@
{
"groupId": "com.ctre.phoenix6.sim",
"artifactId": "simTalonSRX",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"isJar": false,
"skipInvalidPlatforms": true,
"validPlatforms": [
Expand All @@ -65,7 +65,7 @@
{
"groupId": "com.ctre.phoenix6.sim",
"artifactId": "simTalonFX",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"isJar": false,
"skipInvalidPlatforms": true,
"validPlatforms": [
Expand All @@ -78,7 +78,7 @@
{
"groupId": "com.ctre.phoenix6.sim",
"artifactId": "simVictorSPX",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"isJar": false,
"skipInvalidPlatforms": true,
"validPlatforms": [
Expand All @@ -91,7 +91,7 @@
{
"groupId": "com.ctre.phoenix6.sim",
"artifactId": "simPigeonIMU",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"isJar": false,
"skipInvalidPlatforms": true,
"validPlatforms": [
Expand All @@ -104,7 +104,7 @@
{
"groupId": "com.ctre.phoenix6.sim",
"artifactId": "simCANCoder",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"isJar": false,
"skipInvalidPlatforms": true,
"validPlatforms": [
Expand All @@ -117,7 +117,7 @@
{
"groupId": "com.ctre.phoenix6.sim",
"artifactId": "simProTalonFX",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"isJar": false,
"skipInvalidPlatforms": true,
"validPlatforms": [
Expand All @@ -130,7 +130,7 @@
{
"groupId": "com.ctre.phoenix6.sim",
"artifactId": "simProCANcoder",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"isJar": false,
"skipInvalidPlatforms": true,
"validPlatforms": [
Expand All @@ -143,7 +143,7 @@
{
"groupId": "com.ctre.phoenix6.sim",
"artifactId": "simProPigeon2",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"isJar": false,
"skipInvalidPlatforms": true,
"validPlatforms": [
Expand All @@ -158,7 +158,7 @@
{
"groupId": "com.ctre.phoenix6",
"artifactId": "wpiapi-cpp",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"libName": "CTRE_Phoenix6_WPI",
"headerClassifier": "headers",
"sharedLibrary": true,
Expand All @@ -173,7 +173,7 @@
{
"groupId": "com.ctre.phoenix6",
"artifactId": "tools",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"libName": "CTRE_PhoenixTools",
"headerClassifier": "headers",
"sharedLibrary": true,
Expand All @@ -188,7 +188,7 @@
{
"groupId": "com.ctre.phoenix6.sim",
"artifactId": "wpiapi-cpp-sim",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"libName": "CTRE_Phoenix6_WPISim",
"headerClassifier": "headers",
"sharedLibrary": true,
Expand All @@ -203,7 +203,7 @@
{
"groupId": "com.ctre.phoenix6.sim",
"artifactId": "tools-sim",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"libName": "CTRE_PhoenixTools_Sim",
"headerClassifier": "headers",
"sharedLibrary": true,
Expand All @@ -218,7 +218,7 @@
{
"groupId": "com.ctre.phoenix6.sim",
"artifactId": "simTalonSRX",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"libName": "CTRE_SimTalonSRX",
"headerClassifier": "headers",
"sharedLibrary": true,
Expand All @@ -233,7 +233,7 @@
{
"groupId": "com.ctre.phoenix6.sim",
"artifactId": "simTalonFX",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"libName": "CTRE_SimTalonFX",
"headerClassifier": "headers",
"sharedLibrary": true,
Expand All @@ -248,7 +248,7 @@
{
"groupId": "com.ctre.phoenix6.sim",
"artifactId": "simVictorSPX",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"libName": "CTRE_SimVictorSPX",
"headerClassifier": "headers",
"sharedLibrary": true,
Expand All @@ -263,7 +263,7 @@
{
"groupId": "com.ctre.phoenix6.sim",
"artifactId": "simPigeonIMU",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"libName": "CTRE_SimPigeonIMU",
"headerClassifier": "headers",
"sharedLibrary": true,
Expand All @@ -278,7 +278,7 @@
{
"groupId": "com.ctre.phoenix6.sim",
"artifactId": "simCANCoder",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"libName": "CTRE_SimCANCoder",
"headerClassifier": "headers",
"sharedLibrary": true,
Expand All @@ -293,7 +293,7 @@
{
"groupId": "com.ctre.phoenix6.sim",
"artifactId": "simProTalonFX",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"libName": "CTRE_SimProTalonFX",
"headerClassifier": "headers",
"sharedLibrary": true,
Expand All @@ -308,7 +308,7 @@
{
"groupId": "com.ctre.phoenix6.sim",
"artifactId": "simProCANcoder",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"libName": "CTRE_SimProCANcoder",
"headerClassifier": "headers",
"sharedLibrary": true,
Expand All @@ -323,7 +323,7 @@
{
"groupId": "com.ctre.phoenix6.sim",
"artifactId": "simProPigeon2",
"version": "24.1.0",
"version": "24.1.0-45-g0e8c329",
"libName": "CTRE_SimProPigeon2",
"headerClassifier": "headers",
"sharedLibrary": true,
Expand Down

0 comments on commit b3e0b38

Please sign in to comment.