Skip to content

Commit

Permalink
(maybe) working field relative rotation?
Browse files Browse the repository at this point in the history
  • Loading branch information
JayK445 committed Oct 28, 2023
1 parent d3ac8d8 commit d31c84e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
29 changes: 21 additions & 8 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,19 @@ private void configureButtonBindings() {
rotationVelocity,
will.rightBumper()));

new Trigger(
() ->
Util.vectorMagnitude(will.getRightY(), will.getRightX())
> Drive.ROTATE_VECTOR_MAGNITUDE)
.onTrue(
new RotateVectorDriveCommand(
drivebaseSubsystem,
translationXSupplier,
translationYSupplier,
will::getRightY,
will::getRightX,
will.rightBumper()));


will.povUp()
.onTrue(new RotateAngleDriveCommand(drivebaseSubsystem, translationXSupplier, translationYSupplier, 0));
Expand Down Expand Up @@ -305,9 +318,9 @@ private void configureButtonBindings() {
// new ForceOuttakeSubsystemModeCommand(outtakeSubsystem,
// OuttakeSubsystem.Modes.INTAKE));

will.rightTrigger()
.whileTrue(new ArmPositionCommand(armSubsystem, Arm.Setpoints.SHELF_INTAKE))
.onFalse(new ArmPositionCommand(armSubsystem, Arm.Setpoints.STOWED));
// will.rightTrigger()
// .whileTrue(new ArmPositionCommand(armSubsystem, Arm.Setpoints.SHELF_INTAKE))
// .onFalse(new ArmPositionCommand(armSubsystem, Arm.Setpoints.STOWED));



Expand Down Expand Up @@ -403,12 +416,12 @@ private void configureButtonBindings() {
Constants.SCORE_STEP_MAP.get(scoreType),
will.rightTrigger()));

will.leftTrigger()
.onTrue(
new HashMapCommand<>(
scoreCommandMap, () -> currentNodeSelection.get().getScoreTypeIdentifier()));
// will.leftTrigger()
// .onTrue(
// new HashMapCommand<>(
// scoreCommandMap, () -> currentNodeSelection.get().getScoreTypeIdentifier()));

will.leftTrigger().onTrue(new InstantCommand(() -> currentNodeSelection.apply(n -> n.shift(1))));
// will.leftTrigger().onTrue(new InstantCommand(() -> currentNodeSelection.apply(n -> n.shift(1))));
jason.b().onTrue(new InstantCommand(() -> currentNodeSelection.apply(n -> n.shift(-1))));

// control the lights
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/frc/robot/commands/RotateVectorDriveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ public void execute() {
double rotY = rotationYSupplier.getAsDouble();
boolean isRobotRelative = isRobotRelativeSupplier.getAsBoolean();

double targetAngle = Util.angleSnap(Util.vectorToAngle(-rotX, -rotY), angles);
double targetAngle = Util.normalizeDegrees(Util.vectorToAngle(-rotX, -rotY));
//Util.vectorToAngle(-rotX, -rotY);

// if stick magnitude is greater then rotate angle mag
if (Util.vectorMagnitude(rotX, rotY) > Drive.ROTATE_VECTOR_MAGNITUDE) {
angle = isRobotRelative ? Util.normalizeDegrees(targetAngle + initialAngle) : targetAngle;
angle = targetAngle;
}

drivebaseSubsystem.driveAngle(new Pair<>(x, y), angle);
Expand All @@ -92,13 +93,14 @@ public void end(boolean interrupted) {
@Override
public boolean isFinished() {
// are we at the angle we want
return Util.epsilonZero(
Util.relativeAngularDifference(drivebaseSubsystem.getDriverGyroscopeRotation(), angle),
Drive.ANGULAR_ERROR)
// is our rotational velocity low
&& Util.epsilonEquals(drivebaseSubsystem.getRotVelocity(), 0, 10)
// are we not intentionally running pid to hold an angle
&& Util.vectorMagnitude(rotationXSupplier.getAsDouble(), rotationYSupplier.getAsDouble())
<= Drive.ROTATE_VECTOR_MAGNITUDE;
// return Util.epsilonZero(
// Util.relativeAngularDifference(drivebaseSubsystem.getDriverGyroscopeRotation(), angle),
// Drive.ANGULAR_ERROR)
// // is our rotational velocity low
// && Util.epsilonEquals(drivebaseSubsystem.getRotVelocity(), 0, 10)
// // are we not intentionally running pid to hold an angle
// && Util.vectorMagnitude(rotationXSupplier.getAsDouble(), rotationYSupplier.getAsDouble())
// <= Drive.ROTATE_VECTOR_MAGNITUDE;
return false;
}
}

0 comments on commit d31c84e

Please sign in to comment.