Skip to content

Commit

Permalink
robot relative
Browse files Browse the repository at this point in the history
  • Loading branch information
penguin212 committed Feb 7, 2024
1 parent fb06ca8 commit 8bb0ec1
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static class ElevatorConstants {

public static final int ZERO_LIMIT_ID = 3;

public static final double GROUND_POSITION = Units.inchesToMeters(0.5);
public static final double GROUND_POSITION = Units.inchesToMeters(1);
public static final double SPEAKER_POSITION = 0;
public static final double AMP_POSITION = Units.inchesToMeters(29);
public static final double CHUTE_POSITION = Units.inchesToMeters(1);
Expand Down Expand Up @@ -66,7 +66,7 @@ public static class SwerveConstants {

public static final int BR_DRIVE = 6;
public static final int BR_STEER = 7;
public static final double BR_OFFSET = 2.43 - Math.PI * 1 / 4;
public static final double BR_OFFSET = 2.66 + Math.PI * 3.0 / 4.0;

private static double MODULE_DIST = Units.inchesToMeters(27.25 / 2.0);
public static final Translation2d FL_POS = new Translation2d(-MODULE_DIST, MODULE_DIST);
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,17 @@ private void configureBindings() {
final SwerveSubsystem swerveSubsystem = (SwerveSubsystem) baseSwerveSubsystem;

ledSubsystem.setDefaultCommand(new RunCommand(() -> {
ledSubsystem.setDriverHeading(-swerveSubsystem.getDriverHeading().getRadians());// - swerveSubsystem.getRobotPosition().getRotation().getRadians());

ledSubsystem.setDriverHeading(driveController.getRelativeMode() ? 0 : -swerveSubsystem.getDriverHeading().getRadians());

}, ledSubsystem));

swerveSubsystem.setDefaultCommand(new RunCommand(() -> {
swerveSubsystem.setDrivePowers(driveController.getLeftPower(), driveController.getForwardPower(), driveController.getRotatePower());//, 1 * (controller.getRightTriggerAxis() - controller.getLeftTriggerAxis()));
if(driveController.getRelativeMode()){
swerveSubsystem.setRobotRelativeDrivePowers(driveController.getLeftPower(), driveController.getForwardPower(), driveController.getRotatePower());
} else {
swerveSubsystem.setDrivePowers(driveController.getLeftPower(), driveController.getForwardPower(), driveController.getRotatePower());
}
// pivotSubsystem.setFieldPosition(swerveSubsystem.getRobotPosition());
}, swerveSubsystem));

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/frc/robot/controllers/BaseDriveController.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ public abstract class BaseDriveController {
public abstract JoystickButton getLeftBumper();

public abstract JoystickButton getRightBumper();

public abstract Boolean getRelativeMode();
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,8 @@ public JoystickButton getRightBumper(){
public JoystickButton getLeftBumper(){
return rightMiddleLeftButton;
}


public Boolean getRelativeMode(){
return rightTrigger.getAsBoolean();
}
}
5 changes: 5 additions & 0 deletions src/main/java/frc/robot/controllers/XboxDriveController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package frc.robot.controllers;

import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj2.command.button.JoystickButton;

Expand Down Expand Up @@ -46,4 +47,8 @@ public JoystickButton getLeftBumper() {
public JoystickButton getRightBumper() {
return driveRBumper;
}

public Boolean getRelativeMode() {
return driveController.getRightTriggerAxis() > .1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ElevatorSubsystem extends SubsystemBase{
private double manualPower = 0;

private ElevatorState state = ElevatorState.GROUND;
private ElevatorState targetState = ElevatorState.START;
private ElevatorState targetState = ElevatorState.GROUND;

private final CANSparkMax extensionMotor;
private RelativeEncoder extensionEncoder;
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/frc/robot/subsystems/swerve/SwerveSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,28 @@ public void setDrivePowers(double xPower, double yPower, double angularPower){
getDriverHeading()
);

states = kinematics.toSwerveModuleStates(speeds);
SwerveDriveKinematics.desaturateWheelSpeeds(
states, speeds,
MAX_VEL, MAX_VEL, MAX_OMEGA);
}

public void setRobotRelativeDrivePowers(double xPower, double yPower, double angularPower){
ChassisSpeeds speeds = ChassisSpeeds.fromRobotRelativeSpeeds(
xPower * MAX_VEL,
yPower * MAX_VEL,
angularPower * MAX_OMEGA,
new Rotation2d(0)
);

this.states = kinematics.toSwerveModuleStates(speeds);
states = kinematics.toSwerveModuleStates(speeds);
SwerveDriveKinematics.desaturateWheelSpeeds(
this.states, speeds,
states, speeds,
MAX_VEL, MAX_VEL, MAX_OMEGA);
}



public void setSwerveModuleStates(SwerveModuleState[] states){
this.states = states;
}
Expand Down

0 comments on commit 8bb0ec1

Please sign in to comment.